/* Shared shell for the daily games: header, sheet, leaderboard, archive, settings. */
html, body { height: 100%; overscroll-behavior: none; }

.app {
  height: 100vh; height: 100dvh;
  max-width: 500px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

/* ---------- Header ---------- */
.top {
  display: grid;
  grid-template-columns: 44px 44px 1fr 44px 44px;
  align-items: center;
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.brand h1 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 30px; letter-spacing: -.01em; }
.day-chip {
  display: inline-flex; align-items: center; gap: 1px; margin-top: 4px;
  border: 0; background: none; padding: 2px 4px 2px 8px; border-radius: 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3);
}
.day-chip:hover { color: var(--ink-2); }
.day-chip .icon { width: 14px; height: 14px; }

.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--ink); background: var(--surface-2); }

.past-banner {
  margin: 10px 14px 0; padding: 8px 8px 8px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 13px; color: var(--ink-2);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.past-banner[hidden] { display: none; }
.past-banner button { border: 0; background: var(--surface-2); padding: 6px 10px; border-radius: 7px; font-weight: 600; font-size: 13px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 76px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 14px;
  padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow);
  animation: toastIn .2s var(--ease) both;
}
.toast.out { animation: toastOut .25s ease-in both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }
@keyframes toastOut { to { opacity: 0; } }

/* ---------- Sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade .2s both; }
.sheet {
  position: relative; width: 100%; max-width: 500px; max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-elev); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(28px + env(safe-area-inset-bottom));
  animation: up .35s var(--ease) both;
}
.modal.closing .sheet { animation: down .2s ease-in both; }
.modal.closing .modal-backdrop { animation: fade .2s reverse both; }
@media (min-width: 620px) {
  .modal { align-items: center; }
  .sheet { border-radius: 20px; border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
  .grabber { display: none; }
}
@keyframes up { from { transform: translateY(100%); } }
@keyframes down { to { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.grabber { width: 36px; height: 4px; border-radius: 4px; background: var(--border-strong); margin: -8px auto 12px; }
.sheet .close { position: absolute; top: 10px; right: 10px; }

.sheet h2 { font-family: var(--serif); font-weight: 400; font-size: 32px; letter-spacing: -.01em; margin: 2px 0 6px; }
.sheet .lede { color: var(--ink-2); font-size: 15px; line-height: 1.5; margin: 0 0 16px; }
.sheet h3 { font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin: 24px 0 10px; }
.sheet p, .sheet li { font-size: 15px; line-height: 1.55; color: var(--ink-2); }
.sheet p b, .sheet li b { color: var(--ink); }
.sheet ul { padding-left: 18px; margin: 0; }

/* Result header */
.result { text-align: center; padding: 6px 0 4px; }
.result .note { font-family: var(--serif); font-style: italic; font-size: 19px; color: var(--ink-2); margin: 0; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 18px; }
.countdown { flex: 1; text-align: left; }
.countdown small { display: block; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.countdown b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }

/* Segmented control */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; margin-top: 22px; border-radius: 10px; background: var(--surface-2); }
.seg button { border: 0; background: none; padding: 8px 0; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); transition: background .2s, color .2s; }
.seg button[aria-selected="true"] { background: var(--bg-elev); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.pane { margin-top: 14px; min-height: 120px; }

/* Leaderboard rows */
.lb { list-style: none; padding: 0; margin: 0; }
.lb li { display: grid; grid-template-columns: 22px 1fr auto auto; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); color: var(--ink); }
.lb li:last-child { border-bottom: 0; }
.lb li.me { background: var(--surface); border-radius: 10px; border-bottom-color: transparent; padding-left: 10px; padding-right: 10px; margin: 0 -6px; }
.lb .rank { font-size: 13px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.lb .who { font-weight: 600; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .who small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.lb .score { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.lb .score small { display: block; font-size: 11px; font-weight: 500; color: var(--ink-3); }
.muted { color: var(--ink-3) !important; font-size: 14px; }
.empty { text-align: center; padding: 26px 8px; color: var(--ink-3); font-size: 14px; line-height: 1.5; }

/* Join */
.join { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.join p { margin: 0 0 12px; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { border: 1px solid var(--border-strong); background: transparent; border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 500; }
.chip:hover { border-color: var(--ink-3); }
.join-form { display: flex; gap: 8px; }
.join-form input {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--ink);
  font: inherit; font-size: 16px;
}
.join-form input:focus { outline: none; border-color: var(--ink-2); }

/* Personal stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stat b { display: block; font-size: 26px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--ink-3); }
.dist { display: grid; gap: 4px; }
.dist-row { display: grid; grid-template-columns: 12px 1fr; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.dist-bar { min-width: 24px; width: 0; background: var(--surface-2); color: var(--ink); border-radius: 4px; padding: 3px 7px; text-align: right; font-size: 12px; transition: width .6s var(--ease); }
.dist-bar.hl { background: var(--correct); color: var(--on-mark); }

/* Archive */
.archive { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.day {
  position: relative; aspect-ratio: 1; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  display: grid; place-content: center; gap: 2px; text-align: center;
  font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums;
  transition: transform .1s, border-color .15s;
}
.day small { font-weight: 500; font-size: 10px; color: var(--ink-3); }
.day:hover:not(:disabled) { border-color: var(--border-strong); }
.day:active:not(:disabled) { transform: scale(.95); }
.day.won { background: var(--correct); border-color: transparent; color: var(--on-mark); }
.day.won small { color: rgba(255, 255, 255, .8); }
.day.lost { background: var(--absent); border-color: transparent; color: var(--on-mark); }
.day.lost small { color: rgba(255, 255, 255, .7); }
.day.playing { border-color: var(--present); }
.day.today::after { content: ""; position: absolute; top: 6px; right: 6px; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.day.current { outline: 2px solid var(--ink); outline-offset: 2px; }
.day:disabled { opacity: .35; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px; font-size: 12px; color: var(--ink-3); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* Settings */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting:last-of-type { border-bottom: 0; }
.setting b { display: block; font-size: 15px; font-weight: 600; color: var(--ink); }
.setting small { color: var(--ink-3); font-size: 13px; }
.switch { position: relative; flex: none; width: 46px; height: 28px; border-radius: 99px; border: 0; padding: 0; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border-strong); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .25s var(--ease); }
.switch[aria-checked="true"] { background: var(--correct); box-shadow: none; }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.link-btn { border: 0; background: none; padding: 6px 0; font-weight: 600; font-size: 14px; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--border-strong); }

.note-line { margin-top: 12px; }
