:root {
  --c-main: #8B4513;
  --c-sub: #D2691E;
  --c-accent: #FFD700;
  --c-bg: #F5DEB3;
  --c-text: #2C1810;
  --c-ok: #2e8b57;
  --c-warn: #b22222;
  --c-border: #6f3a14;
  --shadow: 0 10px 24px rgba(44, 24, 16, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--c-text);
  background: radial-gradient(circle at 20% 20%, #f8e8c9 0%, var(--c-bg) 45%, #e7c894 100%);
  font-family: "Noto Serif SC", "Songti SC", "STSong", "KaiTi", serif;
}

body {
  position: relative;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image:
    linear-gradient(45deg, rgba(139, 69, 19, 0.25) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(139, 69, 19, 0.25) 25%, transparent 25%);
  background-size: 26px 26px;
  background-position: 0 0, 13px 13px;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 1720px;
  margin: 0 auto;
  padding: 16px 20px;
}

.page {
  animation: fade-in 0.25s ease-out;
}

.hidden {
  display: none !important;
}

.title {
  margin: 20px 0 8px;
  text-align: center;
  color: var(--c-main);
  letter-spacing: 1px;
  font-size: clamp(1.8rem, 4.2vw, 2.8rem);
}

.subtitle {
  margin: 0 0 20px;
  text-align: center;
  color: var(--c-sub);
  font-size: clamp(0.95rem, 2vw, 1.15rem);
}

.version-text {
  margin: -10px 0 14px;
  text-align: center;
  color: #7f4f2a;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.card {
  background: rgba(255, 248, 230, 0.72);
  border: 2px solid var(--c-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.mode-grid {
  margin: 16px auto;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  width: min(760px, 92vw);
}

.difficulty-panel {
  width: min(760px, 92vw);
  margin: 10px auto 0;
}

.difficulty-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.difficulty-row + .difficulty-row {
  margin-top: 8px;
}

.difficulty-row label {
  font-weight: 700;
  color: #6f3a14;
}

.difficulty-row select {
  min-width: 220px;
  max-width: 100%;
  padding: 7px 10px;
  border: 2px solid var(--c-border);
  border-radius: 8px;
  background: #fff4dc;
  color: #5f2f12;
  font-weight: 700;
}

.map-tools {
  width: min(96vw, 1580px);
  margin: 0 auto 10px;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  gap: 12px;
}

.map-tools-main {
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  flex-direction: column;
  gap: 12px;
  flex-wrap: wrap;
  width: 100%;
}

.map-primary-row {
  flex-wrap: wrap;
}

.assist-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.map-tools-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
}

.map-pan-pad {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 36px);
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 8px;
}

.map-tools button {
  white-space: nowrap;
}

.pan-btn {
  width: 44px;
  height: 36px;
  padding: 0;
}

.pan-up {
  grid-area: up;
}

.pan-left {
  grid-area: left;
}

.pan-right {
  grid-area: right;
}

.pan-down {
  grid-area: down;
}

.rules-box {
  width: min(760px, 92vw);
  margin: 10px auto 0;
}

.rules-box h3 {
  margin: 0 0 6px;
  color: #6f3a14;
  font-size: 1.05rem;
}

.rules-box p {
  margin: 4px 0;
  color: #5f2f12;
  line-height: 1.45;
}

.records-box {
  width: min(760px, 92vw);
  margin: 10px auto 0;
}

.records-box h3 {
  margin: 0 0 6px;
  color: #6f3a14;
  font-size: 1.05rem;
}

.records-content {
  color: #5f2f12;
  line-height: 1.55;
  font-weight: 700;
}

.record-line + .record-line {
  margin-top: 4px;
}

button {
  border: 2px solid var(--c-border);
  border-radius: 10px;
  background: linear-gradient(180deg, #f3c47d 0%, var(--c-sub) 100%);
  color: #fffbe9;
  font-weight: 700;
  font-size: 1rem;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

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

button.secondary {
  background: linear-gradient(180deg, #c89f74 0%, #8a5a35 100%);
}

.muted {
  text-align: center;
  color: #5e4333;
  margin-top: 12px;
}

.error {
  text-align: center;
  color: #7f1d1d;
  margin-top: 8px;
  font-weight: 700;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 10px;
}

.question-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 1.06rem;
  line-height: 1.4;
}

#question {
  font-weight: 700;
  color: var(--c-main);
}

.feedback {
  min-height: 1.4em;
  font-weight: 700;
  text-align: right;
}

.feedback-ok {
  color: var(--c-ok);
}

.feedback-warn,
.feedback-error {
  color: var(--c-warn);
}

.map-shell {
  width: min(96vw, 1580px);
  height: clamp(520px, 78vh, 920px);
  margin: 0 auto 10px;
  border: 3px solid var(--c-border);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(244, 224, 185, 0.94) 0%, rgba(232, 194, 132, 0.96) 100%);
  overflow: hidden;
  touch-action: none;
}

.map-shell.review {
  height: clamp(360px, 56vh, 640px);
}

.map-shell svg {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.map-basemap {
  fill: rgba(120, 74, 41, 0.48);
  pointer-events: none;
}

.map-basemap.map-theme-world {
  fill: rgba(101, 67, 44, 0.46);
}

.map-outline {
  fill: none;
  stroke: #2b1408;
  stroke-width: 2.2;
  opacity: 0.98;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.map-outline.map-theme-world {
  stroke-width: 1.45;
}

.map-feature {
  fill: rgba(118, 64, 29, 0.62);
  stroke: rgba(60, 29, 10, 0.88);
  stroke-width: 0.9;
  stroke-opacity: 0.9;
  vector-effect: non-scaling-stroke;
  transition: fill 0.12s ease;
}

.map-feature-no-border {
  stroke: none !important;
  fill: transparent;
}

@media (hover: hover) and (pointer: fine) {
  .map-feature:hover {
    fill: rgba(245, 183, 74, 0.9);
  }

  .map-feature-hard:hover {
    fill: transparent !important;
  }
}

.feature-target {
  fill: rgba(255, 215, 0, 0.55);
}

.feature-selected {
  fill: rgba(210, 105, 30, 0.62);
}

.feature-correct,
.feature-review-correct {
  fill: rgba(46, 139, 87, 0.58) !important;
}

.feature-wrong,
.feature-review-wrong {
  fill: rgba(178, 34, 34, 0.56) !important;
}

.distance-line {
  stroke: #5c1f08;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  vector-effect: non-scaling-stroke;
}

.target-marker {
  fill: #ffcc00;
  stroke: #6f3a14;
  stroke-width: 2;
}

.player-marker {
  fill: #2e8b57;
  stroke: #1f4f37;
  stroke-width: 1.5;
}

.controls {
  width: min(96vw, 1580px);
  margin: 0 auto;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.dev-tools {
  width: min(96vw, 1580px);
  margin: 0 auto 10px;
  padding: 10px 12px;
}

.dev-tools-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.dev-tools-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.dev-tools textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.4;
  color: #2d1b12;
  background: rgba(255, 248, 232, 0.95);
  border: 1px solid #8b5a33;
  border-radius: 8px;
  padding: 8px;
}

.result-title {
  text-align: center;
  margin: 14px 0;
  color: var(--c-main);
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.details {
  width: min(860px, 92vw);
  margin: 0 auto 12px;
  line-height: 1.7;
  font-size: 1.02rem;
}

.history {
  width: min(980px, 92vw);
  margin: 10px auto;
  overflow-x: auto;
}

.history table {
  width: 100%;
  border-collapse: collapse;
}

.history th,
.history td {
  border-bottom: 1px dashed #8f5c2c;
  padding: 8px 6px;
  font-size: 0.95rem;
  text-align: left;
  vertical-align: top;
}

.history th {
  color: #6f3a14;
}

@media (max-width: 768px) {
  #app {
    padding: 10px;
  }

  .mode-grid {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .difficulty-row {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
  }

  .difficulty-row select {
    width: 100%;
  }

  .rules-box {
    width: 100%;
  }

  .records-box {
    width: 100%;
  }

  .map-tools {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .map-tools-main {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .map-tools-row {
    width: 100%;
  }

  .map-tools-row button {
    flex: 1 1 48%;
  }

  .assist-tools {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .map-pan-pad {
    width: 100%;
    justify-content: center;
  }

  .header-row {
    flex-wrap: wrap;
  }

  .question-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .map-shell {
    width: 100%;
    height: 64vh;
  }

  .map-shell.review {
    height: 52vh;
  }

  .controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .controls button {
    flex: 1 1 45%;
  }

  .dev-tools-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (min-width: 769px) {
  .map-shell {
    width: min(95vw, 1560px);
    height: clamp(540px, 80vh, 960px);
    margin: 0 auto 10px;
  }

  .controls {
    width: min(95vw, 1560px);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
