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

:root {
  --bg-deep: #1a1a2e;
  --bg-accent: #28345f;
  --panel: #ffffff;
  --panel-soft: #f5f7fb;
  --line: #d7ddea;
  --text-main: #1a1a2e;
  --text-sub: #62708a;
  --gold: #ffd700;
  --danger: #e74c3c;
  --danger-deep: #c0392b;
  --success: #27ae60;
}

body {
  font-family: 'Segoe UI', 'Noto Sans JP', sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at top, rgba(94, 129, 244, 0.2), transparent 32%),
    linear-gradient(180deg, #11172d 0%, var(--bg-deep) 52%, #101624 100%);
}

#start-screen {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top, rgba(129, 156, 255, 0.16), transparent 28%),
    linear-gradient(180deg, #11172d 0%, var(--bg-deep) 52%, #101624 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#start-screen.hidden { display: none; }

#start-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(244, 247, 252, 0.98) 100%);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 28px;
  padding: 34px 32px 30px;
  text-align: center;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  max-width: 720px;
  width: min(100%, 720px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  backdrop-filter: blur(14px);
}

#start-title-wrap {
  margin-bottom: 24px;
}

#start-title-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(40, 52, 95, 0.09);
  color: var(--bg-accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  margin-bottom: 14px;
}

#start-title {
  font-size: clamp(21px, 4vw, 32px);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.15;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
  white-space: nowrap;
}

#start-subtitle {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.6;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: left;
}

.setting-row-stacked {
  display: block;
}

.setting-row-featured {
  background:
    linear-gradient(180deg, rgba(40, 52, 95, 0.08) 0%, rgba(255, 255, 255, 0.96) 100%);
  border-color: rgba(40, 52, 95, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.setting-row-featured label {
  color: var(--bg-accent);
}

.setting-row label {
  font-size: 13px;
  color: #33415c;
  min-width: 96px;
  font-weight: 700;
}

.setting-row-stacked label {
  display: block;
  min-width: 0;
  margin-bottom: 10px;
}

.setting-row input[type="number"] {
  width: 72px;
  padding: 8px 10px;
  border: 1.5px solid #c7d0df;
  border-radius: 10px;
  font-size: 14px;
  text-align: center;
  outline: none;
  background: var(--panel-soft);
}

.setting-row input[type="number"]:focus,
.setting-row select:focus {
  border-color: var(--bg-accent);
  box-shadow: 0 0 0 3px rgba(40, 52, 95, 0.08);
}

.setting-row select {
  flex: 1;
  padding: 8px 10px;
  border: 1.5px solid #c7d0df;
  border-radius: 10px;
  font-size: 13px;
  outline: none;
  background: var(--panel-soft);
}

.difficulty-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.difficulty-btn {
  border: 1.5px solid #c7d0df;
  background: linear-gradient(180deg, #ffffff 0%, #eef2f9 100%);
  color: #33415c;
  border-radius: 12px;
  padding: 12px 0;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.difficulty-btn:hover {
  border-color: rgba(40, 52, 95, 0.45);
}

.difficulty-btn:focus-visible {
  outline: none;
  border-color: var(--bg-accent);
  box-shadow: 0 0 0 3px rgba(40, 52, 95, 0.12);
}

.difficulty-btn:active {
  transform: scale(0.98);
}

.difficulty-btn.is-active {
  color: white;
  border-color: var(--bg-accent);
  background: linear-gradient(135deg, var(--bg-accent) 0%, var(--bg-deep) 100%);
  box-shadow: 0 10px 20px rgba(26, 26, 46, 0.18);
}

.setting-note {
  margin-top: 10px;
  font-size: 12px;
  color: #6f7788;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--bg-accent);
}

.setting-value {
  min-width: 56px;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  color: var(--bg-accent);
}

.setting-unit {
  font-size: 12px;
  color: #7a859b;
  white-space: nowrap;
  display: block;
  margin-top: 8px;
}

.setting-row-toggle select {
  max-width: 120px;
}

.switch {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 56px;
  height: 32px;
  border-radius: 999px;
  background: #cfd7e6;
  box-shadow: inset 0 0 0 1px rgba(40, 52, 95, 0.12);
  transition: background 0.2s ease;
}

.switch-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(17, 23, 45, 0.24);
  transition: transform 0.2s ease;
}

.switch-labels {
  position: relative;
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #70809d;
  min-width: 32px;
}

.switch-labels span {
  display: none;
}

.switch-labels span:first-child {
  display: inline;
}

.switch input:checked ~ .switch-labels span {
  display: none;
}

.switch input:checked ~ .switch-labels span:last-child {
  display: inline;
}

.switch input:checked + .switch-track {
  background: linear-gradient(135deg, var(--bg-accent) 0%, var(--bg-deep) 100%);
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(24px);
}

.switch input:focus-visible + .switch-track {
  outline: none;
  box-shadow: 0 0 0 3px rgba(40, 52, 95, 0.18);
}

#setting-hintcount-row input:disabled {
  cursor: not-allowed;
}

#start-btn {
  margin-top: 20px;
  background: linear-gradient(135deg, var(--bg-accent) 0%, var(--bg-deep) 100%);
  color: white;
  border: none;
  padding: 15px 0;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

#start-btn:hover:not(:disabled) { filter: brightness(1.06); }
#start-btn:active:not(:disabled) { transform: scale(0.98); }
#start-btn:disabled { opacity: 0.55; cursor: not-allowed; }

#header {
  background: var(--bg-deep);
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  flex-shrink: 0;
  border-bottom: 1px solid #2d2d5e;
}

#round-info {
  font-size: 13px;
  color: #b7c0d4;
  min-width: 90px;
}

#logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

#score-display {
  font-size: 13px;
  color: var(--gold);
  font-weight: 700;
  min-width: 90px;
  text-align: right;
}

#score-display span {
  font-size: 20px;
}

#question-banner {
  background: white;
  text-align: center;
  padding: 14px 16px 10px;
  flex-shrink: 0;
  border-bottom: 3px solid #e8e8e8;
}

#municipality-name {
  display: block;
  font-size: 30px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: 0.08em;
}

.name-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.name-main {
  display: block;
}

.name-ruby {
  display: block;
  font-size: 0.42em;
  line-height: 1.1;
  letter-spacing: 0.12em;
  color: #6f7788;
  font-weight: 600;
}

#prefecture-hint {
  display: block;
  font-size: 13px;
  color: #888;
  margin-top: 3px;
}

#timer {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 4px;
  min-height: 18px;
}

#timer[data-urgent="true"] {
  color: var(--danger);
  animation: timerPulse 0.6s ease-in-out infinite;
}

@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes perfectHitGlow {
  0%, 100% { box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25); }
  50% { box-shadow: 0 -8px 34px rgba(255, 196, 0, 0.48); }
}

@keyframes perfectHitPop {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.14); }
  70% { transform: scale(0.96); }
}

@keyframes perfectPinPulse {
  0%, 100% { box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(255, 215, 0, 0.22), 0 8px 18px rgba(39, 174, 96, 0.45); }
}

#map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: #ffffff;
}

#instruction {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(26, 26, 46, 0.88);
  color: #ddd;
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  z-index: 900;
  pointer-events: none;
}

#result-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 3px solid var(--bg-deep);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 1000;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.25);
  transform: translateY(0);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#result-panel.hidden {
  transform: translateY(110%);
}

#result-panel[data-hit="perfect"] {
  border-top-color: #f1c40f;
  background: linear-gradient(180deg, #fffef4 0%, #ffffff 100%);
  animation: perfectHitGlow 0.9s ease-in-out 2;
}

#result-left {
  flex: 1;
}

#result-status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#result-distance {
  font-size: 20px;
  font-weight: 700;
  color: #222;
}

#result-distance[data-hit="perfect"] {
  color: #b7791f;
  letter-spacing: 0.04em;
}

#result-adjacent-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 14px;
  border: 2px solid #f59e0b;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff3bf 0%, #facc15 100%);
  color: #6b3f00;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
  box-shadow: 0 8px 20px rgba(245, 158, 11, 0.3);
  white-space: nowrap;
  transform: translateY(-1px);
}

#result-adjacent-badge.hidden {
  display: none;
}

#result-guess {
  font-size: 13px;
  color: #444;
  margin-top: 4px;
}

#result-label {
  font-size: 13px;
  color: #666;
  margin-top: 2px;
}

#result-guess,
#result-label {
  line-height: 1.45;
}

.result-entity {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.result-entity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(40, 52, 95, 0.08);
  color: var(--bg-accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.result-entity-body {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  color: #33415c;
  font-weight: 700;
}

.result-entity-body .name-stack {
  margin-left: 0;
  vertical-align: top;
  align-items: flex-start;
}

#instruction .name-stack {
  margin-left: 2px;
  vertical-align: top;
}

#result-points-wrap {
  display: flex;
  align-items: baseline;
  gap: 3px;
  min-width: 80px;
  justify-content: center;
}

#result-points {
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
}

#result-points-unit {
  font-size: 16px;
  color: #666;
}

#result-points[data-level="high"]  { color: var(--success); }
#result-points[data-level="mid"]   { color: #e67e22; }
#result-points[data-level="low"]   { color: var(--danger); }
#result-points[data-level="zero"]  { color: #aaa; }

#result-points[data-hit="perfect"] {
  color: #f1c40f;
  text-shadow: 0 0 18px rgba(241, 196, 15, 0.32);
  animation: perfectHitPop 0.7s ease-out 2;
}

#next-btn {
  background: var(--bg-deep);
  color: white;
  border: none;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
}

#next-btn:hover  { background: #2d2d5e; }
#next-btn:active { transform: scale(0.97); }

#game-over {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #f6f8fd 0%, #edf3fb 100%);
  overflow-y: auto;
  padding: 24px 22px 28px;
  z-index: 2000;
}

#game-over.hidden { display: none; }

#game-over-card {
  background: transparent;
  border-radius: 0;
  padding: 0;
  text-align: center;
  box-shadow: none;
  max-width: 1180px;
  width: 100%;
  min-height: calc(100dvh - 52px);
  margin: 0 auto;
  overflow: visible;
}

#final-msg {
  font-size: 25px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 14px;
}

#final-score {
  font-size: 44px;
  font-weight: 800;
  color: var(--success);
  line-height: 1;
}

#final-difficulty {
  font-size: 14px;
  color: #62708a;
  margin-top: 8px;
  margin-bottom: 14px;
  font-weight: 700;
}

.round-results {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
  text-align: left;
}

.round-result-item {
  padding: 14px 15px;
  border: 1px solid #d7ddea;
  border-radius: 14px;
  background: #f8faff;
}

.round-result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.round-result-number {
  font-size: 13px;
  font-weight: 800;
  color: var(--bg-accent);
}

.round-result-points {
  font-size: 15px;
  font-weight: 800;
}

.round-result-points[data-level="high"]  { color: var(--success); }
.round-result-points[data-level="mid"]   { color: #e67e22; }
.round-result-points[data-level="low"]   { color: var(--danger); }
.round-result-points[data-level="zero"]  { color: #aaa; }

.round-result-answer {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.45;
}

.round-result-selection {
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.45;
  color: #62708a;
}

.share-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

#share-x-btn,
#share-line-btn,
#game-over-card .secondary-action,
#restart-btn {
  background: var(--bg-deep);
  color: white;
  border: none;
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
}

#share-x-btn,
#share-line-btn {
  width: 100%;
}

#share-x-btn {
  background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 100%);
}

#share-line-btn {
  background: linear-gradient(135deg, #06c755 0%, #00a63e 100%);
}

#share-x-btn:hover,
#share-line-btn:hover {
  filter: brightness(1.06);
}

#share-x-btn:active,
#share-line-btn:active {
  transform: scale(0.97);
}

#game-over-card .secondary-action {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  background: #eef2f9;
  color: var(--bg-accent);
}

#restart-btn {
  width: 100%;
}

#game-over-card .secondary-action:hover {
  background: #dde6f6;
}

#game-over-card .secondary-action:active {
  transform: scale(0.97);
}

#restart-btn:hover  { background: #2d2d5e; }
#restart-btn:active { transform: scale(0.97); }

#confirm-btn {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  border: none;
  padding: 14px 36px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  z-index: 950;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
  white-space: nowrap;
}

#confirm-btn:hover  { background: var(--danger-deep); }
#confirm-btn:active { transform: translateX(-50%) scale(0.97); }

#confirm-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

#hint-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  background: rgba(255, 215, 0, 0.96);
  color: #3d2d00;
  border: none;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  z-index: 950;
  box-shadow: 0 10px 24px rgba(20, 23, 35, 0.2);
  transition: transform 0.1s ease, filter 0.2s ease, opacity 0.2s ease;
  white-space: nowrap;
}

#hint-btn:hover:not(:disabled) {
  filter: brightness(1.04);
}

#hint-btn:active:not(:disabled) {
  transform: scale(0.97);
}

#hint-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#hint-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

.pin-guess,
.pin-answer {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.pin-guess  { background: var(--danger); }
.pin-answer { background: var(--success); }

.pin-answer-perfect {
  border-color: rgba(255, 244, 184, 0.96);
  animation: perfectPinPulse 0.85s ease-in-out 3;
}

.map-municipality-tooltip {
  border: none;
  border-radius: 999px;
  color: #fff;
  padding: 0;
  white-space: nowrap;
}

.map-municipality-tooltip::before {
  display: none;
}

.map-municipality-tooltip-selected {
  background: rgba(37, 99, 235, 0.94);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.28);
}

.map-municipality-tooltip-answer {
  background: rgba(39, 174, 96, 0.94);
  box-shadow: 0 6px 18px rgba(39, 174, 96, 0.28);
}

.map-entity {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.map-entity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.map-entity-body {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.map-entity-body .name-stack {
  align-items: flex-start;
}

.map-entity-body .name-ruby {
  color: rgba(255, 255, 255, 0.82);
}

@media (max-width: 640px) {
  #start-screen {
    align-items: flex-start;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  }

  #start-card {
    width: 100%;
    max-height: calc(100dvh - max(24px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    padding: 24px 16px 20px;
    border-radius: 22px;
  }

  #start-title {
    font-size: clamp(16px, 5vw, 24px);
    letter-spacing: 0.01em;
  }

  #start-subtitle {
    font-size: 12px;
  }

  .setting-row {
    gap: 8px;
    padding: 10px 12px;
  }

  .setting-row label {
    min-width: 82px;
    font-size: 12px;
  }

  .difficulty-buttons {
    grid-template-columns: 1fr;
  }

  .slider-row {
    gap: 10px;
  }

  .setting-value {
    min-width: 48px;
    font-size: 12px;
  }

  .setting-row select,
  .setting-row input[type="number"] {
    font-size: 12px;
  }

  .switch {
    gap: 8px;
  }

  .switch-track {
    width: 52px;
    height: 30px;
  }

  .switch-thumb {
    width: 22px;
    height: 22px;
  }

  .switch input:checked + .switch-track .switch-thumb {
    transform: translateX(22px);
  }

  #header {
    padding: 10px 12px;
  }

  #logo {
    font-size: 13px;
    letter-spacing: 0.04em;
  }

  #municipality-name {
    font-size: 24px;
    letter-spacing: 0.04em;
  }

  #result-panel {
    padding: 12px 14px;
    gap: 10px;
  }

  #result-points {
    font-size: 34px;
  }

  .share-actions {
    grid-template-columns: 1fr;
  }

  #game-over-card {
    min-height: calc(100dvh - 56px);
  }

  .round-results {
    grid-template-columns: 1fr;
  }

  #hint-btn {
    top: 12px;
    right: 12px;
    padding: 10px 14px;
    font-size: 13px;
  }
}

@media (max-width: 980px) and (min-width: 641px) {
  .round-results {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
