/* TEN FLAT — enamel stopwatch dial at the center; phone-first single column, live feed pinned to a screen edge */
:root {
  --bg: #e9ece8;
  --face: #f8f9f6;
  --ink: #17201c;
  --muted: #5f6a64;
  --rule: #c9cfca;
  --soft: #dde2de;
  --accent: #2443c9;
  --hand: #e0402a;
  --good: #1f8a52;
  --font-display: "Dela Gothic One", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-body: "Zen Kaku Gothic New", system-ui, "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-num: "Azeret Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --live-h: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613; --face: #1b221e; --ink: #e8ede9; --muted: #95a099; --rule: #313b35; --soft: #232b26;
    --accent: #7d95ff; --hand: #ff6a50; --good: #4cc887; color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: calc(var(--live-h) + env(safe-area-inset-bottom, 0px) + 12px);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; padding-block: 14px 8px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.logo { font-family: var(--font-display); font-weight: 400; font-size: 1.45rem; letter-spacing: .04em; margin: 0; white-space: nowrap; }
.logo span { color: var(--hand); }
.top-actions { display: flex; gap: 6px; min-width: 0; }
.chip-btn {
  border: 1px solid var(--rule); background: var(--face); border-radius: 999px; padding: 6px 12px;
  font-size: .8rem; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; min-width: 0;
}
.profile-btn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9em; }

/* tabs */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--soft); padding: 4px; border-radius: 14px; }
.tabs button {
  border: 0; background: transparent; border-radius: 10px; padding: 8px 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; line-height: 1.25; color: var(--muted);
}
.tabs button span { font-weight: 700; font-size: .95rem; }
.tabs button small { font-size: .7rem; letter-spacing: .04em; }
.tabs button[aria-selected="true"] { background: var(--face); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }
.tabs button[aria-selected="true"] span { color: var(--ink); }

.round-info { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.round-info .day { font-family: var(--font-num); font-weight: 600; color: var(--ink); letter-spacing: .06em; }
.round-info b { font-family: var(--font-num); font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }


/* stage */
.stage { display: flex; flex-direction: column; gap: 12px; }
.dial {
  width: min(100%, 300px, 40vh); aspect-ratio: 1; margin: 0 auto; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.dial svg { width: 100%; height: 100%; display: block; }
.dial-label { font-family: var(--font-num); font-size: 8px; fill: var(--muted); letter-spacing: 1px; }
.readout {
  text-align: center; font-family: var(--font-num); font-weight: 800;
  font-size: clamp(2.8rem, 15vw, 4.2rem); line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}
.readout small { font-size: .36em; font-weight: 400; color: var(--muted); margin-left: .15em; }
.readout.hidden-num { color: var(--rule); }

.verdict { text-align: center; min-height: 3.2em; display: flex; flex-direction: column; gap: 2px; align-items: center; justify-content: center; }
.verdict .word { font-family: var(--font-display); font-size: 1.45rem; line-height: 1.2; }
.verdict .diff { font-size: .88rem; color: var(--muted); }
.verdict .diff b { font-family: var(--font-num); color: var(--ink); font-weight: 600; }
.v-perfect .word { color: var(--hand); animation: pop .5s ease-out; }
.v-ok .word { color: var(--good); }
.v-near .word { color: var(--accent); }
.v-far .word { color: var(--muted); }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

.go {
  font-family: var(--font-display); font-size: 1.25rem; letter-spacing: .08em;
  border: 0; border-radius: 16px; padding: 18px; min-height: 64px; cursor: pointer;
  background: var(--accent); color: var(--face); touch-action: manipulation; user-select: none; -webkit-user-select: none;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, var(--ink));
}
.go.stop { background: var(--hand); box-shadow: 0 4px 0 color-mix(in srgb, var(--hand) 60%, var(--ink)); }
.go:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.go:disabled { background: var(--soft); color: var(--muted); box-shadow: none; cursor: default; transform: none; }
.hint { text-align: center; font-size: .75rem; color: var(--muted); margin: -4px 0 0; }

.result-card {
  background: var(--face); border: 1px solid var(--rule); border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px; align-items: stretch;
}
.rank-line { display: flex; align-items: baseline; justify-content: center; gap: 8px; flex-wrap: wrap; font-size: .9rem; color: var(--muted); }
.rank-line b { font-family: var(--font-num); font-size: 1.6rem; color: var(--ink); }
.share-main {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  border: 0; border-radius: 12px; padding: 15px 12px; min-height: 54px; cursor: pointer;
  background: var(--accent); color: var(--face); font-weight: 700; font-size: 1rem;
}
.share-main svg { width: 20px; height: 20px; flex: none; }
.share-sub { margin: -4px 0 0; text-align: center; font-size: .75rem; color: var(--muted); }
.share-row { display: flex; gap: 8px; }
.share-x {
  flex: 2; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ink); color: var(--bg); text-decoration: none; border-radius: 12px; padding: 13px 12px; font-weight: 700; min-height: 48px;
}
.share-x svg { width: 18px; height: 18px; flex: none; }
.share-x:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.share { flex: 1; border: 1px solid var(--ink); background: transparent; border-radius: 12px; padding: 12px 8px; font-weight: 700; cursor: pointer; min-height: 48px; white-space: nowrap; }
.share-note { margin: 0; text-align: center; font-size: .8rem; color: var(--good); min-height: 1.2em; }

/* board */
.board { display: flex; flex-direction: column; gap: 8px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.board h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.1rem; }
.seg { display: flex; border: 1px solid var(--rule); border-radius: 999px; padding: 2px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 5px 12px; font-size: .78rem; color: var(--muted); cursor: pointer; }
.seg button[aria-selected="true"] { background: var(--ink); color: var(--bg); font-weight: 700; }
.board-sub { margin: 0; font-size: .78rem; color: var(--muted); }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rows li {
  display: grid; grid-template-columns: 2.4em 1.6em minmax(0, 1fr) auto; gap: 8px; align-items: center;
  padding: 9px 4px; border-bottom: 1px solid var(--rule); font-size: .9rem;
}
.rows li.me { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 8px; }
.rows .rk { font-family: var(--font-num); font-weight: 600; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.rows li:nth-child(-n+3) .rk { color: var(--hand); }
.rows .fl { font-size: 1.15rem; line-height: 1; text-align: center; }
.rows .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .nm small { display: block; font-size: .72rem; color: var(--muted); }
.rows .tm { font-family: var(--font-num); text-align: right; font-variant-numeric: tabular-nums; line-height: 1.25; }
.rows .tm small { display: block; font-size: .72rem; color: var(--muted); }
.rows .tm.perfect { color: var(--hand); font-weight: 600; }
.rows .empty { display: block; color: var(--muted); font-size: .85rem; padding: 14px 4px; border: 0; }
.pending { font-size: .8rem; color: var(--muted); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.pending ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.pending li { background: var(--face); border: 1px solid var(--rule); border-radius: 999px; padding: 3px 10px; }

.foot { font-size: .75rem; color: var(--muted); text-align: center; padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.foot p { margin: 0; }
.foot a { color: var(--muted); }

/* yesterday */
.yesterday { display: flex; flex-direction: column; gap: 6px; background: var(--face); border: 1px solid var(--rule); border-radius: 14px; padding: 14px 14px 8px; }
.yesterday h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.05rem; }
.yday { font-family: var(--font-num); font-size: .78rem; font-weight: 600; color: var(--muted); letter-spacing: .06em; }
.yesterday .rows li:last-child { border-bottom: 0; }
.y-country { margin: 0; padding: 8px 4px 6px; border-top: 1px solid var(--rule); font-size: .85rem; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.y-country b { font-weight: 700; }
.y-country .num { font-family: var(--font-num); }

/* analytics consent (shown to visitors in Europe) */
.consent {
  position: fixed; z-index: 40; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--live-h) + env(safe-area-inset-bottom, 0px) + 10px);
  width: min(440px, calc(100% - 24px)); background: var(--face); border: 1px solid var(--rule); border-radius: 14px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .15); padding: 14px; display: flex; flex-direction: column; gap: 10px; font-size: .85rem;
}
.consent p { margin: 0; }
.consent a { color: var(--accent); }
.consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.consent-actions button { border-radius: 10px; padding: 10px; font-weight: 700; cursor: pointer; }
@media (min-width: 900px) { .consent { bottom: 20px; } }

/* live feed: phone = bar pinned to the bottom edge showing the newest result */
.live {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--live-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 max(16px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(16px, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--face) 92%, transparent); border-top: 1px solid var(--rule);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 12px; overflow: hidden;
}
.live-title { font-family: var(--font-num); font-size: .68rem; font-weight: 800; letter-spacing: .14em; color: var(--hand); display: flex; align-items: center; gap: 6px; flex: none; }
.live-title i { width: 7px; height: 7px; border-radius: 50%; background: var(--hand); animation: blink 1.6s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.live ol { list-style: none; margin: 0; padding: 0; min-width: 0; flex: 1; }
.live li { display: none; align-items: center; gap: 8px; min-width: 0; font-size: .88rem; }
.live li:first-child { display: flex; animation: slidein .45s ease-out; }
.live li .fl { font-size: 1.1rem; flex: none; }
.live li .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.live li .tm { font-family: var(--font-num); margin-left: auto; flex: none; font-variant-numeric: tabular-nums; }
.live li.perfect .tm { color: var(--hand); font-weight: 800; }
.live li.waiting { display: flex; color: var(--muted); font-size: .8rem; }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* wide screens: feed becomes a panel on the right edge */
@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .app { padding-block: 28px 12px; }
  .live {
    left: auto; right: max(20px, env(safe-area-inset-right, 0px)); bottom: 20px; top: auto; width: 250px; height: auto;
    padding: 12px 14px; border: 1px solid var(--rule); border-radius: 14px;
    flex-direction: column; align-items: stretch; gap: 8px;
  }
  .live li { display: flex; padding: 6px 0; border-top: 1px solid var(--rule); animation: none; }
  .live li:first-child { border-top: 0; }
}
@media (min-width: 900px) and (max-width: 1200px) {
  .app { margin-left: max(0px, calc((100% - 480px - 290px) / 2)); }
}

/* profile sheet */
.modal { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 440px; background: var(--face); border-radius: 18px 18px 0 0;
  padding: 20px max(18px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 8px;
}
@media (min-width: 600px) { .modal { align-items: center; } .sheet { border-radius: 18px; padding: 22px; } }
.sheet h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.25rem; }
.sheet-sub { margin: 0 0 6px; font-size: .82rem; color: var(--muted); }
.sheet label { font-size: .8rem; font-weight: 700; margin-top: 4px; }
.sheet input, .sheet select {
  font: inherit; font-size: 16px; /* 16px keeps iOS from zooming */
  padding: 11px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--bg); color: var(--ink); width: 100%;
}
.form-error { margin: 0; min-height: 1.2em; font-size: .8rem; color: var(--hand); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }
.sheet-actions button { border-radius: 12px; padding: 13px; cursor: pointer; font-weight: 700; }
.ghost { border: 1px solid var(--rule); background: transparent; }
.primary { border: 0; background: var(--accent); color: var(--face); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
