@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&family=Instrument+Serif:ital@0;1&display=swap');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0b;
  --surface: #141416;
  --surface-hover: #1c1c1f;
  --border: #2a2a2e;
  --text: #e8e6e3;
  --text-dim: #7a7872;
  --accent: #c4a882;
  --accent-dim: rgba(196, 168, 130, 0.15);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
}

canvas#flagCanvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* ─── Panel ──────────────────────────────────────────────────── */

.panel {
  position: fixed;
  top: 24px; left: 24px;
  bottom: 24px;
  width: 300px;
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 10;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.4s ease;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(20, 20, 22, 0.88);
}

.panel.collapsed {
  transform: translateX(calc(-100% - 32px));
  opacity: 0;
  pointer-events: none;
}

.panel-toggle {
  position: fixed;
  top: 24px; left: 24px;
  width: 48px; height: 48px;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9;
  transition: all 0.3s ease;
  color: var(--text);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(20, 20, 22, 0.88);
}
.panel-toggle:hover { background: var(--surface-hover); border-color: var(--accent); }
.panel-toggle svg { width: 20px; height: 20px; }
.panel:not(.collapsed) ~ .panel-toggle { opacity: 0; pointer-events: none; }

.panel-header {
  padding: 24px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-family: 'Instrument Serif', serif;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.panel-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}
.panel-close:hover { background: var(--surface-hover); color: var(--text); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ─── Controls ───────────────────────────────────────────────── */

.section { margin-bottom: 28px; }
.section:last-child { margin-bottom: 0; }

.section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.control-row { margin-bottom: 16px; }
.control-row:last-child { margin-bottom: 0; }

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.control-name { font-size: 13px; color: var(--text); font-weight: 500; }
.control-value {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.control-note {
  margin-top: 7px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-dim);
  opacity: 0.82;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
  transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-webkit-slider-thumb:active { transform: scale(0.95); }

/* ─── Wind dial ──────────────────────────────────────────────── */

.wind-direction-wrap { display: flex; align-items: center; gap: 16px; }

.wind-dial {
  position: relative;
  width: 64px; height: 64px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
}

.wind-dial-arrow {
  position: absolute;
  top: 50%; left: 50%;
  width: 2px; height: 24px;
  background: var(--accent);
  border-radius: 1px;
  transform-origin: center bottom;
  transform: translateX(-50%) translateY(-100%);
  pointer-events: none;
}

.wind-dial-arrow::after {
  content: '';
  position: absolute;
  top: -3px; left: 50%;
  transform: translateX(-50%);
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
}

.wind-dial-center {
  position: absolute;
  top: 50%; left: 50%;
  width: 4px; height: 4px;
  background: var(--text-dim);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.wind-direction-info { flex: 1; }
.wind-direction-degrees {
  font-size: 28px;
  font-family: 'Instrument Serif', serif;
  line-height: 1;
  margin-bottom: 2px;
}
.wind-direction-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ─── Dropzone ───────────────────────────────────────────────── */

.dropzone {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.dropzone-icon {
  width: 32px; height: 32px;
  margin: 0 auto 10px;
  color: var(--text-dim);
  transition: color 0.3s;
}
.dropzone:hover .dropzone-icon { color: var(--accent); }

.dropzone-text { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.dropzone-text strong { color: var(--text); font-weight: 500; }
.dropzone-hint { font-size: 11px; color: var(--text-dim); margin-top: 6px; opacity: 0.6; }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.texture-preview {
  margin-top: 12px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
}
.texture-preview img,
.texture-preview video {
  width: 100%;
  display: block;
  object-fit: cover;
  background: repeating-conic-gradient(#1a1a1d 0% 25%, #222225 0% 50%) 50% / 12px 12px;
}
.texture-preview video { display: none; }

.texture-remove {
  position: absolute;
  top: 8px; right: 8px;
  width: 28px; height: 28px;
  border-radius: 6px;
  border: none;
  background: rgba(0,0,0,0.7);
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  transition: background 0.2s;
  backdrop-filter: blur(8px);
}
.texture-remove:hover { background: rgba(180, 60, 60, 0.8); }

/* ─── Color picker ───────────────────────────────────────────── */

.color-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }

.color-swatch {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.color-swatch input[type="color"] {
  position: absolute;
  inset: -4px;
  width: calc(100% + 8px);
  height: calc(100% + 8px);
  border: none;
  cursor: pointer;
  background: none;
}
.color-swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch input[type="color"]::-webkit-color-swatch { border: none; border-radius: 6px; }

.color-label { font-size: 13px; color: var(--text); }

/* ─── Buttons ────────────────────────────────────────────────── */

.btn-reset {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.btn-reset:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.media-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn-media {
  flex: 1;
  padding: 10px 8px;
  font-size: 10px;
}

.btn-media:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ─── View toggle bar ────────────────────────────────────────── */

.view-toggle {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  z-index: 10;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(20, 20, 22, 0.88);
}
.view-toggle button {
  padding: 8px 10px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: 'DM Sans', sans-serif;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.view-toggle button.active {
  background: var(--accent-dim);
  color: var(--accent);
}
.view-toggle button:hover:not(.active) {
  color: var(--text);
}
.toggle-divider {
  width: 1px;
  background: var(--border);
  margin: 4px 4px;
  flex-shrink: 0;
}

.pin-toggle {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.1);
}

.pin-toggle button {
  flex: 1;
  padding: 7px 8px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: 'DM Sans', sans-serif;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pin-toggle button.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.pin-toggle button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pin-editor {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.1);
}

.pin-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.pin-editor-head span {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pin-editor-head button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 10px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
}

.pin-editor-head button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pin-editor-head button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pin-map {
  position: relative;
  width: 100%;
  aspect-ratio: 1.75 / 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: crosshair;
  background:
    linear-gradient(90deg, rgba(196, 168, 130, 0.24) 0 4%, rgba(196, 168, 130, 0.04) 4% 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.12));
}

.pin-map::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 18px 18px;
  pointer-events: none;
}

.pin-map::after {
  content: '';
  position: absolute;
  left: 5%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(196, 168, 130, 0.45);
  pointer-events: none;
}

.pin-map-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(12, 12, 12, 0.95);
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(196, 168, 130, 0.35);
  pointer-events: none;
}

.pin-editor-help {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text-dim);
}

/* ─── Light mode ─────────────────────────────────────────────── */

html.light-mode {
  --bg: #f0ede8;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-hover: #eae6e0;
  --border: #d4d0ca;
  --text: #1a1918;
  --text-dim: #8a8680;
  --accent: #8a6b4a;
  --accent-dim: rgba(138, 107, 74, 0.12);
}
html.light-mode .panel {
  background: rgba(255, 255, 255, 0.82);
}
html.light-mode .panel-toggle,
html.light-mode .view-toggle {
  background: rgba(255, 255, 255, 0.82);
}
html.light-mode .wind-dial {
  background: #f5f3f0;
}

/* ─── Watermark ──────────────────────────────────────────────── */

.watermark {
  position: fixed;
  bottom: 20px; right: 24px;
  font-family: 'Instrument Serif', serif;
  font-size: 13px;
  color: var(--text-dim);
  opacity: 0.3;
  z-index: 5;
  font-style: italic;
}

/* ─── Global drop overlay ────────────────────────────────────── */

.global-drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 11, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(8px);
}
.global-drop-overlay.active { opacity: 1; pointer-events: all; }
.global-drop-content { text-align: center; }
.global-drop-content svg { width: 56px; height: 56px; color: var(--accent); margin-bottom: 16px; }
.global-drop-content p { font-family: 'Instrument Serif', serif; font-size: 24px; }
.global-drop-content span {
  display: block;
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
}

@media (max-width: 820px) {
  .view-toggle {
    width: calc(100% - 24px);
    left: 12px;
    transform: none;
    justify-content: center;
    padding: 4px 3px;
  }
  .view-toggle button {
    padding: 8px 8px;
    font-size: 10px;
  }
}
