.tdm-game {
  --tdm-bg: #f7f8fc;
  --tdm-card: #ffffff;
  --tdm-text: #263238;
  --tdm-sub: #68727d;
  --tdm-line: #dbe1e8;
  --tdm-accent: #5865f2;
  --tdm-accent-soft: #eef0ff;
  --tdm-good: #1f9d68;
  --tdm-bad: #e24d4d;
  max-width: 920px;
  margin: 24px auto;
  color: var(--tdm-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

.tdm-game *, .tdm-game *::before, .tdm-game *::after { box-sizing: border-box; }

.tdm-card {
  position: relative;
  overflow: hidden;
  padding: 24px;
  border: 1px solid var(--tdm-line);
  border-radius: 24px;
  background: var(--tdm-card);
  box-shadow: 0 12px 38px rgba(30, 44, 75, 0.09);
}

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

.tdm-eyebrow {
  margin: 0 0 3px;
  color: var(--tdm-accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.tdm-title { margin: 0; font-size: clamp(25px, 4vw, 38px); line-height: 1.2; }

.tdm-reset, .tdm-replay, .tdm-retry-wrong {
  appearance: none;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  transition: transform .15s ease, opacity .15s ease, box-shadow .15s ease;
}

.tdm-reset {
  flex: 0 0 auto;
  padding: 9px 14px;
  background: #f0f2f5;
  color: #4d5966;
  font-size: 13px;
}

.tdm-reset:hover, .tdm-replay:hover, .tdm-retry-wrong:hover { transform: translateY(-1px); }

.tdm-status-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}

.tdm-stat {
  min-width: 0;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--tdm-bg);
  text-align: center;
}

.tdm-stat span { display: block; margin-bottom: 1px; color: var(--tdm-sub); font-size: 11px; font-weight: 700; }
.tdm-stat strong { font-size: 17px; }

.tdm-progress {
  height: 7px;
  overflow: hidden;
  margin-bottom: 10px;
  border-radius: 999px;
  background: #edf0f4;
}

.tdm-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--tdm-accent);
  transition: width .28s ease;
}

/* 問題カードは「中央に収まる小さめの帯」にする */
.tdm-question-box {
  width: min(100%, 560px);
  margin: 0 auto 8px;
  padding: 10px 16px 11px;
  border-radius: 18px;
  background: var(--tdm-accent-soft);
  text-align: center;
  line-height: 1.15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 0 !important;
}

.tdm-question-label,
.tdm-instruction {
  display: block;
  margin: 0 !important;
  color: var(--tdm-sub);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.tdm-question {
  margin: 0 !important;
  color: var(--tdm-accent);
  font-size: clamp(24px, 4.2vw, 34px);
  font-weight: 900;
  line-height: 1.08;
}

.tdm-instruction {
  margin: 0 !important;
}

.tdm-feedback {
  min-height: 22px;
  margin: 4px 0 6px;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}

.tdm-feedback.is-good { color: var(--tdm-good); }
.tdm-feedback.is-bad { color: var(--tdm-bad); }

.tdm-map-wrap {
  position: relative;
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 8px;
  border-radius: 20px;
  background: linear-gradient(180deg, #fafdff 0%, #f4f8fb 100%);
  touch-action: manipulation;
}

.tdm-map-wrap .geolonia-svg-map { display: block; width: 100%; height: auto; }

.tdm-map-wrap .prefecture {
  fill: #e8edf2 !important;
  stroke: #647381 !important;
  stroke-width: 1.4 !important;
  cursor: pointer;
  outline: none;
  transition: fill .15s ease, opacity .15s ease;
}

.tdm-map-wrap .prefecture:hover, .tdm-map-wrap .prefecture:focus { fill: #d7dcff !important; }
.tdm-map-wrap .prefecture.is-cleared { fill: #c8eadb !important; }
.tdm-map-wrap .prefecture.is-correct { fill: #4dc490 !important; }
.tdm-map-wrap .prefecture.is-wrong { fill: #f27b7b !important; }

.tdm-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(255,255,255,.93);
  backdrop-filter: blur(2px);
}
.tdm-overlay[hidden] { display: none; }

.tdm-overlay-panel {
  width: min(100%, 480px);
  padding: 18px 18px 16px;
  border: 2px solid #b8e8cd;
  border-radius: 24px;
  background: linear-gradient(180deg, #f6fff9 0%, #eff8ff 100%);
  box-shadow: 0 16px 34px rgba(30,44,75,.12);
  text-align: center;
}

.tdm-overlay-title { margin: 0 0 4px; color: var(--tdm-good); font-size: clamp(30px, 5vw, 46px); font-weight: 900; line-height: 1.05; }
.tdm-overlay-name { margin: 0; color: #1e3552; font-size: clamp(24px, 4.4vw, 36px); font-weight: 900; line-height: 1.15; }

.tdm-overlay-shape {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 142px;
  margin: 8px auto 4px;
}

.tdm-shape-svg { display: block; width: min(100%, 190px); height: 132px; overflow: visible; }
.tdm-shape-svg .tdm-shape-geometry path,
.tdm-shape-svg .tdm-shape-geometry polygon,
.tdm-shape-svg .tdm-shape-geometry rect,
.tdm-shape-svg .tdm-shape-geometry circle {
  fill: #4dc490 !important;
  stroke: #1f7b58 !important;
  stroke-width: 1.6 !important;
  vector-effect: non-scaling-stroke;
}

.tdm-overlay-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
  color: #4e5d71;
  font-size: 14px;
  font-weight: 800;
}

.tdm-spinner {
  width: 21px;
  height: 21px;
  border: 3px solid #d2daff;
  border-top-color: var(--tdm-accent);
  border-radius: 50%;
  animation: tdm-spin .8s linear infinite;
}

@keyframes tdm-spin { to { transform: rotate(360deg); } }

.tdm-wrong-panel {
  width: min(100%, 680px);
  margin: 12px auto 0;
  padding: 11px 13px;
  border: 1px solid #f2c4c4;
  border-radius: 14px;
  background: #fff7f7;
}
.tdm-wrong-panel[hidden] { display: none; }
.tdm-wrong-heading { margin-bottom: 7px; color: #a73f3f; font-size: 13px; font-weight: 800; }
.tdm-wrong-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tdm-wrong-chip { padding: 4px 9px; border-radius: 999px; background: #ffe2e2; color: #8f3535; font-size: 12px; font-weight: 800; }

.tdm-complete {
  width: min(100%, 760px);
  margin: 16px auto 0;
  padding: 18px 16px 16px;
  border: 2px solid #ffd76d;
  border-radius: 20px;
  background: #fffaf0;
  text-align: center;
}
.tdm-complete[hidden] { display: none; }
.tdm-complete-icon {
  font-size: 34px;
  line-height: 1;
  margin-bottom: 6px;
}
.tdm-complete h3 {
  margin: 0 0 8px;
  font-size: clamp(24px, 4vw, 32px);
  line-height: 1.2;
}
.tdm-complete p {
  margin: 0;
  line-height: 1.5;
}
.tdm-complete p[data-tdm-complete-message] {
  margin-bottom: 12px;
}
.tdm-result {
  margin: 0 0 10px;
  font-size: 16px;
}
.tdm-complete-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.tdm-replay, .tdm-retry-wrong { min-width: 230px; padding: 11px 18px; }
.tdm-replay { background: var(--tdm-accent); color: #fff; box-shadow: 0 7px 18px rgba(88,101,242,.24); }
.tdm-retry-wrong { background: #e55656; color: #fff; box-shadow: 0 7px 18px rgba(226,77,77,.2); }
.tdm-retry-wrong[hidden] { display: none; }

@media (max-width: 600px) {
  .tdm-game { margin: 12px auto; }
  .tdm-card { padding: 14px 11px 17px; border-radius: 18px; }
  .tdm-header { align-items: center; margin-bottom: 10px; }
  .tdm-reset { padding: 8px 11px; font-size: 12px; }
  .tdm-stat { padding: 7px 5px; }
  .tdm-stat strong { font-size: 15px; }
  .tdm-progress { margin-bottom: 8px; }
  .tdm-question-box { padding: 4px 8px 5px; border-radius: 10px; }
  .tdm-question-label, .tdm-instruction { font-size: 10px; }
  .tdm-question { font-size: 23px; }
  .tdm-feedback { min-height: 20px; margin: 3px 0 5px; font-size: 13px; }
  .tdm-map-wrap { padding: 2px; }
  .tdm-map-wrap .prefecture { stroke-width: 2 !important; }
  .tdm-overlay { padding: 9px; }
  .tdm-overlay-panel { padding: 15px 12px 13px; border-radius: 20px; }
  .tdm-overlay-shape { min-height: 118px; }
  .tdm-shape-svg { height: 108px; width: min(100%, 165px); }
  .tdm-wrong-panel { margin-top: 9px; padding: 9px 10px; }
  .tdm-complete {
    width: 100%;
    margin-top: 14px;
    padding: 16px 12px 14px;
    border-radius: 18px;
  }
  .tdm-complete-icon { font-size: 30px; margin-bottom: 4px; }
  .tdm-complete h3 { margin-bottom: 7px; font-size: 24px; }
  .tdm-complete p[data-tdm-complete-message] { margin-bottom: 10px; }
  .tdm-result { margin-bottom: 9px; font-size: 15px; }
  .tdm-complete-actions { gap: 8px; margin-top: 6px; }
  .tdm-replay, .tdm-retry-wrong { width: 100%; min-width: 0; padding: 11px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .tdm-game *, .tdm-game *::before, .tdm-game *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
