:root {
  --color-none: #e2e8f0;
  --color-visited: #34d399;
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273549;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --border: #334155;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  overscroll-behavior-y: contain;
  touch-action: manipulation;
}
header {
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
  text-align: center;
}
header h1 {
  font-size: 17px;
  margin: 0 0 2px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
header p {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

.stats {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px 4px;
  flex-wrap: wrap;
}
.stats[hidden] {
  display: none;
}
.pick-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 6px 12px 0;
  padding: 8px 12px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
}
.pick-banner[hidden] {
  display: none;
}
.pick-banner button {
  flex: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  min-height: 32px;
}
.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
}
.stat-chip .swatch {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--color-visited);
}

.progress-bar-wrap {
  flex-basis: 100%;
  display: flex;
  justify-content: center;
  margin-top: 2px;
}
.progress-bar {
  width: 100%;
  max-width: 280px;
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--color-visited);
  opacity: 0.45;
  border-radius: 999px;
  transition: width 0.3s ease, opacity 0.3s ease, box-shadow 0.3s ease;
}
.progress-fill.complete {
  opacity: 1;
  box-shadow: 0 0 8px 1px rgba(52, 211, 153, 0.7);
}
.stat-chip b { font-size: 13px; }

.map-tabs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px 0;
}
.map-tab {
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.map-tab.active {
  background: var(--accent);
  color: #04222f;
  border-color: var(--accent);
  font-weight: 600;
}

.map-viewport {
  position: relative;
  width: calc(100% - 16px);
  max-width: 560px;
  margin: 4px auto 0;
  overflow: hidden;
  touch-action: none;
  aspect-ratio: var(--map-aspect, 1 / 1);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
}
.zoom-layer {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}
.map-wrap {
  position: absolute;
  inset: 0;
}
.map-wrap[hidden] {
  display: none;
}
.map-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
  -webkit-user-select: none;
  user-select: none;
}
.map-wrap .prefecture,
.map-wrap .country {
  cursor: pointer;
  transition: fill 0.15s ease, opacity 0.15s ease;
}
.map-wrap .prefecture:active,
.map-wrap .country:active {
  opacity: 0.75;
}

/* Prefecture <g>s each carry their own SVG `transform="matrix(...)"`
   placing them on the map; the CSS `transform` property (used below for
   the pop) overrides that attribute outright rather than combining with
   it, which sent every prefecture jumping to its untransformed origin
   mid-animation. --pop-base captures that original transform (read from
   the attribute in JS, since it uses the same matrix()/none syntax as
   CSS) so the keyframes can layer the scale on top of it instead of
   replacing it. World map countries have no such attribute, so
   --pop-base is simply "none" there and this is a no-op. */
@keyframes region-pop {
  0% { transform: var(--pop-base, matrix(1, 0, 0, 1, 0, 0)) scale(1); }
  40% { transform: var(--pop-base, matrix(1, 0, 0, 1, 0, 0)) scale(1.12); }
  100% { transform: var(--pop-base, matrix(1, 0, 0, 1, 0, 0)) scale(1); }
}
.region-pop {
  transform-box: fill-box;
  transform-origin: center;
  animation: region-pop 0.35s ease-out;
}
#world-map .country {
  stroke: #0f172a;
  stroke-width: 0.6;
  stroke-linejoin: round;
}

/* The zoom buttons live in the action row under the map rather than
   floating over it: any corner of a world map has countries under it
   (the right edge covers the Americas), so a floating control always
   made some of them untappable at the default zoom. */
.zoom-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.zoom-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(30, 41, 59, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.zoom-btn:active {
  background: var(--panel-2);
}
.zoom-btn.zoom-reset {
  font-size: 14px;
}

.map-label {
  font-size: 12px;
  font-weight: 600;
  fill: #0f172a;
  stroke: #ffffff;
  stroke-width: 2px;
  paint-order: stroke fill;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
  display: none;
}
.show-labels .map-label {
  display: block;
}

#japan-map.show-wishlist .wishlist-marked,
#world-map.show-wishlist .wishlist-marked {
  stroke: #f59e0b;
  stroke-width: 2.5px;
  stroke-dasharray: 4 2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.wishlist-view {
  position: relative;
  width: calc(100% - 16px);
  max-width: 560px;
  margin: 4px auto 0;
  min-height: 240px;
}
.wishlist-view[hidden] {
  display: none;
}
.wishlist-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 72px;
}
.wishlist-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.wishlist-card.completed {
  opacity: 0.6;
}
.wishlist-card.completed .wishlist-card-name,
.wishlist-card.completed .wishlist-card-memo {
  text-decoration: line-through;
}
.wishlist-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.wishlist-card-name {
  font-size: 15px;
  font-weight: 600;
}
.wishlist-card-deadline {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.wishlist-card-memo {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  word-break: break-word;
}
.wishlist-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.wishlist-card-actions button {
  flex: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  padding: 8px 10px;
  min-height: 36px;
}
.wishlist-card-actions .visit-check {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 10px;
  min-height: 36px;
  cursor: pointer;
}
.wishlist-card-actions .visit-check input {
  width: 16px;
  height: 16px;
  accent-color: #04222f;
}
.wishlist-card-actions .visit-check:has(input:checked) {
  background: var(--accent);
  color: #04222f;
  border-color: var(--accent);
}
.wishlist-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 40px 20px;
}
.wishlist-add-btn {
  position: fixed;
  right: max(20px, calc((100% - 560px) / 2 + 20px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #04222f;
  border: none;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  z-index: 10;
}
.wishlist-add-btn:active {
  filter: brightness(0.92);
}

.form-field {
  margin-bottom: 14px;
}
.form-field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.form-field select,
.form-field input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  min-height: 44px;
}
.modal-btn-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.modal-btn-row .modal-close-btn {
  margin-top: 0;
}

.actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
}
.actions[hidden] {
  display: none;
}
button.action-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
}
button.action-btn:active { background: var(--panel-2); }
button.action-btn.toggled {
  border-color: var(--accent);
  color: var(--accent);
}

.attribution {
  text-align: center;
  font-size: 10px;
  color: var(--text-dim);
  padding: 0 16px 12px;
  line-height: 1.6;
}
.attribution a { color: var(--text-dim); }
.attribution button.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-dim);
  text-decoration: underline;
  font-size: inherit;
  cursor: pointer;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.modal-overlay.open {
  display: flex;
}
.modal-sheet {
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  padding: 18px 20px calc(24px + env(safe-area-inset-bottom));
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-sheet h2 {
  margin: 0 0 12px;
  font-size: 16px;
}
.modal-sheet section {
  margin-bottom: 16px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text-dim);
}
#onboardingModal section {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
}
.modal-sheet section h3 {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text);
}
.modal-sheet a { color: var(--accent); }
.modal-close-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  min-height: 44px;
}
.modal-close-btn[hidden] {
  display: none;
}
.share-sheet img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 52vh;
  margin: 0 auto 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.modal-close-btn.primary {
  background: var(--accent);
  color: #04222f;
  border-color: var(--accent);
  font-weight: 600;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.toast.achievement {
  background: linear-gradient(135deg, #34d399, #10b981);
  color: #04222f;
  border-color: transparent;
  font-size: 15px;
  font-weight: 700;
  padding: 14px 22px;
  box-shadow: 0 10px 32px rgba(52, 211, 153, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes toast-pop {
  0% { transform: translate(-50%, 0) scale(0.8); }
  55% { transform: translate(-50%, 0) scale(1.08); }
  100% { transform: translate(-50%, 0) scale(1); }
}
.toast.achievement.show {
  animation: toast-pop 0.4s ease-out;
}
.toast.milestone {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #2d1a00;
  border-color: transparent;
  font-size: 16px;
  font-weight: 800;
  padding: 16px 24px;
  box-shadow: 0 12px 36px rgba(245, 158, 11, 0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes toast-pop-big {
  0% { transform: translate(-50%, 0) scale(0.7); }
  50% { transform: translate(-50%, 0) scale(1.12); }
  75% { transform: translate(-50%, 0) scale(0.97); }
  100% { transform: translate(-50%, 0) scale(1); }
}
.toast.milestone.show {
  animation: toast-pop-big 0.5s ease-out;
}
.toast.complete-celebration {
  background: linear-gradient(135deg, #fde68a, #fbbf24, #f59e0b);
  color: #2d1a00;
  border-color: transparent;
  font-size: 17px;
  font-weight: 800;
  padding: 18px 28px;
  box-shadow: 0 14px 44px rgba(245, 158, 11, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes toast-pop-grand {
  0% { transform: translate(-50%, 0) scale(0.6); }
  45% { transform: translate(-50%, 0) scale(1.15); }
  65% { transform: translate(-50%, 0) scale(0.96); }
  85% { transform: translate(-50%, 0) scale(1.04); }
  100% { transform: translate(-50%, 0) scale(1); }
}
.toast.complete-celebration.show {
  animation: toast-pop-grand 0.65s ease-out;
}
