/* Loba Scorer — one stylesheet, no frameworks, no web fonts.
   Designed for a phone held in one hand at a card table: big targets,
   high contrast, dark by default so it does not blind the table.

   The look leans on the table itself: green baize with a woven texture, panels
   that sit on it like dealt cards with a pale edge and a real shadow, a gold
   trim, and a serif face for names and numbers the way an index is printed on
   a card. */

:root {
  --felt-900: #08251a;
  --felt-800: #0e3324;
  --felt-700: #14412e;
  --felt-600: #1a5038;
  --line: #2f6b4c;
  --line-soft: rgba(233, 226, 208, 0.14);
  --ink: #f4f1e6;
  --ink-dim: #b3cbbc;
  --ink-faint: #7fa895;
  --gold: #e3b866;
  --gold-dim: #a8802f;
  --good: #4dd193;
  --warn: #f0a03c;
  --bad: #ef6b6b;
  --card: #16412d;
  --card-hi: #1d5238;
  /* Face-up playing card: warm off-white, like real card stock. */
  --stock: #f5f1e4;
  --stock-edge: #ded6c0;
  --stock-ink: #1b1408;
  --pip-red: #b3252b;
  --radius: 14px;
  --radius-sm: 9px;
  --radius-card: 12px;
  --tap: 48px;
  --pad: 16px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --shadow-card: 0 2px 0 rgba(0, 0, 0, 0.22), 0 8px 18px rgba(0, 0, 0, 0.3);
}

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

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

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  /* Baize: a fine woven cross-hatch over a soft centre-lit green. */
  background-color: var(--felt-900);
  background-image:
    radial-gradient(120% 80% at 50% 0%, rgba(46, 122, 84, 0.5), transparent 70%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.022) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.045) 0 2px, transparent 2px 4px);
  background-attachment: fixed;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px;
  background: linear-gradient(to bottom, #10382700, #0a2a1e 55%);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--gold-dim);
  box-shadow: 0 1px 0 rgba(227, 184, 102, 0.16), 0 6px 16px rgba(0, 0, 0, 0.28);
}

.topbar__title {
  flex: 1;
  margin: 0;
  font-family: var(--serif);
  font-size: 1.16rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

.topbar__lang {
  flex: 0 0 auto;
  min-width: 38px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  background: rgba(227, 184, 102, 0.1);
  color: var(--gold);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.topbar__lang:active { background: var(--gold); color: #1a1206; }

.topbar__back, .topbar__menu {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.topbar__back { font-size: 2rem; }
.topbar__back:active, .topbar__menu:active { background: var(--felt-700); }
.topbar__back[hidden] { visibility: hidden; display: block; }

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--pad) var(--pad) 180px;
}

/* ------------------------------------------------------------- primitives */

h2 { font-size: 1.15rem; margin: 0 0 10px; font-weight: 650; }
h3 { font-size: 0.95rem; margin: 0 0 8px; font-weight: 620; color: var(--ink-dim); }
p { margin: 0 0 12px; }
a { color: var(--gold); }

.muted { color: var(--ink-dim); }
.faint { color: var(--ink-faint); font-size: 0.85rem; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }

.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.panel {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(0, 0, 0, 0.05)),
    var(--card);
  border: 1px solid var(--line);
  border-top-color: rgba(244, 241, 230, 0.18);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-card);
}

/* Hero panels carry a faint suit watermark, clipped by the rounded corner. */
.panel--hero { overflow: hidden; }
.panel--hero::after {
  content: "\2660";
  position: absolute;
  right: 10px;
  bottom: 4px;
  font-size: 3.4rem;
  line-height: 1;
  color: rgba(244, 241, 230, 0.05);
  pointer-events: none;
}

/* Little face-up cards used as decoration on the home screen. */
.hero__cards { display: flex; justify-content: center; gap: 8px; margin-bottom: 4px; }
.minicard {
  position: relative;
  width: 40px;
  height: 56px;
  border-radius: 6px;
  background: var(--stock);
  border: 1px solid var(--stock-edge);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
  color: var(--stock-ink);
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  padding: 5px 0 0 5px;
  text-align: left;
}
.minicard i { display: block; font-style: normal; font-size: 0.9rem; }
.minicard--red { color: var(--pip-red); }
.minicard:nth-child(1) { transform: rotate(-8deg) translateY(2px); }
.minicard:nth-child(3) { transform: rotate(8deg) translateY(2px); }

.trophy { font-size: 2.6rem; }
.panel + .panel { margin-top: 12px; }
.panel__head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.panel__head h2, .panel__head h3 { margin: 0; }

.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--card-hi);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn--primary {
  background: linear-gradient(180deg, #f0cb85, var(--gold) 55%, #cf9f44);
  border-color: #f0cb85;
  color: #22180a;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.28);
  box-shadow: 0 2px 0 var(--gold-dim), 0 6px 14px rgba(0, 0, 0, 0.3);
}
.btn--ghost { background: transparent; }
.btn--danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn--block { display: block; width: 100%; }
.btn--big { min-height: 56px; font-size: 1.05rem; }
.btn--sm { min-height: 38px; padding: 0 12px; font-size: 0.88rem; }

.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

input[type="text"], input[type="number"], select {
  min-height: var(--tap);
  width: 100%;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--felt-900);
  color: var(--ink);
  font: inherit;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
select { appearance: none; padding-right: 30px; }

label.field { display: block; }
label.field > span { display: block; margin-bottom: 5px; font-size: 0.85rem; color: var(--ink-dim); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.switch input { width: 22px; height: 22px; accent-color: var(--gold); }

/* --------------------------------------------------------------- segmented */

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  flex: 1;
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--gold); color: #1a1206; }

/* Four value tables will not fit across a phone, so wrap them 2x2 and go to a
   single row once there is room. */
.seg--presets { display: grid; grid-template-columns: repeat(2, 1fr); }
.seg--presets button { font-size: 0.92rem; padding: 0 6px; border-bottom: 1px solid var(--line); }
.seg--presets button:nth-child(2n) { border-right: 0; }
.seg--presets button:nth-last-child(-n+2) { border-bottom: 0; }

@media (min-width: 560px) {
  .seg--presets { grid-template-columns: repeat(4, 1fr); }
  .seg--presets button { border-bottom: 0; border-right: 1px solid var(--line); }
  .seg--presets button:last-child { border-right: 0; }
}

/* -------------------------------------------------------------- role cards */

.roles { display: grid; gap: 10px; }
.role {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent), var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold-dim);
  box-shadow: var(--shadow-card);
}
.role--lead { background: linear-gradient(135deg, var(--felt-600), var(--card)); border-color: var(--gold-dim); }
.role__icon { font-size: 1.5rem; width: 32px; text-align: center; }
.role__what { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-faint); }
.role__who { font-family: var(--serif); font-size: 1.22rem; font-weight: 700; letter-spacing: 0.01em; }
.role__icon { color: var(--gold); }

.biground {
  text-align: center;
  padding: 6px 0 14px;
}
.biground__n {
  font-family: var(--serif);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.biground__label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-faint); }

/* ---------------------------------------------------------------- standings */

table.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.tbl th, table.tbl td { padding: 9px 6px; text-align: right; border-bottom: 1px solid var(--line); }
table.tbl th:first-child, table.tbl td:first-child { text-align: left; }
table.tbl th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-faint); font-weight: 600; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl td.total { font-family: var(--serif); font-weight: 700; font-size: 1.18rem; }
table.tbl td:first-child { font-size: 1rem; }
tr.is-out td { color: var(--ink-faint); }
tr.is-out td:first-child { text-decoration: line-through; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.03em;
  vertical-align: middle;
}
.pill--out { background: rgba(239, 107, 107, 0.18); color: var(--bad); }
.pill--reeng { background: rgba(229, 180, 95, 0.18); color: var(--gold); }
.pill--danger { background: rgba(240, 160, 60, 0.18); color: var(--warn); }
.pill--good { background: rgba(70, 209, 138, 0.18); color: var(--good); }

/* --------------------------------------------------------------- entry rows */

.entry {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.entry + .entry { margin-top: 10px; }
.entry.is-set { border-color: var(--good); }
.entry__top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.entry__name { flex: 1; font-family: var(--serif); font-weight: 700; font-size: 1.12rem; }
.entry__val {
  min-width: 62px;
  text-align: right;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.entry__val--unset { color: var(--ink-faint); font-size: 1.1rem; font-weight: 500; }
.entry__tools { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.entry__tools .btn { min-height: 42px; padding: 0 10px; font-size: 0.9rem; }
.entry__tools .btn[aria-pressed="true"] { background: var(--good); border-color: var(--good); color: #06251a; }
.entry__num { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; }
.entry__num input { flex: 1; }

/* --------------------------------------------------------------- card picker */

.rankgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.rankcard {
  position: relative;
  min-height: 62px;
  padding: 6px 4px 5px;
  border: 1px solid var(--stock-edge);
  border-radius: var(--radius-card);
  background: linear-gradient(180deg, #fffdf6, var(--stock) 60%, #ece5d2);
  color: var(--stock-ink);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18), 0 5px 10px rgba(0, 0, 0, 0.26);
}
.rankcard:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18), 0 2px 5px rgba(0, 0, 0, 0.26);
}
.rankcard__r {
  display: block;
  font-family: var(--serif);
  font-size: 1.32rem;
  font-weight: 700;
  line-height: 1.05;
}
.rankcard__v {
  display: block;
  margin-top: 1px;
  font-size: 0.68rem;
  font-weight: 600;
  color: #6d6350;
}
.rankcard[data-rank="JOKER"] { grid-column: span 2; }
.rankcard[data-rank="JOKER"] .rankcard__r { color: var(--pip-red); }
.rankcard[data-rank="A"] .rankcard__r,
.rankcard[data-rank="K"] .rankcard__r { color: var(--pip-red); }
.rankcard .badge {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 22px; height: 22px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--pip-red);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 22px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 40px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 12px;
  border-radius: 999px;
  background: var(--felt-600);
  border: 1px solid var(--line);
  font-weight: 650;
}
.chip button {
  width: 24px; height: 24px;
  border: 0; border-radius: 50%;
  background: rgba(0,0,0,0.28);
  color: var(--ink);
  font-size: 1rem; line-height: 1;
  cursor: pointer;
}

.runtotal {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--felt-700);
  border: 1px solid var(--gold-dim);
}
.runtotal__n {
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

/* ---------------------------------------------------------------- photo flow */

.photowrap { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; }
.photowrap canvas { display: block; width: 100%; height: auto; }

.detected { display: grid; gap: 8px; }
.detected__row {
  display: grid;
  grid-template-columns: 30px 1fr 96px;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--felt-700);
  border: 1px solid var(--line);
}
.detected__row.is-unsure { border-color: var(--warn); }
.detected__row.is-dropped { opacity: 0.45; }
.detected__idx { text-align: center; font-weight: 700; color: var(--ink-faint); }
.detected__meta { font-size: 0.78rem; color: var(--ink-faint); }
.detected__row select { min-height: 40px; }

.conf { height: 4px; border-radius: 2px; background: rgba(255,255,255,0.12); overflow: hidden; margin-top: 4px; }
.conf > i { display: block; height: 100%; background: var(--good); }
.conf.is-low > i { background: var(--warn); }

.note {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--warn);
  background: rgba(240, 160, 60, 0.1);
  font-size: 0.88rem;
}
.note--info { border-left-color: var(--gold); background: rgba(229, 180, 95, 0.09); }
.note--bad { border-left-color: var(--bad); background: rgba(239, 107, 107, 0.1); }
.note + .note { margin-top: 8px; }
.note ul { margin: 6px 0 0; padding-left: 18px; }

/* --------------------------------------------------------------- exact cut */

.panel--cut { border-left: 3px solid var(--gold-dim); }
.panel--cut .btn[aria-pressed="true"] {
  background: linear-gradient(180deg, #f0cb85, var(--gold) 55%, #cf9f44);
  border-color: #f0cb85;
  color: #22180a;
  font-weight: 700;
}
.cut__icon { color: var(--gold); }
.panel--cut .btn[aria-pressed="true"] .cut__icon { color: #22180a; }
.pill--cut { background: rgba(227, 184, 102, 0.2); color: var(--gold); }

.pre {
  white-space: pre-wrap;
  font-size: 0.8rem;
  background: var(--felt-900);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: ui-monospace, monospace;
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}
/* Setting `display` above beats the UA rule for [hidden], so restate it —
   without this the sheet and its backdrop are permanently on screen. */
.modal[hidden] { display: none; }
.modal__sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--felt-800);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.modal__head {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 14px 8px;
  border-bottom: 1px solid var(--line);
}
.modal__title { flex: 1; margin: 0; font-family: var(--serif); font-size: 1.1rem; font-weight: 700; }
.modal__close {
  width: 36px; height: 36px;
  border: 0; border-radius: 50%;
  background: var(--felt-700); color: var(--ink);
  font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.modal__body { padding: 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal__body > * + * { margin-top: 12px; }
.modal__foot { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.modal__foot .btn { flex: 1; }
.modal__foot:empty { display: none; }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  max-width: 90vw;
  padding: 12px 18px;
  border-radius: 999px;
  background: #08150f;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* --------------------------------------------------------------- sticky bar */

.stickybar {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 25;
  padding: 12px var(--pad) calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--felt-900) 60%, rgba(12, 36, 25, 0.85));
  border-top: 1px solid var(--line);
}
.stickybar__inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.stickybar__inner .btn { flex: 1; }

/* ----------------------------------------------------------------- misc bits */

.list { display: grid; gap: 8px; }
.list__item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--felt-700);
  border: 1px solid var(--line);
}
.list__item .grow { font-weight: 600; }
.seatnum {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-family: var(--serif);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 24px;
  text-align: center;
}

.valuegrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.valuegrid label { display: block; }
.valuegrid span { display: block; font-size: 0.75rem; color: var(--ink-faint); margin-bottom: 3px; }
.valuegrid input { min-height: 40px; padding: 0 8px; text-align: center; }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--felt-700);
  border: 1px solid var(--line);
  font-size: 0.85em;
  font-family: ui-monospace, monospace;
}

.rulelist { margin: 0; padding-left: 20px; }
.rulelist li { margin-bottom: 8px; }

.empty { text-align: center; padding: 32px 12px; color: var(--ink-faint); }
.empty__icon { font-size: 3rem; margin-bottom: 8px; color: var(--ink-faint); }

@media (min-width: 520px) {
  .entry__tools { grid-template-columns: repeat(4, 1fr); }
  .entry__num { grid-column: 1 / -1; }
}

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