:root {
  /* TimeTurtle: lagoon and sea-turtle greens, warm sand cards */
  --bg: #E9F6EE;
  --bg-2: #CDEFDC;
  --card: #FFFFFF;
  --ink: #17324A;
  --ink-soft: #4F6A7A;
  --line: #D5EADF;
  --primary: #12A17A;
  --primary-dark: #0B7A5C;
  --primary-soft: #E1F5EC;
  --blue: #3B6BFF;
  --easy: #3CB95A;
  --medium: #F5A524;
  --hard: #EF4560;
  --era-rome: #F7A35C;
  --era-medieval: #B79CF0;
  --era-explore: #5FCFC0;
  --era-industrial: #EBC686;
  --era-modern: #6FB6FF;
  --shadow: 0 6px 0 rgba(31, 35, 64, 0.08), 0 14px 30px rgba(31, 35, 64, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, #FFFFFF 0, transparent 40%),
    radial-gradient(circle at 90% 80%, var(--bg-2) 0, transparent 45%),
    var(--bg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
/* Stop double-tap-to-zoom when tapping buttons quickly (e.g. + and −). */
html, button, input, select, .slider-wrap { touch-action: manipulation; }
button { -webkit-user-select: none; user-select: none; }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  max-width: 520px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.brand-icon { font-size: 28px; display: inline-block; transform: rotate(-10deg); }
.brand-name { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 22px; letter-spacing: -0.3px; }
.brand-name b { color: var(--primary); font-weight: 700; }

.scorebox {
  display: flex; flex-direction: column; align-items: center;
  background: var(--ink); color: #fff;
  border-radius: 14px; padding: 6px 14px 4px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.18);
  min-width: 104px;
}
.scorebox-label { font-size: 10px; font-weight: 800; letter-spacing: 2px; opacity: 0.7; }
.scorebox-value { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 26px; line-height: 1; letter-spacing: 2px; font-variant-numeric: tabular-nums; }
.scorebox.bump { animation: bump 0.45s ease; }
@keyframes bump { 30% { transform: scale(1.15); background: var(--primary); } }

/* ---------- Layout ---------- */
main { max-width: 520px; margin: 0 auto; padding: 4px 16px calc(32px + env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 14px; animation: rise 0.35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 2px solid var(--line);
}
.card-title { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 18px; margin: 0 0 12px; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; cursor: pointer; border-radius: 16px;
  font-weight: 800; transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: translateY(3px); }
.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 5px 0 var(--primary-dark);
}
.btn-primary:active { box-shadow: 0 2px 0 var(--primary-dark); }
.btn-big { width: 100%; padding: 16px 18px; font-size: 18px; font-family: "Fredoka", sans-serif; font-weight: 600; letter-spacing: 0.2px; }
.btn-round {
  width: 48px; height: 48px; flex: none;
  background: #F6F1E8; color: var(--ink); font-size: 26px; line-height: 1;
  box-shadow: 0 4px 0 #E3D8C5;
}
.btn-round:active { box-shadow: 0 1px 0 #E3D8C5; }

/* ---------- Start ---------- */
.hero { text-align: center; padding: 26px 20px 22px; }
.hero-badge {
  display: inline-block; background: var(--primary-soft); color: var(--primary-dark);
  font-weight: 800; font-size: 13px; letter-spacing: 0.5px;
  padding: 6px 12px; border-radius: 999px;
}
.hero-title { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 38px; line-height: 1.05; margin: 14px 0 10px; letter-spacing: -0.5px; }
.hero-sub { color: var(--ink-soft); margin: 0 auto 18px; max-width: 34ch; line-height: 1.45; }
.hero-date { color: var(--ink-soft); font-size: 13px; margin: 12px 0 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.stat { background: #FBF7F0; border-radius: 14px; padding: 10px 4px 8px; text-align: center; }
.stat b { display: block; font-family: "Fredoka", sans-serif; font-size: 22px; font-weight: 600; }
.stat span { font-size: 11px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.5px; }
#resultStats { margin-bottom: 0; }

.howto summary { cursor: pointer; font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 17px; list-style: none; }
.howto summary::after { content: "＋"; float: right; color: var(--ink-soft); }
.howto[open] summary::after { content: "－"; }
.howto ol { padding-left: 20px; line-height: 1.55; margin: 12px 0 8px; }
.howto-note { font-size: 13px; color: var(--ink-soft); margin: 0; line-height: 1.45; }

/* ---------- Play ---------- */
.rounds { display: flex; gap: 8px; justify-content: center; padding-top: 2px; }
.dot {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 15px;
  background: #fff; border: 2px solid var(--line); color: var(--ink-soft);
}
.dot.current { border-color: var(--ink); color: var(--ink); transform: translateY(-2px); box-shadow: 0 4px 0 rgba(31,35,64,0.12); }
.dot.done { background: var(--ink); color: #fff; border-color: var(--ink); font-size: 13px; }

.event-card { padding: 18px 20px 20px; }
.event-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pill { font-size: 12px; font-weight: 800; letter-spacing: 1px; color: #fff; padding: 5px 10px; border-radius: 999px; }
.pill.easy { background: var(--easy); }
.pill.medium { background: var(--medium); }
.pill.hard { background: var(--hard); }
.pill.practice { background: var(--blue); }
.round-label { font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.event-title { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 25px; line-height: 1.2; margin: 0; letter-spacing: -0.2px; }

.guess-card { padding-top: 16px; }
.guess-display { text-align: center; margin-bottom: 10px; min-height: 58px; }
.guess-main { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 48px; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.guess-unit { font-weight: 800; font-size: 18px; color: var(--ink-soft); margin-left: 6px; }

/* Slider */
.slider-wrap { position: relative; padding: 18px 0 6px; }
/* The turtle is the slider handle: the real thumb is invisible and the 🐢 sits on top of it. */
.slider-turtle {
  position: absolute; top: 37px; left: 50%; z-index: 2; pointer-events: none;
  font-size: 34px; line-height: 1; transform: translate(-50%, -54%) scaleX(-1);
  filter: drop-shadow(0 3px 4px rgba(23, 50, 74, 0.28));
  transition: transform 0.15s ease;
}
.slider-wrap:active .slider-turtle { transform: translate(-50%, -60%) scaleX(-1) scale(1.12); }
.slider-track {
  position: absolute; left: 0; right: 0; top: 30px; height: 14px; border-radius: 999px;
  background: linear-gradient(90deg,
    var(--era-rome) 0 20%, var(--era-medieval) 20% 40%, var(--era-explore) 40% 65%,
    var(--era-industrial) 65% 85%, var(--era-modern) 85% 100%);
  box-shadow: inset 0 2px 0 rgba(0,0,0,0.08);
}
input[type=range] {
  -webkit-appearance: none; appearance: none;
  position: relative; width: 100%; height: 38px; margin: 0; background: transparent; cursor: pointer;
}
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-runnable-track { height: 38px; background: transparent; }
input[type=range]::-moz-range-track { height: 38px; background: transparent; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 40px; height: 40px; margin-top: -1px; border-radius: 50%;
  background: transparent; border: 0; box-shadow: none;
}
input[type=range]::-moz-range-thumb {
  width: 40px; height: 40px; border-radius: 50%;
  background: transparent; border: 0; box-shadow: none;
}
input[type=range]:disabled { cursor: default; }
input[type=range]:disabled::-webkit-slider-thumb { border-color: var(--ink); }
input[type=range]:disabled::-moz-range-thumb { border-color: var(--ink); }

.eras { position: relative; height: 26px; margin-top: 4px; }
.era { position: absolute; transform: translateX(-50%); font-size: 20px; line-height: 1; }

.marker { position: absolute; top: -26px; transform: translateX(-50%); pointer-events: none; }
.marker span {
  display: block; background: var(--easy); color: #fff; font-size: 11px; font-weight: 800;
  padding: 3px 8px; border-radius: 8px; white-space: nowrap; position: relative;
}
.marker::after {
  content: ""; position: absolute; left: 50%; top: 18px; width: 4px; height: 30px; margin-left: -2px;
  background: var(--easy); border-radius: 2px;
}

.fine { display: flex; align-items: center; gap: 10px; margin: 14px 0 18px; }
.typed {
  flex: 1; display: flex; align-items: stretch; min-width: 0;
  border: 2px solid var(--line); border-radius: 14px; overflow: hidden; background: #FFFCF7;
}
.typed:focus-within { border-color: var(--blue); }
.typed input {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 11px 12px;
  font-weight: 800; font-size: 18px; text-align: center;
}
.typed input:focus { outline: none; }
.typed-tag {
  display: flex; align-items: center; padding: 0 12px; background: #F6F1E8;
  border-right: 2px solid var(--line); font-weight: 800; font-size: 14px; color: var(--ink-soft);
}

/* Reveal */
.reveal { text-align: center; animation: rise 0.3s ease; }
.reveal-points { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 56px; color: var(--primary); line-height: 1; margin: 4px 0 10px; }
.reveal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.reveal-row > div { background: #FBF7F0; border-radius: 14px; padding: 10px 6px; }
.reveal-label { display: block; font-size: 11px; font-weight: 800; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 2px; }
.reveal-answer { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 19px; color: var(--easy); }
.reveal-guess { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 19px; }
.reveal-miss { font-weight: 800; color: var(--ink-soft); font-size: 14px; margin-bottom: 10px; }
.reveal-fact {
  text-align: left; background: #EEF3FF; border-radius: 14px; padding: 12px 14px; margin: 0 0 16px;
  line-height: 1.45; font-size: 15px;
}
.reveal-fact::before { content: "📜 "; }

/* ---------- Results ---------- */
.results-hero { text-align: center; }
.results-total { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 72px; line-height: 1; margin: 14px 0 4px; letter-spacing: -1px; }
.results-total small { font-size: 26px; color: var(--ink-soft); margin-left: 4px; }
.results-rank { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 20px; color: var(--primary-dark); }
.results-emoji { display: flex; justify-content: center; gap: 8px; margin: 14px 0 18px; }
.chip {
  flex: 1; max-width: 72px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: #FBF7F0; border-radius: 14px; padding: 8px 0 6px;
}
.chip-emoji { font-size: 24px; line-height: 1; }
.chip b { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 18px; }
.countdown { margin-top: 14px; font-size: 14px; color: var(--ink-soft); font-weight: 700; }
.countdown b { color: var(--ink); font-variant-numeric: tabular-nums; }

.breakdown { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.breakdown li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; background: #FBF7F0; border-radius: 14px; }
.bd-emoji { font-size: 20px; line-height: 1.3; }
.bd-body { flex: 1; min-width: 0; }
.bd-title { font-weight: 800; line-height: 1.3; }
.bd-sub { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.bd-pts { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; font-weight: 800; padding: 12px 18px; border-radius: 14px;
  transition: all 0.25s ease; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .hero-title { font-size: 32px; }
  .event-title { font-size: 22px; }
  .guess-main { font-size: 42px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Secondary buttons ---------- */
.btn-secondary {
  background: #FFFFFF; color: var(--ink); border: 2px solid var(--line);
  box-shadow: 0 5px 0 #E8DCC8;
}
.actions { display: flex; flex-direction: column; gap: 16px; }
.btn-secondary:active { box-shadow: 0 2px 0 #E8DCC8; }
.btn-small {
  padding: 8px 12px; font-size: 14px; background: #F6F1E8; color: var(--ink);
  box-shadow: 0 3px 0 #E3D8C5;
}
.btn-small:active { box-shadow: 0 1px 0 #E3D8C5; }
.btn-danger { background: #FFE9EC; color: #C42540; box-shadow: 0 3px 0 #F5C7CF; }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.cal-title { font-family: "Fredoka", sans-serif; font-weight: 700; font-size: 26px; margin: 0; }
.cal-sub { color: var(--ink-soft); margin: 6px 0 16px; font-size: 15px; }
.cal-month + .cal-month { margin-top: 22px; }
.cal-month h3 { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 18px; margin: 0 0 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-wd { text-align: center; font-size: 12px; font-weight: 800; color: var(--ink-soft); padding-bottom: 2px; }
.cal-cell {
  aspect-ratio: 1 / 1.1; border-radius: 12px; border: 0; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.cal-cell.blank { background: transparent; }
.cal-cell.off { background: transparent; color: #CFC6B8; }
.cal-cell.open {
  background: #FBF7F0; border: 2px solid var(--line); cursor: pointer;
  box-shadow: 0 3px 0 #EDE3D2;
}
.cal-cell.open:active { transform: translateY(2px); box-shadow: 0 1px 0 #EDE3D2; }
.cal-num { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 17px; line-height: 1; }
.cal-pts { font-size: 11px; font-weight: 800; color: var(--ink-soft); line-height: 1; }
.cal-cell.future { opacity: 0.75; border-style: dashed; }
.cal-cell.partial { background: #FFF6DC; border-color: #F5D98A; }
.cal-cell.played { background: var(--ink); border-color: var(--ink); color: #fff; box-shadow: 0 3px 0 #0E1028; opacity: 1; }
.cal-cell.played .cal-pts { color: #FFD3C6; font-size: 12px; }
.cal-cell.today { border-color: var(--primary); border-style: solid; box-shadow: 0 3px 0 var(--primary-dark); opacity: 1; }
.cal-cell.today .cal-num { color: var(--primary); }
.cal-cell.today.played .cal-num { color: #fff; }

.cal-legend { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 18px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 5px; vertical-align: -1px; }
.lg-today { border: 2px solid var(--primary); }
.lg-played { background: var(--ink); }
.lg-open { background: #FBF7F0; border: 2px solid var(--line); }

.preview-card { background: #FFFBEA; border-color: #F5E2A0; }
.preview-card p { margin: 6px 0 12px; font-size: 14px; color: var(--ink-soft); line-height: 1.45; }
.preview-card code { background: #fff; padding: 1px 5px; border-radius: 5px; font-size: 13px; }

/* ---------- Practice ---------- */
.practice-list { display: flex; flex-direction: column; gap: 12px; }
.practice-item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: #FBF7F0; border: 2px solid var(--line); border-radius: 18px; padding: 14px;
  box-shadow: 0 4px 0 #EDE3D2; cursor: pointer;
}
.practice-item:active { transform: translateY(2px); box-shadow: 0 2px 0 #EDE3D2; }
.pr-icon { font-size: 34px; line-height: 1; }
.pr-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.pr-body b { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 19px; }
.pr-body small { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.pr-play { background: var(--primary); color: #fff; font-weight: 800; font-size: 14px; padding: 8px 12px; border-radius: 12px; box-shadow: 0 3px 0 var(--primary-dark); white-space: nowrap; }
.pr-score { font-family: "Fredoka", sans-serif; font-weight: 600; font-size: 18px; white-space: nowrap; }

/* ---------- Difficulty rating ---------- */
.rate { background: #FBF7F0; border-radius: 16px; padding: 12px; margin: 0 0 16px; }
.rate-q { font-weight: 800; font-size: 14px; color: var(--ink-soft); margin-bottom: 8px; }
.rate-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rate-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 8px 4px;
  font-size: 22px; cursor: pointer; box-shadow: 0 3px 0 #EDE3D2;
}
.rate-btn span { font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.rate-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #EDE3D2; }
.rate-btn.selected { border-color: var(--blue); background: #EEF3FF; box-shadow: 0 3px 0 #C9D6FF; }
.rate-btn.selected span { color: var(--blue); }
.rate-comment { display: flex; gap: 8px; margin-top: 10px; }
.rate-comment input {
  flex: 1; min-width: 0; border: 2px solid var(--line); border-radius: 12px; padding: 9px 10px;
  font-size: 16px; background: #fff;
}
.rate-comment input:focus { outline: none; border-color: var(--blue); }
.rate-thanks { margin-top: 10px; font-weight: 800; font-size: 14px; color: var(--easy); }

.site-footer { text-align: center; padding: 6px 0 4px; font-size: 13px; font-weight: 700; }
.site-footer a { color: var(--ink-soft); }
.btn:disabled { opacity: 0.7; }

/* ---------- TimeTurtle touches ---------- */
.hero-turtle { display: flex; flex-direction: row-reverse; justify-content: center; align-items: center; gap: 4px; margin: -4px 0 8px; }
.ht-turtle { font-size: 58px; line-height: 1; display: inline-block; transform: scaleX(-1); animation: swim 3.2s ease-in-out infinite; }
.ht-trail { font-size: 26px; opacity: 0.55; animation: trail 3.2s ease-in-out infinite; }
@keyframes swim { 0%, 100% { transform: scaleX(-1) translate(0, 0) rotate(0deg); } 50% { transform: scaleX(-1) translate(-6px, -6px) rotate(-4deg); } }
@keyframes trail { 0%, 100% { opacity: 0.55; transform: translateY(0); } 50% { opacity: 0.25; transform: translateY(3px); } }
.event-kicker { font-size: 13px; font-weight: 800; color: var(--primary-dark); letter-spacing: 0.3px; margin-bottom: 4px; }
.results-turtle { font-size: 52px; line-height: 1; margin: 0 auto 8px; display: block; width: max-content; transform: scaleX(-1); animation: hop 1.1s ease-out 1; }
@keyframes hop { 0% { transform: scaleX(-1) translateY(18px) scale(0.6); opacity: 0; } 60% { transform: scaleX(-1) translateY(-8px) scale(1.08); opacity: 1; } 100% { transform: scaleX(-1) translateY(0) scale(1); } }
@media (prefers-reduced-motion: reduce) { .ht-turtle, .ht-trail, .results-turtle { animation: none; } }

/* Shown only on the private test link (ALLOW_FUTURE=true) */
.test-ribbon {
  position: fixed; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 50;
  background: #FFE9A8; color: #6B4B00; border: 1px solid #F0C64A; border-radius: 999px;
  padding: 5px 12px; font-size: 13px; font-weight: 600; pointer-events: none; white-space: nowrap;
}

/* Challenge links: a friend's score rides in the share link */
.challenge {
  margin: 12px 0 4px; padding: 12px 14px; border-radius: 16px;
  background: #FFF4D6; border: 2px solid #F3D27A; text-align: center;
}
.challenge p { margin: 0 0 10px; font-weight: 700; font-size: 16px; line-height: 1.35; }
.challenge .btn { width: 100%; padding: 12px 16px; font-size: 17px; }
.challenge-result {
  margin: 10px auto 2px; padding: 8px 14px; border-radius: 999px; display: inline-block;
  background: #FFF4D6; border: 2px solid #F3D27A; font-weight: 800; font-size: 15px;
}
.home-tip { position: relative; background: var(--primary-soft); }
.home-tip p { margin: 6px 0 0; font-size: 15px; line-height: 1.4; }
.home-tip-x {
  position: absolute; top: 8px; right: 8px; border: 0; background: transparent; font-size: 16px;
  width: 36px; height: 36px; cursor: pointer; touch-action: manipulation; color: inherit; opacity: .6;
}
