:root {
  --bg: #0b0d10;
  --panel: #161a20;
  --panel2: #212831;
  --line: #2b333d;
  --text: #f2f4f7;
  --muted: #909baa;
  --accent: #ff9f0a;
  --go: #30d158;
  --stop: #ff453a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { color-scheme: dark; }

/* ---------- Export ---------- */
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet {
  position: fixed; inset: 0; z-index: 5; background: rgba(0, 0, 0, .6);
  display: flex; align-items: flex-end;
}
.sheet-box {
  width: 100%; max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 6px 16px calc(16px + var(--sab));
}
.sheet-box h2 { margin-top: 16px; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; padding: 10px 4px; }
.dates { display: flex; gap: 10px; margin-top: 10px; }
.dates label { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.dates input {
  width: 100%; min-width: 0; height: 46px; padding: 0 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 16px; -webkit-appearance: none; appearance: none;
}
.sheet-box .muted { margin: 10px 2px 0; }
.sheet-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.sheet-btns .btn { font-size: 17px; padding: 15px; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
[hidden] { display: none !important; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--sat);
}

main { flex: 1; min-height: 0; position: relative; }

.view { display: none; height: 100%; flex-direction: column; padding: 0 16px; }
.view.active { display: flex; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 24px; }
.view.scroll.active { display: block; }

h1 { font-size: 28px; margin: 14px 0 10px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }

/* ---------- Timer ---------- */
.bar { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 2px 0; }
.bar-item { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.bar-item b { font-size: 26px; }
.lbl { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.of { color: var(--muted); font-size: 18px; }

.display { text-align: center; padding: 6px 0 4px; }
.status { font-size: 20px; font-weight: 600; color: var(--muted); min-height: 27px; }
.time {
  font-size: clamp(84px, 29vw, 150px);
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.sub { font-size: 18px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 25px; }

body[data-state="standby"] .status { color: var(--accent); }
body[data-state="running"] .status { color: var(--go); }
body[data-state="running"] .time { color: var(--go); }

.mid { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 0; }

.shots { display: flex; flex-direction: column; gap: 6px; }
.shot {
  display: grid;
  grid-template-columns: 44px 1fr 1fr;
  align-items: center;
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 14px;
  font-variant-numeric: tabular-nums;
  font-size: 22px;
}
.shot .n { color: var(--muted); font-size: 17px; }
.shot .t { font-weight: 700; }
.shot .s { color: var(--muted); text-align: right; font-size: 18px; }
.shot.last .t { color: var(--accent); }
.shot.off { opacity: .4; }
.shot.off .t { text-decoration: line-through; color: var(--text); }

.review { margin-top: 12px; }
.hint { color: var(--muted); font-size: 14px; margin: 6px 2px; }
.standing {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--panel); border-radius: 14px; padding: 10px 10px 10px 14px; margin-top: 8px;
}
.calc { text-align: center; padding: 12px 0 4px; font-size: 18px; color: var(--muted); font-variant-numeric: tabular-nums; }
.calc b { color: var(--text); font-size: 24px; }

.stepper { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.stepper button {
  width: 48px; height: 44px; border: 0; border-radius: 11px;
  background: var(--panel2); font-size: 26px; line-height: 1; font-weight: 500;
}
.stepper button:active { background: var(--line); }
.stepper b { min-width: 64px; text-align: center; font-size: 19px; font-variant-numeric: tabular-nums; }

.session-box { display: none; }
body[data-state="idle"] .session-box { display: block; }
.series-list { display: flex; flex-direction: column; gap: 6px; }
.serie {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  background: var(--panel); border-radius: 12px; padding: 10px 14px; font-variant-numeric: tabular-nums;
}
.serie .n { color: var(--muted); min-width: 34px; }
.serie .d { color: var(--muted); font-size: 15px; flex: 1; }
.serie .r { font-weight: 700; font-size: 20px; }
.serie.best .r { color: var(--go); }
.note {
  width: 100%; margin-top: 10px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: transparent; outline: none;
  -webkit-user-select: text; user-select: text;
}
.note:focus { border-color: var(--accent); }
.row-btns { display: flex; gap: 8px; margin-top: 10px; }
.row-btns .btn { flex: 1; }

.actions { display: flex; gap: 10px; padding: 10px 0 12px; }
.btn {
  border: 0; border-radius: 16px; padding: 14px 16px; font-weight: 700;
  background: var(--panel2); color: var(--text);
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: .4; }
.btn.small { font-size: 15px; padding: 10px 14px; border-radius: 11px; font-weight: 600; }
.btn.ghost { background: var(--panel2); }
.btn.danger { background: rgba(255, 69, 58, .18); color: var(--stop); }
.btn.main { flex: 1; font-size: 30px; letter-spacing: .04em; padding: 0 16px; height: 96px; }
.actions .btn.ghost { height: 96px; font-size: 18px; }
.btn.start { background: var(--accent); color: #1a1000; }
.btn.stopb { background: var(--stop); color: #fff; }
.btn.cancel { background: var(--panel2); color: var(--text); }
.btn.score { background: var(--go); color: #032b0e; font-size: 24px; }

/* ---------- Tabs ---------- */
#tabs {
  display: flex;
  border-top: 1px solid var(--line);
  background: #0e1115;
  padding-bottom: var(--sab);
}
#tabs button {
  flex: 1; border: 0; background: none; color: var(--muted);
  padding: 8px 0 6px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
#tabs button.active { color: var(--accent); }
#tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body[data-state="standby"] #tabs,
body[data-state="running"] #tabs,
body[data-state="starting"] #tabs { display: none; }
body[data-state="standby"] .actions,
body[data-state="running"] .actions,
body[data-state="starting"] .actions { padding-bottom: calc(12px + var(--sab)); }

/* ---------- Settings / History ---------- */
.group { background: var(--panel); border-radius: 14px; overflow: hidden; }
.row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--line); min-height: 60px;
}
.group > .row:last-child, .group > div:last-child > .row:last-child { border-bottom: 0; }
.row.col { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px; }
.row-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: 14px; }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 32px; }

.meter { position: relative; height: 16px; border-radius: 8px; background: var(--panel2); overflow: hidden; }
.meter-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--go); }
.meter.hit .meter-fill { background: var(--stop); }
.meter-thr { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--accent); }

.seg { display: flex; background: var(--panel2); border-radius: 11px; padding: 3px; }
.seg button { border: 0; background: none; padding: 9px 13px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--accent); color: #1a1000; }

.toggle { width: 58px; height: 34px; border-radius: 17px; border: 0; background: var(--panel2); position: relative; flex-shrink: 0; }
.toggle i { position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle[aria-checked="true"] { background: var(--go); }
.toggle[aria-checked="true"] i { transform: translateX(24px); }

.foot { color: var(--muted); font-size: 13px; text-align: center; margin: 26px 10px 10px; }
.empty { color: var(--muted); text-align: center; margin-top: 60px; }

.card { background: var(--panel); border-radius: 14px; margin-bottom: 10px; overflow: hidden; }
.card summary { list-style: none; padding: 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.card summary::-webkit-details-marker { display: none; }
.card .when { font-size: 14px; color: var(--muted); }
.card .ttl { font-weight: 600; }
.card .sum { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.card .body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.card .line { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0 0; font-variant-numeric: tabular-nums; }
.card .line .sh { display: block; color: var(--muted); font-size: 13px; }
.card .stats { color: var(--muted); font-size: 14px; padding-top: 10px; }
.card .row-btns { margin-top: 12px; }

/* ---------- Flash + Toast ---------- */
body.flash #app { animation: flash .35s ease-out; }
@keyframes flash { 0% { background: var(--go); } 100% { background: transparent; } }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(130px + var(--sab));
  background: #2d3540; color: var(--text); padding: 12px 16px; border-radius: 14px;
  text-align: center; font-size: 15px; opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 10;
}
#toast.show { opacity: 1; transform: none; }

@media (max-height: 620px) {
  .btn.main, .actions .btn.ghost { height: 76px; }
  .time { font-size: clamp(64px, 24vw, 110px); }
}

.card .line b { white-space: nowrap; text-align: right; }
.card .line > span { min-width: 0; }
.btn.small { white-space: nowrap; }
