/* ============================================================================
 * app.css - phone first, thumb reachable, readable in a tournament hall
 * ==========================================================================*/

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --line: #d6dae2;
  --line-strong: #aeb6c4;
  --ink: #22262c;
  --ink-dim: #5d6675;
  --ink-faint: #8f98a8;
  --accent: #800000;   /* the maroon in the Asian Skat Masters logo */
  --accent-ink: #ffffff;
  --pos: #17693f;
  --pos-bg: #e4f3ea;
  --neg: #a32020;
  --neg-bg: #fbe8e8;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --radius: 12px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(16, 22, 33, .08), 0 4px 14px rgba(16, 22, 33, .06);
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-2: #242932;
    --line: #333a45;
    --line-strong: #4a5361;
    --ink: #e8ebf0;
    --ink-dim: #a6afbd;
    --ink-faint: #737d8c;
    --accent: #4a9fd4;
    --accent-ink: #0d1116;
    --pos: #5dd39e;
    --pos-bg: #17301f;
    --neg: #ff8a8a;
    --neg-bg: #33191a;
    --warn: #e5b95c;
    --warn-bg: #322815;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

body { padding-bottom: env(safe-area-inset-bottom); }

/* --- app shell ---------------------------------------------------------- */

#app { max-width: 900px; margin: 0 auto; padding: 0 12px calc(env(safe-area-inset-bottom) + 32px); }

header.bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  margin: 0 -12px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
header.bar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 650; letter-spacing: -.01em; }
header.bar .sub { font-size: 12px; color: var(--ink-dim); font-weight: 400; display: block; }

/* The tab bar sits under the header rather than at the foot of the screen.
   It scrolls away with the page on a phone, which keeps the whole viewport for
   a protocol table; the header above it stays. */
nav.tabs {
  position: sticky; top: 0; z-index: 25;
  display: flex; justify-content: space-around;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  margin: 0 -12px 12px;
  padding: 4px 4px 4px;
}
nav.tabs button {
  flex: 1; border: 0; background: none; color: var(--ink-dim);
  font-size: 11px; padding: 6px 2px; min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
  border-radius: 10px;
}
nav.tabs button .ic { font-size: 19px; line-height: 1; }
nav.tabs button[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* --- generic ------------------------------------------------------------ */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin: 0 0 12px;
}
.card > h2 { font-size: 14px; margin: 0 0 10px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-dim); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grow { flex: 1; }
.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }
.small { font-size: 13px; }
.tiny { font-size: 11px; }
.num { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.center { text-align: center; }
.stack > * + * { margin-top: 8px; }
.hidden { display: none !important; }

button, .btn {
  font: inherit; font-weight: 550;
  min-height: var(--tap); padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:active { transform: scale(.985); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.ghost { border-color: transparent; background: transparent; color: var(--accent); }
button.danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, transparent); }
button.sm { min-height: 36px; padding: 0 10px; font-size: 13px; }
button[disabled] { opacity: .45; pointer-events: none; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 10px;
  min-height: var(--tap); padding: 0 12px; width: 100%;
}
textarea { padding: 10px 12px; min-height: 84px; line-height: 1.4; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--ink-dim); margin-bottom: 4px; letter-spacing: .02em; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-dim);
}
.pill.ok { background: var(--pos-bg); color: var(--pos); }
.pill.bad { background: var(--neg-bg); color: var(--neg); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

/* --- choice grids ------------------------------------------------------- */

.choices { display: grid; gap: 6px; }
.choices.c2 { grid-template-columns: repeat(2, 1fr); }
.choices.c3 { grid-template-columns: repeat(3, 1fr); }
.choices.c4 { grid-template-columns: repeat(4, 1fr); }
.choices.c6 { grid-template-columns: repeat(6, 1fr); }
.choices button {
  min-height: 52px; padding: 0 6px; font-size: 14px; line-height: 1.15;
  flex-direction: column; gap: 1px;
}
.choices button .sub { font-size: 10px; color: var(--ink-faint); font-weight: 400; }
.choices button[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
}
.choices button[aria-pressed="true"] .sub { color: color-mix(in srgb, var(--accent-ink) 75%, transparent); }
.choices button.suit-red[aria-pressed="false"] { color: var(--neg); }

.toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.toggles button { min-height: 46px; font-size: 12.5px; padding: 0 4px; }
.toggles button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.toggles button[disabled] { opacity: .3; }

.stepper { display: flex; align-items: center; gap: 0; }
.stepper button { min-width: 52px; border-radius: 10px 0 0 10px; font-size: 22px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper .val {
  flex: 1; text-align: center; min-height: var(--tap); display: flex;
  align-items: center; justify-content: center;
  border: 1px solid var(--line-strong); border-left: 0; border-right: 0;
  font-family: var(--mono); font-size: 20px; font-weight: 600; background: var(--surface);
}

.winloss { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.winloss button { min-height: 58px; font-size: 16px; font-weight: 650; }
.winloss button[aria-pressed="true"][data-v="won"] { background: var(--pos); color: #fff; border-color: transparent; }
.winloss button[aria-pressed="true"][data-v="lost"] { background: var(--neg); color: #fff; border-color: transparent; }

.valuebox {
  display: flex; align-items: baseline; justify-content: center; gap: 10px;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface-2); margin-bottom: 12px;
}
.valuebox .big { font-family: var(--mono); font-size: 38px; font-weight: 700; letter-spacing: -.02em; }
.valuebox .formula { font-size: 12px; color: var(--ink-dim); }

/* --- tables ------------------------------------------------------------- */

.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-dim); font-weight: 600; }
th:first-child, td:first-child { text-align: left; }
th.l, td.l { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line-strong); }
tr.sub td { color: var(--ink-dim); font-size: 12px; }
tr.flag td { background: var(--neg-bg); }
tr.me td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* --- protocol grid ------------------------------------------------------ */

.protocol td, .protocol th { padding: 5px 6px; font-size: 12.5px; }
.protocol tbody tr { cursor: pointer; }
.protocol tbody tr:active { background: var(--surface-2); }
.protocol .g { color: var(--ink-faint); }

/* --- lists -------------------------------------------------------------- */

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; min-height: var(--tap);
  cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit;
  box-shadow: var(--shadow);
}
.item .title { font-weight: 600; }
.item .meta { font-size: 12px; color: var(--ink-dim); }
.item .chev { color: var(--ink-faint); margin-left: auto; }

/* --- issues ------------------------------------------------------------- */

.issue {
  border-left: 3px solid var(--neg); background: var(--neg-bg);
  padding: 9px 12px; border-radius: 0 8px 8px 0; font-size: 13px; margin-bottom: 6px;
}
.issue.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.issue .code { font-family: var(--mono); font-size: 10px; opacity: .65; display: block; }

/* --- modal -------------------------------------------------------------- */

.sheetmodal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 14, 20, .5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheetmodal > .body {
  background: var(--bg); width: 100%; max-width: 900px;
  border-radius: 18px 18px 0 0; padding: 8px 14px calc(env(safe-area-inset-bottom) + 20px);
  max-height: 92vh; overflow-y: auto;
}
.sheetmodal .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line-strong); margin: 8px auto 12px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 78px); z-index: 70;
  background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 550;
  box-shadow: var(--shadow); max-width: 90vw;
}

.stage { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 14px; }
.stage .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex: none; }
.stage.active .dot { background: var(--accent); animation: pulse 1s infinite; }
.stage.done .dot { background: var(--pos); }
@keyframes pulse { 50% { opacity: .3; } }

.photo { width: 100%; border-radius: 10px; border: 1px solid var(--line); display: block; }

.empty { text-align: center; padding: 40px 20px; color: var(--ink-dim); }
.empty .ic { font-size: 40px; display: block; margin-bottom: 10px; opacity: .5; }

@media (min-width: 700px) {
  .toggles { grid-template-columns: repeat(6, 1fr); }
  #app { padding-bottom: 40px; }
}

@media print {
  nav.tabs, header.bar, button { display: none !important; }
  .card { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

/* --- branding ----------------------------------------------------------- */

#brand {
  height: 26px; width: auto; display: block;
  /* The logo is a fixed-size PNG from the site; this keeps it crisp on a
     phone without shipping a second asset. */
  image-rendering: -webkit-optimize-contrast;
}
header.bar h1 { font-size: 15px; }
/* Wide enough for both: the wordmark and the title would fight on a phone. */
@media (max-width: 560px) {
  header.bar h1 { display: none; }
}
@media (min-width: 561px) {
  #brand { height: 22px; }
}

/* --- key/value table, for things that are shown but not editable -------- */

table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 3px 0; vertical-align: top; }
table.kv td:first-child { width: 45%; padding-right: 10px; }

/* --- highlights --------------------------------------------------------- */

td.bestcell {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 6px;
}
.banner {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border-left: 3px solid var(--accent);
  padding: 8px 10px; border-radius: 8px;
}
button.linky {
  border: 0; background: none; padding: 0; margin: 0; font: inherit; color: inherit;
  text-align: left; cursor: pointer; text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 2px; min-height: 0;
}
button.linky:hover { color: var(--accent); }

/* --- profiles ----------------------------------------------------------- */

.avatar { border-radius: 50%; object-fit: cover; flex: none; }
.avatar.ph {
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2));
  color: var(--accent); font-weight: 650; letter-spacing: .02em;
}
.big { font-size: 22px; font-weight: 650; line-height: 1.1; }

/* --- flags and countries ------------------------------------------------ */

.flag {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-style: normal;
}
.big-flag { font-size: 22px; line-height: 1; flex: none; }
.ctry { display: inline-flex; align-items: baseline; gap: 5px; }

/* A tournament row reads left to right and does not centre anything: flag,
   where, when, who won. */
.item.tourney { display: flex; align-items: center; gap: 10px; text-align: left; }
