/* Shared base styles -- loaded by both this page and placename/index.html
   (as ../style.css there), which layers its own placename/style.css on
   top for anything placename-specific. Both pages reuse the exact same
   element IDs/classes wherever the visual pattern is identical (hint-bar,
   controls, catchup-panel/list/item, result-panel, score-grade/number/
   message, buttons), so a fix here fixes both at once; only genuinely
   different pieces live in each page's own stylesheet. */
:root {
  --ocean-deep: #0b3d5c;
  --ocean-mid: #1c5d82;
  --ocean-light: #2f7ea6;
  --ink: #eaf6ff;
  --accent: #ffb703;
  --player-color: #ff5252;
  --real-color: #2ecc71;
  --miss-color: #9b59b6;
  --panel-bg: rgba(255, 255, 255, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(180deg, #06263b 0%, #0b3d5c 100%);
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
}

header {
  text-align: center;
  margin-bottom: 16px;
}

h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  letter-spacing: 0.05em;
}

.subtitle {
  margin: 0;
  opacity: 0.8;
  font-size: 0.95rem;
}

#best-score-line {
  margin-top: 6px;
  opacity: 1;
  color: var(--accent);
  font-weight: 600;
}

.cross-link {
  margin-top: 10px;
  font-size: 0.82rem;
}

.cross-link a {
  color: var(--ink);
  opacity: 0.75;
  text-decoration: none;
  border-bottom: 1px solid rgba(234, 246, 255, 0.35);
}

.cross-link a:hover {
  opacity: 1;
}

#mode-toggle {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin: 10px auto 0;
  background: var(--panel-bg);
  border-radius: 999px;
  padding: 3px;
  width: fit-content;
}

.mode-btn {
  padding: 6px 16px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  opacity: 0.65;
  transition: background 0.15s, opacity 0.15s;
}

.mode-btn.active {
  background: var(--ocean-light);
  opacity: 1;
  font-weight: 700;
}

#challenge-desc {
  margin-top: 6px;
  color: var(--accent);
  font-size: 0.85rem;
}

#challenge-tools {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
}

/* Author `display` rules always beat the UA's default [hidden]{display:none}
   regardless of specificity/source order -- learned the hard way with
   .toggle-hint earlier, so every element here that's toggled via the
   `hidden` attribute (not just a class) needs this same override. */
#challenge-tools[hidden] {
  display: none;
}

#catchup-btn,
#back-to-today-btn {
  padding: 5px 12px;
  font-size: 0.78rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: var(--panel-bg);
  color: var(--ink);
  cursor: pointer;
}

#catchup-btn:hover,
#back-to-today-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

#catchup-panel {
  width: 100%;
  max-width: 420px;
  margin: 10px auto 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--panel-bg);
  text-align: left;
}

.catchup-panel-title {
  margin: 0 0 8px;
  font-size: 0.82rem;
  opacity: 0.85;
}

#catchup-list {
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.catchup-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
}

.catchup-item:hover {
  background: rgba(255, 255, 255, 0.14);
}

.catchup-item.done {
  background: rgba(46, 204, 113, 0.14);
}

.catchup-item.done:hover {
  background: rgba(46, 204, 113, 0.24);
}

.catchup-date {
  font-weight: 700;
  opacity: 0.9;
}

.catchup-summary {
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.catchup-status {
  opacity: 0.8;
  white-space: nowrap;
  font-size: 0.75rem;
}

#catchup-close-btn {
  margin-top: 10px;
  padding: 6px 16px;
  font-size: 0.8rem;
}

main {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#hint-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  margin-bottom: 12px;
  font-size: 0.85rem;
}

/* Wasn't toggled via the `hidden` attribute until placename mode started
   hiding the whole bar at once (previously only individual children inside
   it were ever hidden) -- same [hidden]-vs-author-display-rule cascade bug
   as .toggle-hint/#challenge-tools before it. */
#hint-bar[hidden] {
  display: none;
}

.hint {
  background: var(--panel-bg);
  padding: 4px 10px;
  border-radius: 999px;
}

.toggle-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.toggle-hint[hidden] {
  display: none;
}

.toggle-hint input {
  cursor: pointer;
}

#canvas-wrap {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  touch-action: none;
  cursor: crosshair;
}

#canvas-wrap canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#result-canvas {
  pointer-events: none;
}

/* Suggests rotating the phone when today's challenge map is landscape-
   shaped but the phone is held in portrait -- overlaid on the canvas
   (not in normal flow) so it doesn't eat into the height budget, and
   non-interactive so it never blocks drawing underneath it. */
#rotate-hint {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
  font-size: 0.78rem;
  text-align: center;
  pointer-events: none;
}

#controls {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Same cascade bug as #hint-bar above -- placename mode is the first thing
   to ever hide this whole bar rather than just individual buttons in it. */
#controls[hidden] {
  display: none;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: var(--ocean-light);
  color: var(--ink);
  transition: background 0.15s, transform 0.1s;
}

button:hover {
  background: #3a92bd;
}

button:active {
  transform: scale(0.97);
}

#finish-btn {
  background: var(--accent);
  color: #2a1a00;
  font-weight: 700;
}

#finish-btn:hover {
  background: #ffc733;
}

#retry-btn {
  background: var(--real-color);
  color: #06331a;
  font-weight: 700;
}

#download-card-btn {
  background: transparent;
  border: 2px solid var(--ocean-light);
  color: var(--ink);
}

#download-card-btn:hover {
  background: var(--ocean-light);
}

#result-panel {
  margin-top: 20px;
  padding: 18px 24px;
  border-radius: 12px;
  background: var(--panel-bg);
  text-align: center;
  width: 100%;
}

.scroll-hint {
  display: none;
  margin: 0 0 12px;
  font-size: 0.78rem;
  text-align: center;
  color: rgba(234, 246, 255, 0.75);
}

#new-record-badge {
  font-size: 1rem;
  font-weight: 700;
  color: var(--real-color);
  margin-bottom: 6px;
  animation: pop 0.4s ease;
}

@keyframes pop {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#score-grade {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

#score-number {
  font-size: 1.3rem;
  margin-top: 4px;
  opacity: 0.9;
}

#score-message {
  margin: 10px 0 4px;
  opacity: 0.85;
}

#score-breakdown {
  margin: 14px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.score-item {
  display: grid;
  grid-template-columns: 84px 1fr 40px;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.score-item-label {
  opacity: 0.85;
  white-space: nowrap;
}

.score-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ocean-light), var(--accent));
  transition: width 0.5s ease;
}

.score-item-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  opacity: 0.9;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: center;
  margin-top: 10px;
  font-size: 0.85rem;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.swatch-correct {
  background: var(--real-color);
}

.swatch-over {
  background: var(--player-color);
}

.swatch-under {
  background: var(--miss-color);
}

#score-analysis {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.analysis-line {
  font-size: 0.85rem;
  line-height: 1.5;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 8px 12px;
}

/* Compact mobile layout: the goal is to fit the whole canvas in the
   viewport (no scrolling needed mid-draw, which is what causes stray
   strokes when a scroll gesture starts on the canvas instead of the
   page) and keep 完成/清除重畫 etc. always reachable via a bottom bar
   that's fixed regardless of scroll position or canvas height. */
@media (max-width: 640px) {
  body {
    padding: 10px 10px calc(78px + env(safe-area-inset-bottom, 0px));
  }

  .tagline {
    display: none;
  }

  header {
    margin-bottom: 8px;
  }

  h1 {
    font-size: 1.3rem;
    margin-bottom: 2px;
  }

  #best-score-line {
    margin-top: 2px;
    font-size: 0.78rem;
  }

  #hint-bar {
    gap: 4px 8px;
    margin-bottom: 8px;
    font-size: 0.72rem;
  }

  .hint {
    padding: 3px 8px;
  }

  /* Sized to fit within the height budget without ever distorting: width
     is the smaller of "100% of the container" and "the height budget
     scaled by the map's own aspect ratio" (--map-ratio, set in JS whenever
     the projection is (re)configured), then height is left to derive from
     width via aspect-ratio. A landscape-shaped daily-challenge map (after
     a ~90° rotation) still shrinks to fit, correctly proportioned, instead
     of being squashed by width and height fighting each other. */
  #canvas-wrap {
    width: min(100%, calc((100vh - 190px) * var(--map-ratio, 0.6)));
    width: min(100%, calc((100dvh - 190px) * var(--map-ratio, 0.6)));
    height: auto;
    min-height: 200px;
  }

  #controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    gap: 8px;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(6, 38, 59, 0.95);
    backdrop-filter: blur(6px);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.35);
    z-index: 10;
  }

  #controls button {
    padding: 9px 14px;
    font-size: 0.88rem;
  }

  .scroll-hint {
    display: block;
  }
}
