/* Pokie Tracker: shared styles for the home page and recorder (same look as the analyser) */
:root {
    --bg: #f4f7f8;
    --surface: #ffffff;
    --fg: #16232a;
    --muted: #5b6d75;
    --line: #d6e0e4;
    --accent: #0a9fd1;
    --accent-soft: #d8f1fa;
    --win: #1f9d55;
    --win-soft: #dcf3e5;
    --loss: #d4483b;
    --loss-soft: #fbe3e0;
    --key: #eef3f5;
    --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f171b; --surface: #16222a; --fg: #e3edf1; --muted: #8fa3ac; --line: #26363f;
        --accent: #33c0ee; --accent-soft: #123441; --win: #45c27a; --win-soft: #143222;
        --loss: #ef6a5c; --loss-soft: #3a1c19; --key: #1d2c35; color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0f171b; --surface: #16222a; --fg: #e3edf1; --muted: #8fa3ac; --line: #26363f;
    --accent: #33c0ee; --accent-soft: #123441; --win: #45c27a; --win-soft: #143222;
    --loss: #ef6a5c; --loss-soft: #3a1c19; --key: #1d2c35; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }

.wrap {
    max-width: 1000px; margin: 0 auto; padding-block: 24px 48px;
    padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
    display: flex; flex-direction: column; gap: 20px;
}
h1 { font-size: 1.7rem; font-weight: 700; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0; }
.sub { color: var(--muted); margin: 4px 0 0; max-width: 65ch; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.spread { justify-content: space-between; }
.lbl { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.pos { color: var(--win); } .neg { color: var(--loss); }
.muted { color: var(--muted); }

button, .btn {
    font: inherit; font-weight: 500; border-radius: 7px; border: 1px solid var(--line); background: var(--surface);
    color: var(--fg); padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover, .btn:hover { border-color: var(--accent); }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.danger { color: var(--loss); }
.small { padding: 5px 10px; font-size: .95rem; }
.filebtn { position: relative; }
.filebtn input { position: absolute; width: 1px; height: 1px; opacity: 0; }

input[type=text], input[type=number], select {
    font: inherit; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); width: 100%;
}
input[type=number] { font-family: var(--mono); }
.field { display: flex; flex-direction: column; gap: 4px; }

.toast { font-size: 1rem; min-height: 1.3em; color: var(--win); }
.toast.err { color: var(--loss); }

/* ---------- home ---------- */
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.action {
    display: flex; flex-direction: column; gap: 4px; padding: 20px; border-radius: 10px; text-decoration: none; color: var(--fg);
    background: var(--surface); border: 1px solid var(--line);
}
.action:hover { border-color: var(--accent); }
.action .icon { font-size: 1.8rem; line-height: 1; }
.action b { font-size: 1.1rem; }
.action span { color: var(--muted); font-size: 1rem; }
.action.main { background: var(--accent); border-color: var(--accent); color: #fff; }
.action.main span { color: rgba(255, 255, 255, .85); }

.sessions { display: flex; flex-direction: column; gap: 10px; }
.session { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.session-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.session-head b { font-size: 1rem; }
.session-figs { display: flex; gap: 18px; flex-wrap: wrap; font-size: 1rem; }
.session-figs .k { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; display: block; }
.empty { margin: 0; padding: 24px 12px; text-align: center; color: var(--muted); }
details summary { cursor: pointer; font-weight: 600; }
details pre { background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 10px; overflow-x: auto; font-size: .95rem; }
.table-wrap { overflow-x: auto; }
table.fmt { border-collapse: collapse; width: 100%; font-size: 1rem; }
table.fmt th, table.fmt td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }

/* ---------- recorder ----------
   The page is locked to the screen height (no scrolling): the fixed-size rows take what
   they need and the LOSS button, number pad and WIN button share the rest. */
body.rec { overscroll-behavior: none; height: 100vh; height: 100dvh; overflow: hidden; }
.rec-wrap {
    max-width: 480px; margin: 0 auto; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 8px; overflow: hidden;
    padding: max(8px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(10px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
}
.rec-wrap > * { flex: none; }
.rec-top { display: flex; align-items: center; gap: 6px; }
.rec-top .title { flex: 1; min-width: 0; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-top .icon-btn { padding: 5px 9px; font-size: 1rem; }
.rec-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.rec-stats div { background: var(--surface); padding: 5px 6px; text-align: center; min-width: 0; }
.rec-stats .v { font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 1.1rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-stats .k { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.streak { font-size: .98rem; color: var(--muted); text-align: center; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.recent { display: flex; gap: 6px; align-items: center; height: 36px; }
.chips { flex: 1; display: flex; gap: 5px; overflow: hidden; min-width: 0; }
.chip { font-family: var(--mono); font-size: 1rem; padding: 3px 9px; border-radius: 999px; white-space: nowrap; flex: none; }
.chip.l { background: var(--loss-soft); color: var(--loss); }
.chip.w { background: var(--win-soft); color: var(--win); font-weight: 600; }

.rec-wrap > .loss-btn { flex: 1.15 1 0; }
.loss-btn {
    width: 100%; min-height: 56px; font-size: clamp(1.5rem, 5.5dvh, 2.4rem); font-weight: 700; letter-spacing: .08em; border-radius: 14px;
    background: var(--loss); border-color: var(--loss); color: #fff; touch-action: manipulation; user-select: none;
}
.loss-btn:active { filter: brightness(.88); transform: scale(.99); }

.win-display {
    display: flex; align-items: center; gap: 8px; background: var(--surface); border: 2px solid var(--line); border-radius: 12px; padding: 2px 8px 2px 14px;
}
.win-display.has { border-color: var(--win); }
.win-display .amt { flex: 1; font-family: var(--mono); font-size: clamp(1.5rem, 5dvh, 2.2rem); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; overflow: hidden; white-space: nowrap; }
.win-display .lab { color: var(--muted); font-size: .95rem; text-transform: uppercase; letter-spacing: .06em; }

.rec-wrap > .pad { flex: 3.2 1 0; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(4, 1fr); gap: 7px; min-height: 0; }
.pad button {
    font-family: var(--mono); font-size: clamp(1.3rem, 4.5dvh, 2rem); font-weight: 600; min-height: 0; padding: 0; border-radius: 12px; background: var(--key); border-color: transparent;
    touch-action: manipulation; user-select: none;
}
.pad button:active { filter: brightness(.9); transform: scale(.98); }
.rec-wrap > .win-btn { flex: .85 1 0; }
.win-btn {
    width: 100%; min-height: 50px; font-size: clamp(1.3rem, 4.5dvh, 1.9rem); font-weight: 700; letter-spacing: .06em; border-radius: 14px;
    background: var(--win); border-color: var(--win); color: #fff; touch-action: manipulation; user-select: none;
}
.win-btn:active:not(:disabled) { filter: brightness(.88); }
.flash { animation: flash .35s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 6px var(--accent-soft); } to { box-shadow: 0 0 0 0 transparent; } }

/* messages replace the status line for a few seconds */
.streak.msg { color: var(--win); font-weight: 600; }
.streak.msg-err { color: var(--loss); font-weight: 600; }
/* very narrow phones: keep the four totals readable without cutting them off */
@media (max-width: 360px) {
    .rec-stats div { padding: 5px 3px; }
    .rec-stats .v { font-size: .98rem; }
}
.check { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.check input[type=checkbox] { width: 20px; height: 20px; }
.check input[type=number] { width: 4.6em; padding: 6px 8px; }

.dialog-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.dialog { background: var(--surface); border-radius: 12px; padding: 20px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { font-size: 1.2rem; }
[hidden] { display: none !important; }

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

/* recorder: labelled Download button in the top bar */
.rec-top .dl-btn { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; white-space: nowrap; }
.rec-top .btn, .rec-top button { white-space: nowrap; flex: none; }
@media (max-width: 360px) { .rec-top .dl-btn { font-size: 0; padding: 5px 10px; } .rec-top .dl-btn::before { content: "⬇"; font-size: 1rem; } }
