* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: "Space Grotesk", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }

:root {
  --bg: #f5efe6;
  --bg-2: #e8dfd0;
  --panel-bg: rgba(255, 251, 244, 0.94);
  --text: #1b1a16;
  --muted: #5d5648;
  --border: rgba(27, 26, 22, 0.12);
  --panel-border: rgba(27, 26, 22, 0.08);
  --surface: #fff7ec;
  --surface-2: #f7efe2;
  --accent: #1f6f78;
  --accent-2: #ef7a4c;
  --accent-3: #1b1a16;
  --accent-bg: #1f6f78;
  --accent-fg: #ffffff;
  --map-bg: #f0e6d6;
  --region-fill: rgba(45, 160, 178, 0.28);
  --region-stroke: #1b1a16;
  --shadow: 0 18px 40px rgba(23, 18, 10, 0.18);
  --panel-shadow: 0 18px 42px rgba(23, 18, 10, 0.22);
  --ring: 0 0 0 3px rgba(31, 111, 120, 0.25);
}

body.dark {
  --bg: #0f1112;
  --bg-2: #0b0d0e;
  --panel-bg: rgba(17, 20, 22, 0.92);
  --text: #f1efe9;
  --muted: #b1a897;
  --border: rgba(240, 233, 219, 0.18);
  --panel-border: rgba(240, 233, 219, 0.14);
  --surface: #15191b;
  --surface-2: #101416;
  --accent: #5ad0c2;
  --accent-2: #f29a6e;
  --accent-3: #f1efe9;
  --accent-bg: #5ad0c2;
  --accent-fg: #0f1112;
  --map-bg: #0f1112;
  --region-fill: rgba(90, 208, 194, 0.3);
  --region-stroke: #f1efe9;
  --shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
  --panel-shadow: 0 24px 50px rgba(0, 0, 0, 0.6);
  --ring: 0 0 0 3px rgba(90, 208, 194, 0.35);
}

body {
  position: relative;
  background: radial-gradient(900px 500px at 85% -10%, rgba(239, 122, 76, 0.35), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: radial-gradient(rgba(27, 26, 22, 0.05) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.35;
  pointer-events: none;
  z-index: 0;
}

#layout {
  height: 100%;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  padding: 16px;
  position: relative;
  z-index: 1;
}

#panel {
  padding: 18px;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  overflow: auto;
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  box-shadow: var(--panel-shadow);
}

#map {
  height: 100%;
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: var(--map-bg);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header h1 {
  font-family: "Fraunces", serif;
  font-size: 22px;
  letter-spacing: 0.3px;
}

.mode-buttons,
.task-buttons,
.session-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-buttons button,
.task-buttons button,
.session-buttons button {
  margin-bottom: 0;
}

.session-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.row button {
  margin-bottom: 0;
}

.session-pill {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.mode-buttons button.active,
.task-buttons button.active,
.session-buttons button.active,
.lang-buttons button.active {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 16px rgba(31, 111, 120, 0.25);
}

.lang-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.lang-buttons button,
.theme-toggle {
  width: auto;
  padding: 6px 10px;
  margin-bottom: 0;
  font-size: 16px;
  line-height: 1;
  border-radius: 10px;
}

.theme-toggle {
  border: 1px solid var(--border);
}

#bundleInfo {
  margin-top: 8px;
}

.bundle-stage {
  position: absolute;
  inset: 0;
  display: none;
  background: var(--map-bg);
}

.bundle-stage.active {
  display: block;
}

.bundle-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--map-bg);
}

.bundle-stage svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.bundle-stage .region {
  fill: var(--region-fill);
  stroke: var(--region-stroke);
  stroke-width: 1;
  cursor: pointer;
  vector-effect: non-scaling-stroke;
}

.bundle-stage .region.answered {
  fill: rgba(45, 160, 178, 0.55);
}

.bundle-stage .region.correct {
  fill: rgba(34, 197, 94, 0.55);
}

.bundle-stage .region.wrong {
  fill: rgba(239, 68, 68, 0.55);
}

.bundle-stage .region.unanswered {
  stroke-dasharray: 4 4;
  fill: transparent;
}

.bundle-stage .region.selected {
  stroke-width: 2;
}

#map.quiz-mode {
  background: var(--map-bg);
}

#map.bundle-mode .leaflet-pane,
#map.bundle-mode .leaflet-control-container {
  display: none;
}

h1 { margin: 0; }

.section {
  margin: 14px 0;
  padding: 12px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--panel-border);
}

.section.small {
  font-size: 12px;
  color: var(--muted);
  padding: 10px;
}

.label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
}

.value {
  font-size: 14px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid var(--border);
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 8px;
  font-family: inherit;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
  margin-bottom: 8px;
  font-family: inherit;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(23, 18, 10, 0.12);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.mistake {
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  font-size: 13px;
}

.feedback {
  margin-top: 6px;
  font-size: 12px;
  min-height: 16px;
  color: var(--muted);
}

.feedback.good { color: #166534; }
.feedback.bad { color: #991b1b; }

#panel .section {
  animation: float-in 0.6s ease both;
}

#panel .section:nth-child(2) { animation-delay: 0.05s; }
#panel .section:nth-child(3) { animation-delay: 0.1s; }
#panel .section:nth-child(4) { animation-delay: 0.15s; }
#panel .section:nth-child(5) { animation-delay: 0.2s; }
#panel .section:nth-child(6) { animation-delay: 0.25s; }

@keyframes float-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 980px) {
  #layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding: 12px;
  }

  #panel {
    border-right: none;
  }

  #map { min-height: 60vh; }

  button,
  input,
  select {
    padding: 12px;
  }

  .session-row {
    grid-template-columns: 1fr 1fr;
  }

  .session-row button {
    grid-column: 1 / -1;
  }
}
