/* Mahjong Points Tracker — felt-table aesthetic */
:root {
  --felt-1: oklch(0.22 0.04 152);
  --felt-2: oklch(0.27 0.05 152);
  --felt-3: oklch(0.32 0.05 152);
  --felt-line: oklch(0.40 0.04 150);
  --cream: oklch(0.96 0.02 90);
  --cream-dim: oklch(0.86 0.02 90);
  --muted: oklch(0.70 0.02 90);
  --gold: oklch(0.80 0.13 82);
  --gold-deep: oklch(0.65 0.15 70);
  --red: oklch(0.62 0.18 25);
  --red-dim: oklch(0.55 0.10 25);
  --green-pos: oklch(0.78 0.16 145);
  --shadow: 0 8px 30px -8px rgba(0,0,0,0.4), 0 2px 6px -2px rgba(0,0,0,0.3);
  --shadow-soft: 0 2px 12px -4px rgba(0,0,0,0.25);
  --radius: 14px;
  --radius-sm: 8px;
  --serif: "Noto Serif SC", "Noto Serif", Georgia, serif;
  --sans: "Inter", "Noto Sans SC", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--cream);
  background:
    radial-gradient(ellipse at top, var(--felt-3), var(--felt-1) 70%),
    var(--felt-1);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* Layout */
.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--felt-line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 6px;
  background: linear-gradient(180deg, oklch(0.95 0.02 90), oklch(0.86 0.03 85));
  color: var(--felt-1);
  display: grid; place-items: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 18px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.3);
}
.brand-name {
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: 0.02em;
}
.brand-tag {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.lang-toggle {
  display: inline-flex;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--felt-line);
  border-radius: 999px;
  padding: 3px;
  font-size: 12px;
}
.lang-toggle button {
  background: transparent;
  color: var(--cream-dim);
  border: 0;
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 500;
}
.lang-toggle button.active {
  background: var(--gold);
  color: var(--felt-1);
}

.content { flex: 1; padding: 20px; padding-bottom: 100px; }

/* Setup */
.setup-hero {
  text-align: center;
  margin: 12px 0 24px;
}
.setup-hero h1 {
  font-family: var(--serif);
  font-size: 32px;
  margin: 0 0 6px;
  letter-spacing: 0.02em;
}
.setup-hero p {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}
.section {
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin-bottom: 12px;
  font-weight: 600;
}
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mode-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius-sm);
  padding: 16px;
  text-align: left;
  color: var(--cream);
  transition: all 0.15s ease;
}
.mode-card:hover { border-color: var(--gold-deep); }
.mode-card.active {
  border-color: var(--gold);
  background: rgba(255,200,100,0.10);
  box-shadow: 0 0 0 1px var(--gold) inset;
}
.mode-card h3 {
  margin: 0 0 4px;
  font-family: var(--serif);
  font-size: 18px;
}
.mode-card p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.field:last-child { margin-bottom: 0; }
.field label {
  font-size: 12px;
  color: var(--cream-dim);
  font-weight: 500;
}
.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.field-row:last-child { border-bottom: 0; }
.field-row .label {
  font-size: 13px;
  color: var(--cream);
}
.field-row .hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
input[type="text"], input[type="number"] {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--cream);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
  font-family: var(--mono);
  width: 100%;
}
input[type="text"] { font-family: var(--sans); }
input:focus { border-color: var(--gold); }
.num-input {
  width: 90px;
  text-align: center;
}
.player-input-row {
  display: grid;
  grid-template-columns: 56px 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.player-input-row:last-child { margin-bottom: 0; }
.seat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, oklch(0.95 0.02 90), oklch(0.86 0.03 85));
  color: var(--felt-1);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 16px;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12);
}

.toggle {
  position: relative;
  width: 44px; height: 26px;
  background: rgba(0,0,0,0.4);
  border-radius: 999px;
  border: 1px solid var(--felt-line);
  transition: background 0.15s;
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--cream-dim);
  transition: all 0.15s;
}
.toggle.on { background: var(--gold); border-color: var(--gold); }
.toggle.on::after { left: 20px; background: var(--felt-1); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
  background: transparent;
  color: var(--cream);
}
.btn-primary {
  background: var(--gold);
  color: var(--felt-1);
}
.btn-primary:hover { background: oklch(0.85 0.13 82); }
.btn-secondary {
  background: rgba(255,255,255,0.08);
  border-color: var(--felt-line);
  color: var(--cream);
}
.btn-secondary:hover { background: rgba(255,255,255,0.12); }
.btn-ghost {
  background: transparent;
  color: var(--cream-dim);
}
.btn-ghost:hover { color: var(--cream); }
.btn-danger { background: var(--red-dim); color: var(--cream); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 24px; font-size: 15px; }

/* Game screen */
.scoreboard {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}
.scoreboard.n3 { grid-template-columns: repeat(3, 1fr); }
.scoreboard.n4 { grid-template-columns: repeat(2, 1fr); }
.player-tile {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
  overflow: hidden;
}
.player-tile.dealer {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold) inset;
}
.player-tile .seat {
  font-family: var(--serif);
  font-size: 11px;
  color: var(--gold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.player-tile .pname {
  font-size: 14px;
  font-weight: 600;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-tile .ptotal {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  margin-top: 8px;
  letter-spacing: -0.02em;
}
.player-tile .ptotal.pos { color: var(--green-pos); }
.player-tile .ptotal.neg { color: var(--red); }
.player-tile .pdealer-pin {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--gold);
  color: var(--felt-1);
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.08em;
}

.round-counter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
}
.round-counter .num {
  font-family: var(--serif);
  font-size: 24px;
  color: var(--gold);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .icon {
  font-family: var(--serif);
  font-size: 48px;
  color: var(--gold-deep);
  opacity: 0.4;
  margin-bottom: 12px;
}

/* Bottom nav */
.bottomnav {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, var(--felt-1) 30%);
  padding: 16px 20px 20px;
  display: flex;
  gap: 10px;
}
.fab {
  flex: 1;
  background: var(--gold);
  color: var(--felt-1);
  border: 0;
  border-radius: var(--radius);
  padding: 16px;
  font-weight: 700;
  font-size: 15px;
  font-family: var(--serif);
  letter-spacing: 0.04em;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.fab:hover { background: oklch(0.85 0.13 82); }
.nav-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--felt-line);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.nav-icon:hover { background: rgba(255,255,255,0.1); }

/* Sheet (modal from bottom) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.sheet {
  background: var(--felt-2);
  border-top: 1px solid var(--felt-line);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 20px; max-height: 88vh; }
}
.sheet-header {
  position: sticky;
  top: 0;
  background: var(--felt-2);
  border-bottom: 1px solid var(--felt-line);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1;
}
.sheet-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
}
.sheet-body { padding: 20px; }
.sheet-footer {
  position: sticky;
  bottom: 0;
  background: var(--felt-2);
  border-top: 1px solid var(--felt-line);
  padding: 14px 20px;
  display: flex;
  gap: 10px;
}
.close-btn {
  background: transparent;
  border: 0;
  color: var(--cream-dim);
  font-size: 22px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 999px;
}
.close-btn:hover { background: rgba(255,255,255,0.08); color: var(--cream); }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }

/* Outcome chooser */
.outcome-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.outcome-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--felt-line);
  color: var(--cream);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  font-family: var(--serif);
  letter-spacing: 0.04em;
}
.outcome-btn.active {
  border-color: var(--gold);
  background: rgba(255,200,100,0.1);
  color: var(--gold);
}

.player-pick {
  display: grid;
  gap: 8px;
}
.player-pick.n3 { grid-template-columns: repeat(3, 1fr); }
.player-pick.n4 { grid-template-columns: repeat(2, 1fr); }
.player-pick button {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--felt-line);
  color: var(--cream);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.player-pick button .seat-mini {
  font-family: var(--serif);
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 0.1em;
}
.player-pick button.active {
  border-color: var(--gold);
  background: rgba(255,200,100,0.12);
}
.player-pick button.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.fan-stepper {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}
.fan-pill {
  display: inline-flex;
  align-items: center;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--felt-line);
  border-radius: 999px;
  overflow: hidden;
}
.fan-pill button {
  background: transparent;
  color: var(--cream);
  border: 0;
  width: 38px; height: 38px;
  font-size: 18px;
  font-weight: 700;
}
.fan-pill button:hover { background: rgba(255,255,255,0.08); }
.fan-pill .val {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  min-width: 50px;
  text-align: center;
  color: var(--gold);
}
.fan-warn {
  font-size: 11px;
  color: var(--red);
}
.fan-warn.cap { color: var(--gold); }

/* Bonus grid */
.bonus-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.bonus-table th, .bonus-table td {
  padding: 8px 4px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.bonus-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 500;
}
.bonus-table td:first-child, .bonus-table th:first-child {
  text-align: left;
  font-weight: 600;
}
.bonus-stepper {
  display: inline-flex;
  align-items: center;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--felt-line);
  border-radius: 6px;
  overflow: hidden;
}
.bonus-stepper button {
  background: transparent;
  color: var(--cream-dim);
  border: 0;
  width: 24px; height: 28px;
  font-size: 13px;
  font-weight: 700;
}
.bonus-stepper button:hover { color: var(--cream); background: rgba(255,255,255,0.08); }
.bonus-stepper .v {
  font-family: var(--mono);
  font-size: 13px;
  min-width: 24px;
  text-align: center;
  color: var(--cream);
}

/* Review */
.view-toggle {
  display: inline-flex;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--felt-line);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 14px;
}
.view-toggle button {
  background: transparent;
  border: 0;
  color: var(--cream-dim);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.view-toggle button.active {
  background: var(--gold);
  color: var(--felt-1);
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  overflow: hidden;
}
.history-table th, .history-table td {
  padding: 10px 8px;
  text-align: right;
  font-family: var(--mono);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.history-table th {
  background: rgba(0,0,0,0.25);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  font-weight: 600;
  font-family: var(--sans);
  position: sticky; top: 0;
}
.history-table th:first-child, .history-table td:first-child {
  text-align: left;
  font-family: var(--sans);
}
.history-table tr.totals td {
  background: rgba(255,200,100,0.08);
  font-weight: 700;
  font-size: 15px;
  border-bottom: 0;
}
.history-table tr.totals td:first-child {
  font-family: var(--serif);
  color: var(--gold);
}
.delta-pos { color: var(--green-pos); }
.delta-neg { color: var(--red); }
.delta-zero { color: var(--muted); opacity: 0.5; }
.history-table tr:hover td { background: rgba(255,255,255,0.03); }
.history-table tr.totals:hover td { background: rgba(255,200,100,0.08); }
.history-table .row-actions {
  display: inline-flex; gap: 6px;
}
.icon-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--felt-line);
  color: var(--cream-dim);
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-family: var(--sans);
  font-weight: 500;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.10); color: var(--cream); border-color: rgba(255,255,255,0.18); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: var(--red-dim); color: white; border-color: var(--red); }
.icon-btn .ico { font-size: 11px; opacity: 0.8; }

.feeder-chip {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--felt-line);
  color: var(--cream-dim);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-family: var(--sans);
  transition: all 0.15s;
}
.feeder-chip:hover { background: rgba(255,255,255,0.08); color: var(--cream); }
.feeder-chip.active {
  background: var(--red-dim);
  border-color: var(--red);
  color: white;
}

/* Card view */
.round-card {
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.round-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.round-card-head .num {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--gold);
}
.round-card-head .summary {
  font-size: 12px;
  color: var(--cream-dim);
  text-align: right;
}
.round-card-deltas {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.delta-chip {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--felt-line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-family: var(--mono);
}
.delta-chip .name { font-family: var(--sans); margin-right: 6px; color: var(--cream-dim); }
.round-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 4px;
}
.round-card-note {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  margin-top: 4px;
}

/* Confirm modal */
.confirm {
  background: var(--felt-2);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
}
.confirm h3 { margin: 0 0 8px; font-family: var(--serif); }
.confirm p { color: var(--cream-dim); font-size: 14px; margin: 0 0 16px; }
.confirm-actions { display: flex; gap: 8px; justify-content: center; }

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gold);
  color: var(--felt-1);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: fadeIn 0.2s;
}

/* Export preview */
.export-preview {
  background: linear-gradient(180deg, var(--felt-3), var(--felt-1));
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  padding: 24px;
  font-family: var(--serif);
}
.export-preview h2 {
  text-align: center;
  margin: 0 0 4px;
  font-size: 22px;
}
.export-preview .ts {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 16px;
}

/* Tweaks position fix — leave room for bottom nav */
[class*="TweaksPanel"], #tweaks-root { z-index: 100; }
