/* ===========================================================
   Kniffel Scoreboard — Design tokens
   Subject: a felt game table at night / a scorepad by day.
   Signature: cells read like little die faces — filled ones
   show a bold mono number, struck ones show a soft cross.
=========================================================== */

:root{
  --bg: #FAF7F0;
  --surface: #FFFFFF;
  --surface-2: #F1ECDF;
  --border: #E3DDCB;
  --ink: #1F2421;
  --ink-muted: #6B7A70;
  --accent: #2F6B4F;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3EEE6;
  --red: #C1443D;
  --red-soft: #F6E3E1;
  --gold: #B4862E;
  --gold-soft: #F3E8CE;
  --shadow: 0 10px 30px -12px rgba(31, 36, 33, 0.25);
  --shadow-sm: 0 2px 8px -2px rgba(31, 36, 33, 0.18);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;

  --font-display: -apple-system, "Segoe UI Rounded", "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "SFMono-Regular", "Roboto Mono", Menlo, Consolas, "Courier New", monospace;

  color-scheme: light;
}

[data-theme="dark"]{
  --bg: #121C17;
  --surface: #1A251F;
  --surface-2: #202D26;
  --border: #2B3A32;
  --ink: #F1EEE2;
  --ink-muted: #93A599;
  --accent: #58A87C;
  --accent-ink: #0E1613;
  --accent-soft: #24382E;
  --red: #E3695F;
  --red-soft: #3A2523;
  --gold: #E1B45F;
  --gold-soft: #3A311E;
  --shadow: 0 10px 34px -10px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 2px 10px -2px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

*{ box-sizing: border-box; }
html, body{ height: 100%; }
body{
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  transition: background 0.25s ease, color 0.25s ease;
}
button{ font-family: inherit; }
h1,h2,h3{ font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
p{ margin: 0; }
::selection{ background: var(--accent-soft); }

.app-shell{
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* ---------- Top bar ---------- */
.topbar{
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.icon-btn{
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none; background: transparent; color: var(--ink);
  border-radius: 12px;
  cursor: pointer;
}
.icon-btn:active{ background: var(--surface-2); }
.brand{ display: flex; align-items: center; gap: 8px; }
.brand-die{ color: var(--accent); display: grid; place-items: center; }
.brand-die .pip{ fill: var(--accent-ink); }
.brand-name{ font-family: var(--font-display); font-weight: 800; font-size: 19px; letter-spacing: -0.01em; }

/* ---------- Drawer ---------- */
.drawer-overlay{
  position: fixed; inset: 0; background: rgba(10,14,12,0.45);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease; z-index: 40;
}
.drawer-overlay.open{ opacity: 1; pointer-events: auto; }
.drawer{
  position: fixed; top: 0; bottom: 0; left: 0;
  width: min(84vw, 320px);
  background: var(--surface);
  z-index: 50;
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(.32,.72,0,1);
  padding: max(16px, env(safe-area-inset-top)) 14px 16px;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.drawer.open{ transform: translateX(0); }
.drawer-head{ display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; padding: 0 4px; }
.drawer-item{
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  border: none; background: transparent; color: var(--ink);
  font-size: 15px; font-weight: 600;
  padding: 13px 10px; border-radius: var(--radius-sm);
  cursor: pointer;
}
.drawer-item svg{ color: var(--accent); flex-shrink: 0; }
.drawer-item:active{ background: var(--surface-2); }
.drawer-item-danger{ color: var(--red); }
.drawer-item-danger svg{ color: var(--red); }
.drawer-divider{ height: 1px; background: var(--border); margin: 8px 4px; }
.drawer-footnote{ margin-top: auto; padding: 10px; font-size: 12px; color: var(--ink-muted); line-height: 1.5; }

/* ---------- Main / screens ---------- */
.main{ flex: 1; display: flex; flex-direction: column; min-height: 0; }
.screen{ flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---------- Setup screen ---------- */
#screen-setup{ justify-content: center; padding: 20px 18px 40px; }
.setup-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 22px 22px;
  box-shadow: var(--shadow-sm);
}
.setup-title{ font-size: 26px; font-weight: 800; }
.setup-sub{ color: var(--ink-muted); margin-top: 6px; font-size: 14.5px; }

.player-inputs{ display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.player-row{
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 8px 6px 6px;
}
.player-die{
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.player-row input{
  flex: 1; border: none; background: transparent; color: var(--ink);
  font-size: 16px; font-weight: 600; padding: 8px 4px; min-width: 0;
  font-family: var(--font-body);
}
.player-row input:focus{ outline: none; }
.player-remove{
  width: 30px; height: 30px; border: none; background: transparent;
  color: var(--ink-muted); border-radius: 8px; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center;
}
.player-remove:active{ background: var(--red-soft); color: var(--red); }

.btn{
  border: none; cursor: pointer; font-weight: 700; font-family: var(--font-body);
  border-radius: var(--radius-md); font-size: 15px;
}
.btn-ghost{
  background: transparent; color: var(--accent);
  border: 1.5px dashed var(--border);
  padding: 11px 14px; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-ghost:active{ background: var(--accent-soft); }
.btn-add-player{ margin-top: 12px; }
.btn-primary{
  background: var(--accent); color: var(--accent-ink);
  padding: 15px; width: 100%; margin-top: 18px; font-size: 16px;
  box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}
.btn-primary:active{ filter: brightness(0.94); }
.btn-text{ background: transparent; color: var(--ink-muted); padding: 10px; text-decoration: underline; text-underline-offset: 3px; }
.setup-secondary{ text-align: center; margin-top: 8px; }
.btn-danger{ background: var(--red); color: #fff; padding: 12px 16px; }

/* ---------- Totals strip ---------- */
.totals-strip{
  display: flex; gap: 8px; overflow-x: auto;
  padding: 12px 14px; scrollbar-width: none;
}
.totals-strip::-webkit-scrollbar{ display: none; }
.total-chip{
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  min-width: 92px;
  box-shadow: var(--shadow-sm);
}
.total-chip .name{
  font-size: 12px; font-weight: 700; color: var(--ink-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px;
}
.total-chip .val{
  font-family: var(--font-mono); font-size: 20px; font-weight: 800; color: var(--accent);
}
.total-chip.leader{ border-color: var(--gold); background: var(--gold-soft); }
.total-chip.leader .val{ color: var(--gold); }

/* ---------- Score table ---------- */
.table-wrap{ flex: 1; overflow: auto; padding: 0 14px 100px; -webkit-overflow-scrolling: touch; }
.score-table{ border-collapse: separate; border-spacing: 0 6px; width: 100%; }

.score-table thead th{
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 6px 4px 8px;
  font-size: 12px; text-align: center; color: var(--ink-muted);
}
.score-table thead th.cat-head{ text-align: left; }
.score-table thead .player-th{
  font-family: var(--font-display); font-weight: 800; color: var(--ink);
  font-size: 13px; min-width: 72px;
}

.cat-cell{
  position: sticky; left: 0; z-index: 3;
  background: var(--bg);
  padding: 0 10px 0 2px;
  font-size: 13.5px; font-weight: 600; color: var(--ink);
  white-space: nowrap;
  min-width: 128px;
}
.cat-cell .cat-sub{ display: block; font-size: 10.5px; font-weight: 500; color: var(--ink-muted); margin-top: 1px; }

.section-row td{ padding-top: 14px; }
.section-label{
  font-family: var(--font-display); font-weight: 800; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent);
  position: sticky; left: 0;
}

.score-cell{ text-align: center; padding: 3px; }
.die-btn{
  width: 52px; height: 44px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono); font-weight: 700; font-size: 15px;
  display: grid; place-items: center;
  cursor: pointer;
  margin: 0 auto;
  transition: transform 0.08s ease, background 0.15s ease;
}
.die-btn:active{ transform: scale(0.94); background: var(--surface-2); }
.die-btn.empty{ color: var(--ink-muted); font-weight: 400; font-size: 13px; border-style: dashed; }
.die-btn.filled{ background: var(--accent-soft); border-color: transparent; color: var(--accent); }
[data-theme="dark"] .die-btn.filled{ color: var(--ink); }
.die-btn.struck{ background: transparent; border-style: dashed; color: var(--ink-muted); position: relative; }
.die-btn.struck::after{
  content: ""; position: absolute; left: 8px; right: 8px; top: 50%;
  border-top: 2px solid var(--red); transform: rotate(-8deg);
}
.die-btn.kniffel-filled{ background: var(--gold-soft); color: var(--gold); border-color: transparent; }

.subtotal-row td{ padding-top: 8px; padding-bottom: 4px; }
.subtotal-row .cat-cell{ color: var(--ink-muted); font-weight: 700; font-size: 12.5px; }
.subtotal-val{
  font-family: var(--font-mono); font-weight: 700; font-size: 14px; color: var(--ink);
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 0; width: 52px; margin: 0 auto; display: block;
}
.subtotal-val.bonus-hit{ background: var(--gold-soft); color: var(--gold); }

.total-row td{ padding-top: 12px; }
.total-row .cat-cell{ font-family: var(--font-display); font-weight: 800; font-size: 15px; color: var(--ink); }
.total-val{
  font-family: var(--font-mono); font-weight: 800; font-size: 17px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius-sm); padding: 10px 0; width: 56px; margin: 0 auto; display: block;
}

.kbonus-cell{ display: flex; align-items: center; justify-content: center; gap: 4px; }
.stepper-btn{
  width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); display: grid; place-items: center; cursor: pointer;
}
.stepper-btn:disabled{ opacity: 0.35; }
.stepper-btn:active:not(:disabled){ background: var(--surface-2); }
.kbonus-val{ font-family: var(--font-mono); font-weight: 700; font-size: 13.5px; min-width: 34px; text-align: center; }

/* ---------- Floating actions ---------- */
.game-actions{
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 720px; margin: 0 auto;
  display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.fab-btn{
  pointer-events: auto;
  border: none; cursor: pointer; border-radius: 999px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 14.5px;
}
.fab-secondary{
  width: 48px; height: 48px; justify-content: center;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
}
.fab-primary{
  height: 48px; padding: 0 20px;
  background: var(--accent); color: var(--accent-ink);
}
.fab-btn:active{ transform: scale(0.96); }

/* ---------- History screen ---------- */
.screen-head{ display: flex; align-items: center; gap: 8px; padding: 10px 14px 4px; }
.screen-head h2{ font-size: 19px; font-weight: 800; }
.history-list{ padding: 12px 14px 40px; display: flex; flex-direction: column; gap: 10px; }
.history-card{
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px; box-shadow: var(--shadow-sm);
}
.history-card-top{ display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.history-date{ font-size: 12px; color: var(--ink-muted); }
.history-players{ font-size: 13.5px; margin-top: 6px; color: var(--ink); line-height: 1.6; }
.history-players b{ font-family: var(--font-mono); color: var(--accent); }
.history-actions{ display: flex; gap: 8px; margin-top: 10px; }
.history-actions button{
  flex: 1; padding: 9px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 700;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); cursor: pointer;
}
.history-actions button.danger{ color: var(--red); }
.empty-hint{ text-align: center; color: var(--ink-muted); padding: 40px 24px; font-size: 14px; }

/* ---------- Modals ---------- */
.modal-overlay{
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10,14,12,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.modal-overlay.open{ opacity: 1; pointer-events: auto; }
.modal{
  background: var(--surface);
  width: 100%; max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 18px 18px max(18px, env(safe-area-inset-bottom));
  transform: translateY(16px);
  transition: transform 0.22s cubic-bezier(.32,.72,0,1);
  box-shadow: var(--shadow);
}
.modal-overlay.open .modal{ transform: translateY(0); }
.confirm-modal{ border-radius: 20px; margin: 0 16px; }
.modal-head{ display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.modal-eyebrow{ font-size: 12px; color: var(--ink-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.modal-head h3{ font-size: 19px; margin-top: 2px; }

.quick-grid{ display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.quick-btn{
  padding: 14px 6px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: var(--surface-2); color: var(--ink); font-family: var(--font-mono); font-weight: 700; font-size: 15px;
  cursor: pointer;
}
.quick-btn:active{ background: var(--accent-soft); border-color: var(--accent); }
.quick-btn.chosen{ background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.manual-entry{ display: flex; gap: 8px; margin: 12px 0; }
.manual-entry input{
  flex: 1; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; font-size: 16px; font-family: var(--font-mono); background: var(--surface-2); color: var(--ink);
}
.manual-entry input:focus{ outline: 2px solid var(--accent); outline-offset: 1px; }
.manual-entry button{
  padding: 0 16px; border-radius: var(--radius-sm); border: none; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer;
}

.modal-actions{ display: flex; gap: 8px; margin-top: 14px; }
.modal-actions button{
  flex: 1; padding: 13px; border-radius: var(--radius-sm); font-weight: 700; font-size: 14px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink);
}
.modal-actions button.primary{ background: var(--accent); color: var(--accent-ink); border: none; }
.modal-actions button.danger-outline{ color: var(--red); border-color: var(--red-soft); }

.confirm-modal p{ color: var(--ink-muted); font-size: 14px; margin: 10px 0 16px; line-height: 1.5; }
.confirm-actions{ display: flex; gap: 8px; }
.confirm-actions button{ flex: 1; padding: 12px; border-radius: var(--radius-sm); }

/* ---------- Toast ---------- */
.toast{
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 12px);
  background: var(--ink); color: var(--bg);
  padding: 11px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  z-index: 80; opacity: 0; pointer-events: none; transition: all 0.25s ease;
  box-shadow: var(--shadow);
  max-width: 88vw; text-align: center;
}
.toast.show{ opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive: small phones ---------- */
@media (max-width: 360px){
  .die-btn{ width: 46px; }
  .cat-cell{ min-width: 108px; font-size: 12.5px; }
}

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