/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt:       #1a2e1f;
  --felt-mid:   #1f3524;
  --felt-light: #263d2c;
  --felt-line:  #2e4a35;
  --amber:      #e8a838;
  --amber-dim:  #c48c20;
  --amber-glow: rgba(232,168,56,0.15);
  --amber-faint:rgba(232,168,56,0.06);
  --text:       #f0ebe2;
  --text-dim:   #9eaa9a;
  --text-faint: #4e6052;
  --green-win:  #5ec97a;
  --green-win-bg: rgba(94,201,122,0.10);
  --red:        #e05c5c;
  --red-bg:     rgba(224,92,92,0.10);
  --card-bg:    #213226;
  --card-border:#2e4a35;
  --input-bg:   #182a1d;
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.45);
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.3);
  --radius:     12px;
  --radius-sm:  7px;
  --ff-display: 'Playfair Display', Georgia, serif;
  --ff-mono:    'DM Mono', 'Courier New', monospace;
  --ff-ui:      'DM Sans', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--felt);
  color: var(--text);
  font-family: var(--ff-ui);
  font-size: 15px;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* subtle felt texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(255,255,255,0.015) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(232,168,56,0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}

/* ── Views ───────────────────────────────────────────────────── */
.view { display: none; width: 100%; max-width: 640px; }
.view.active { display: flex; flex-direction: column; }

/* ── Buttons ─────────────────────────────────────────────────── */
button {
  font-family: var(--ff-ui);
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background .12s, opacity .12s, transform .08s, box-shadow .12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button:active:not(:disabled) { transform: scale(0.96); }
button:disabled { opacity: .35; cursor: default; }

.btn-ghost-sm {
  background: transparent;
  color: var(--text-dim);
  padding: 7px 12px;
  font-size: 13px;
  border: 1px solid var(--felt-line);
}
.btn-ghost-sm:hover:not(:disabled) {
  background: var(--felt-light);
  color: var(--text);
}

.btn-add {
  background: var(--felt-light);
  color: var(--amber);
  border: 1px solid var(--felt-line);
  padding: 0 18px;
  height: 44px;
  font-size: 14px;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-add:hover { background: var(--felt-line); }

.btn-start {
  width: 100%;
  height: 52px;
  background: var(--amber);
  color: #1a1a0e;
  font-size: 17px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  letter-spacing: 0.01em;
  box-shadow: 0 4px 20px rgba(232,168,56,0.3);
}
.btn-start:hover:not(:disabled) {
  background: #f0b840;
  box-shadow: 0 6px 28px rgba(232,168,56,0.45);
}

/* ── Inputs ──────────────────────────────────────────────────── */
input[type="text"] {
  font-family: var(--ff-ui);
  font-size: 15px;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius-sm);
  color: var(--text);
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  height: 44px;
}
input[type="text"]::placeholder { color: var(--text-faint); }
input[type="text"]:focus {
  border-color: var(--amber-dim);
  box-shadow: 0 0 0 3px var(--amber-glow);
}


/* ══════════════════════════════════════════════════════════════
   SETUP VIEW
══════════════════════════════════════════════════════════════ */
#view-setup { min-height: 100dvh; justify-content: center; }

.setup-shell {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.setup-header {
  text-align: center;
  padding: 32px 24px 24px;
  background: linear-gradient(160deg, var(--felt-light) 0%, var(--card-bg) 100%);
  border-bottom: 1px solid var(--card-border);
  position: relative;
}
.setup-header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 50%;
  transform: translateX(-50%);
  width: 60px; height: 2px;
  background: var(--amber);
  border-radius: 2px;
}

.crown-mark {
  font-size: 36px;
  line-height: 1;
  color: var(--amber);
  margin-bottom: 10px;
  display: block;
  text-shadow: 0 0 20px var(--amber-glow);
}

.game-wordmark {
  font-family: var(--ff-display);
  font-size: 32px;
  font-weight: 900;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1;
}

.setup-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
}

.setup-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.player-list { display: flex; flex-direction: column; gap: 8px; }

.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn .18s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

.player-num {
  width: 28px; height: 28px;
  background: var(--felt-light);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
  font-family: var(--ff-mono);
}

.btn-remove {
  background: transparent;
  color: var(--text-faint);
  padding: 8px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  font-size: 16px;
  border: 1px solid transparent;
}
.btn-remove:hover:not(:disabled) {
  background: var(--red-bg);
  color: var(--red);
  border-color: rgba(224,92,92,0.2);
}

.add-row { display: flex; gap: 8px; }


/* ══════════════════════════════════════════════════════════════
   GAME VIEW (scoreboard)
══════════════════════════════════════════════════════════════ */
#view-game {
  min-height: 100dvh;
}

.game-shell {
  width: 100%;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--card-border);
  background: var(--felt-light);
  flex-shrink: 0;
}

.game-header-left { display: flex; align-items: center; gap: 10px; }

.badge-gameover {
  font-family: var(--ff-display);
  font-size: 14px;
  color: var(--amber);
  background: var(--amber-faint);
  border: 1px solid rgba(232,168,56,0.25);
  padding: 4px 12px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

/* ── Score Table ── */
.table-scroll {
  flex: 1;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--felt-line) transparent;
}
.table-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--felt-line); border-radius: 3px; }

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.score-table thead {
  position: sticky;
  top: 0;
  z-index: 20;
}

.score-table thead th {
  background: var(--felt-mid);
  border-bottom: 2px solid var(--amber-dim);
  padding: 10px 8px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.score-table thead th.col-round {
  text-align: left;
  padding-left: 14px;
  position: sticky;
  left: 0;
  z-index: 30;
  background: var(--felt-mid);
  box-shadow: 3px 0 8px rgba(0,0,0,0.3);
  min-width: 110px;
}

.score-table tbody tr {
  border-bottom: 1px solid var(--felt-line);
  transition: background .1s;
}

.score-table tbody tr.row-editable { cursor: pointer; }
.score-table tbody tr.row-editable:hover td { background: var(--felt-light) !important; }
.score-table tbody tr.row-active td { background: var(--amber-faint); }
.score-table tbody tr.row-active td.col-round-body {
  background: rgba(232,168,56,0.08);
}

.score-table td {
  padding: 8px;
  text-align: center;
  vertical-align: middle;
}

td.col-round-body {
  text-align: left;
  padding: 8px 10px 8px 14px;
  position: sticky;
  left: 0;
  background: var(--card-bg);
  z-index: 10;
  box-shadow: 3px 0 8px rgba(0,0,0,0.25);
  min-width: 110px;
}

.round-info { display: flex; flex-direction: column; gap: 4px; }

.round-cards-line {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.round-big {
  font-family: var(--ff-mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  line-height: 1;
}
.row-active .round-big { color: var(--amber); }

.round-suffix {
  font-size: 10px;
  color: var(--text-faint);
}

.dealer-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  color: #7ab0f5;
  background: rgba(122,176,245,0.10);
  padding: 2px 7px;
  border-radius: 10px;
  max-width: 92px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-hint {
  display: none;
  position: absolute;
  top: 7px; right: 8px;
  font-size: 11px;
  color: var(--text-faint);
}
td.col-round-body { position: relative; }
.row-editable:hover .edit-hint { display: block; }

/* score cells */
td.cell-score {
  font-family: var(--ff-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
}
td.cell-zero {
  color: var(--green-win);
  font-weight: 700;
  background: var(--green-win-bg) !important;
}
td.cell-empty {
  color: var(--text-faint);
  font-size: 13px;
}

.enter-btn {
  background: var(--amber);
  color: #1a1a0e;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.02em;
}
.enter-btn:hover { background: #f0b840; }

/* totals footer */
.score-table tfoot {
  position: sticky;
  bottom: 0;
  z-index: 20;
}

.score-table tfoot td {
  background: var(--felt-mid);
  border-top: 2px solid var(--felt-line);
  padding: 11px 8px;
  text-align: center;
  font-family: var(--ff-mono);
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
}

.score-table tfoot td.col-round-body {
  background: var(--felt-mid);
  text-align: left;
  font-family: var(--ff-ui);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.score-table tfoot td.td-winning {
  color: var(--amber);
}


/* ══════════════════════════════════════════════════════════════
   SCORE INPUT VIEW
══════════════════════════════════════════════════════════════ */
#view-score {
  min-height: 100dvh;
}

.score-shell {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.score-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-top: 2px;
}

.score-round-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

/* ── Player strip ── */
.player-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  flex-shrink: 0;
}
.player-strip::-webkit-scrollbar { display: none; }

.player-tile {
  flex-shrink: 0;
  width: 68px;
  height: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--felt-line);
  cursor: pointer;
  transition: all .15s;
  background: var(--card-bg);
  gap: 3px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.player-tile.tile-active {
  background: var(--amber);
  border-color: var(--amber);
  box-shadow: 0 4px 18px rgba(232,168,56,0.35);
}

.player-tile.tile-done:not(.tile-active) {
  border-color: rgba(94,201,122,0.35);
  background: var(--green-win-bg);
}

.tile-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-align: center;
  padding: 0 4px;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-active .tile-name { color: #1a1a0e; }

.tile-score {
  font-family: var(--ff-mono);
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
  color: var(--text);
}
.tile-active .tile-score { color: #1a1a0e; }
.tile-score.tile-score-empty { opacity: .25; font-size: 18px; }

/* ── Keypad ── */
.keypad-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
  box-shadow: var(--shadow-lg);
}

.keypad-who {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--felt-line);
  flex-shrink: 0;
}
.keypad-who-label {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
}
.keypad-who-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--amber);
  font-family: var(--ff-display);
}

.expr-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--felt-light);
  border-bottom: 1px solid var(--felt-line);
  font-family: var(--ff-mono);
  font-size: 14px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.expr-eq { font-weight: 700; color: var(--amber); }

.key-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 1px;
  background: var(--felt-line);
  flex: 1;
  min-height: 280px;
  height: calc(100dvh - 320px);
  max-height: 420px;
}

.key {
  background: var(--felt-mid);
  color: var(--text);
  font-size: 22px;
  font-family: var(--ff-mono);
  font-weight: 400;
  cursor: pointer;
  transition: background .08s, transform .07s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  border: none;
  border-radius: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.key:active:not(:disabled) { background: var(--felt-line); transform: scale(0.95); }

.key-del { background: rgba(224,92,92,0.12); color: var(--red); font-size: 15px; }
.key-del:active { background: rgba(224,92,92,0.22); }

.key-next { background: #1e4b9e; color: #fff; font-size: 14px; font-family: var(--ff-ui); font-weight: 700; }
.key-next:hover { background: #2356b8; }
.key-next:active { background: #1a4290; }
.key-next:disabled { opacity: .3; }

.key-finish { background: #145c2c; color: #fff; font-size: 14px; font-family: var(--ff-ui); font-weight: 700; }
.key-finish:hover { background: #196834; }
.key-finish:active { background: #124f26; }
.key-finish:disabled { opacity: .3; }

.key-row-bottom {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--felt-line);
  border-top: 1px solid var(--card-border);
  flex-shrink: 0;
}

.key-sm {
  background: var(--card-bg);
  color: var(--text-dim);
  border: none;
  border-radius: 0;
  height: 36px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background .08s, color .08s, transform .07s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.key-sm:active:not(:disabled) { transform: scale(0.94); }
.key-sm:hover:not(:disabled) { background: var(--felt-light); color: var(--text); }
.key-sm:disabled { opacity: .3; }
.key-sm-green { background: rgba(94,201,122,0.12); color: var(--green-win); }
.key-sm-green:hover:not(:disabled) { background: rgba(94,201,122,0.2); }
.key-sm-blue { background: rgba(30,75,158,0.25); color: #7ab0f5; }
.key-sm-blue:hover:not(:disabled) { background: rgba(30,75,158,0.4); }
.key-sm-plus { color: var(--amber); }
.key-sm-plus:hover:not(:disabled) { background: var(--amber-faint); }


/* ══════════════════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════════════════ */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }

.modal-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  width: 100%;
  max-width: 320px;
  padding: 22px;
  animation: popIn .15s ease;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.93) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
  font-family: var(--ff-display);
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.modal-list { display: flex; flex-direction: column; gap: 8px; }

.went-out-btn {
  background: var(--felt-light);
  border: 1.5px solid var(--felt-line);
  color: var(--text);
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-align: left;
  justify-content: flex-start;
  width: 100%;
  cursor: pointer;
  transition: background .1s, border-color .1s, color .1s;
  -webkit-tap-highlight-color: transparent;
}
.went-out-btn:hover {
  background: var(--amber-faint);
  border-color: var(--amber-dim);
  color: var(--amber);
}

.modal-cancel {
  margin-top: 14px;
  width: 100%;
  justify-content: center;
}
