:root {
  --bg: #f3efe6;
  --panel: rgba(255, 252, 247, 0.94);
  --text: #1f2933;
  --muted: #65707c;
  --line: #d8c9b3;
  --primary: #194e78;
  --primary-dark: #123c5d;
  --warm: #a97738;
  --sea: #d8eef7;
  --correct: #2f7d55;
  --wrong: #a9483d;
  --shadow: 0 18px 36px rgba(48, 43, 34, 0.11);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { overflow-x: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.76), transparent 30%),
    linear-gradient(180deg, #f8f4ea 0%, var(--bg) 58%, #ece5d8 100%);
  font-family: "Segoe UI", Arial, sans-serif;
}

button { font: inherit; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(25, 78, 120, 0.42);
  outline-offset: 3px;
}

.container {
  width: min(1420px, calc(100% - 28px));
  margin: 0 auto;
  padding: 16px 0 34px;
}

.hero {
  margin: 14px 0 14px;
  padding: 16px 24px;
  border: 1px solid rgba(164, 139, 99, 0.18);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3.5vw, 3.25rem);
  line-height: 1;
}

.hero p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(0.96rem, 1.35vw, 1.08rem);
  line-height: 1.42;
}

.timeline-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 2px 2px 9px;
}

.timeline {
  position: relative;
  display: flex;
  min-width: 1000px;
  gap: 6px;
}

.timeline::before {
  position: absolute;
  z-index: 0;
  top: 18px;
  right: 24px;
  left: 24px;
  height: 2px;
  content: "";
  background: var(--line);
}

.timeline-button {
  position: relative;
  z-index: 1;
  flex: 1 0 94px;
  min-height: 48px;
  padding: 6px 8px 5px;
  border: 1px solid rgba(25, 78, 120, 0.13);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 252, 247, 0.94);
  cursor: pointer;
  font-weight: 800;
  line-height: 1.05;
}

.timeline-button span {
  display: block;
  margin-top: 3px;
  font-size: 0.69rem;
  font-weight: 700;
  white-space: normal;
}

.timeline-button.is-complete {
  color: var(--primary-dark);
  border-color: rgba(25, 78, 120, 0.28);
  background: #f7f4ed;
}

.timeline-button.is-active {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: 0 6px 13px rgba(25, 78, 120, 0.2);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 12px;
}

.mode-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid rgba(25, 78, 120, 0.16);
  border-radius: 999px;
  background: rgba(255, 252, 247, 0.8);
}

.mode-button {
  min-height: 38px;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.mode-button.is-active {
  color: white;
  background: var(--primary);
}

.boundary-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 700;
}

.boundary-toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(250px, 1fr);
  gap: 16px;
  align-items: stretch;
}

.map-card,
.info-panel {
  border: 1px solid rgba(164, 139, 99, 0.18);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.map-card { padding: 14px; }

.map-frame {
  position: relative;
  overflow: hidden;
  min-height: 430px;
  border: 1px solid #c7d4d9;
  border-radius: 14px;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.23) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,0.2) 1px, transparent 1px),
    var(--sea);
  background-size: 42px 42px;
  box-shadow: inset 0 0 0 8px rgba(255, 255, 255, 0.24);
}

.map-object {
  display: block;
  width: 100%;
  height: clamp(430px, 56vw, 660px);
  border: 0;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.map-loading.is-hidden { display: none; }

.practice-prompt {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 11px;
  padding: 11px 14px;
  border-left: 4px solid var(--warm);
  border-radius: 8px;
  background: #fff7e7;
}

.practice-kicker {
  color: var(--warm);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.map-caption {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 3px 0;
}

.map-caption > p {
  flex: 0 0 auto;
  margin: 4px 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.7rem;
}

.legend-swatch {
  width: 11px;
  height: 11px;
  border: 1px solid rgba(31, 41, 51, 0.28);
  border-radius: 3px;
  background: var(--swatch);
}

.info-panel {
  display: flex;
  min-height: 100%;
  flex-direction: column;
  padding: clamp(20px, 2vw, 30px);
}

.stage-year {
  margin: 0 0 4px;
  color: var(--warm);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 5vw, 4.8rem);
  font-weight: 800;
  line-height: 0.95;
}

.info-panel h2 {
  margin: 8px 0 12px;
  color: var(--primary-dark);
  font-size: clamp(1.45rem, 2.1vw, 2rem);
  line-height: 1.08;
}

.stage-description,
.stage-context,
.practice-feedback,
.practice-details {
  color: var(--text);
  line-height: 1.55;
}

.context-heading {
  margin: 24px 0 7px;
  color: var(--primary-dark);
  font-size: 1.05rem;
}

.stage-context { margin: 0; }

.method-chip {
  display: inline-flex;
  width: fit-content;
  margin: 8px 0 0;
  padding: 6px 10px;
  border: 1px solid rgba(169, 119, 56, 0.24);
  border-radius: 999px;
  color: #765025;
  background: #fbf1df;
  font-size: 0.76rem;
  font-weight: 900;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: auto;
  padding-top: 26px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 9px 14px;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 850;
}

.primary-button {
  border: 1px solid var(--primary);
  color: white;
  background: var(--primary);
}

.secondary-button {
  border: 1px solid rgba(25, 78, 120, 0.25);
  color: var(--primary-dark);
  background: white;
}

button:disabled { cursor: not-allowed; opacity: 0.42; }

.practice-panel { min-height: 100%; }

.practice-panel h2 { margin-top: 7px; }

.practice-choices {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.practice-choice {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 74px;
  padding: 13px 14px;
  border: 1px solid rgba(25, 78, 120, 0.24);
  border-radius: 12px;
  color: var(--primary-dark);
  background: white;
  cursor: pointer;
  text-align: left;
}

.practice-choice:hover { border-color: var(--primary); background: #f2f7fa; }
.practice-choice strong { font-size: 1rem; }
.practice-choice span { color: var(--muted); font-size: 0.82rem; line-height: 1.35; }

.practice-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  color: var(--primary-dark);
  font-size: 0.84rem;
}

.practice-meta span {
  padding: 4px 8px;
  border-radius: 999px;
  background: #e9f1f6;
  font-weight: 800;
}

.text-button,
.details-button {
  padding: 4px 0;
  border: 0;
  color: var(--primary);
  background: transparent;
  cursor: pointer;
  font-weight: 800;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.practice-prompt {
  display: grid;
  gap: 5px;
  margin: 18px 0 14px;
  padding: 13px 14px;
  border-left: 4px solid var(--warm);
  border-radius: 8px;
  background: #fff7e7;
  line-height: 1.4;
}

.practice-feedback { margin-top: 10px; }
.practice-feedback span { display: block; margin-top: 5px; }
.details-button { margin-top: 12px; }
.practice-details { margin: 8px 0 0; font-size: 0.91rem; }
.next-question { width: 100%; margin-top: 18px; }

.practice-confirm {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(169, 119, 56, 0.3);
  border-radius: 11px;
  background: #fff7e7;
}

.practice-confirm p { margin: 5px 0 12px; }
.confirm-actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 8px; }

.practice-results dl { margin: 18px 0; }
.practice-results dl div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.practice-results dt { color: var(--muted); }
.practice-results dd { margin: 0; font-weight: 900; }
.result-button { width: 100%; margin-top: 8px; text-align: center; }

.practice-feedback {
  padding: 14px;
  border-radius: 10px;
  background: #f4f1eb;
}

.practice-feedback.is-correct {
  border-left: 4px solid var(--correct);
  background: #eaf5ee;
}

.practice-feedback.is-wrong {
  border-left: 4px solid var(--wrong);
  background: #faece9;
}

.practice-feedback strong { color: var(--primary-dark); }

.historical-note {
  margin: 16px 0 0;
  padding: 13px 17px;
  border-left: 4px solid var(--warm);
  border-radius: 8px;
  color: #4f493f;
  background: rgba(255, 248, 234, 0.78);
  line-height: 1.48;
}

.sources {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.5;
}

.sources summary { width: fit-content; cursor: pointer; font-weight: 800; }
.sources a { color: var(--primary-dark); }

@media (max-width: 1024px) {
  .workspace { grid-template-columns: minmax(0, 2.7fr) minmax(230px, 1fr); }
  .map-frame { min-height: 380px; }
  .map-object { height: clamp(400px, 58vw, 580px); }
  .map-caption { display: block; }
  .legend { justify-content: flex-start; margin-top: 6px; }
}

@media (max-width: 768px) {
  .container { width: min(100% - 20px, 720px); padding-top: 10px; }
  .hero { padding: 15px 17px; border-radius: 16px; }
  .workspace { grid-template-columns: 1fr; }
  .map-card, .info-panel { border-radius: 16px; }
  .map-object { height: clamp(400px, 86vw, 570px); }
  .info-panel { min-height: 300px; }
}

@media (max-width: 480px) {
  .toolbar { align-items: flex-start; flex-direction: column; }
  .boundary-toggle { width: 100%; }
  .map-card { padding: 9px; }
  .map-frame { min-height: 330px; }
  .map-object { height: 350px; }
  .map-caption > p { white-space: normal; }
  .legend { gap: 4px 8px; }
  .practice-prompt { align-items: flex-start; flex-direction: column; gap: 3px; }
  .info-panel { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
