/* ================================================
   Rummikub Score Calculator — Stylesheet
   style.css  ·  used by index.html only
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&family=Noto+Sans+HK:wght@300;400;500&family=DM+Mono:wght@400;500&display=swap');

/* ── Design tokens ── */
:root
{
  --bg:           #f5f3ee;
  --bg2:          #ede9e1;
  --surface:      #ffffff;
  --surface2:     #f0ede6;
  --border:       rgba(0,0,0,0.08);
  --border-h:     rgba(0,0,0,0.18);
  --text:         #1a1814;
  --text-sec:     #3d3a33;
  --muted:        #7a7568;
  --dim:          #a8a399;

  --font-display: 'Outfit', sans-serif;
  --font-body:    'Noto Sans HK', sans-serif;
  --font-mono:    'DM Mono', monospace;

  /* Rack gold — primary brand accent for this app */
  --gold:         #8a6200;
  --gold-dim:     #6b4c00;
  --gold-bg:      rgba(138,98,0,0.08);
  --gold-border:  rgba(138,98,0,0.26);

  /* Rummikub tile colours — purely decorative chip cycling */
  --tile-red:     #b3382c;
  --tile-blue:    #1a5fb4;
  --tile-black:   #2a271f;
  --tile-orange:  #c96a12;

  --pos:          #157a3c;
  --pos-bg:       rgba(21,122,60,0.08);
  --neg:          #b3382c;
  --neg-bg:       rgba(179,56,44,0.08);

  --radius-card:  20px;
  --shadow-card:  0 2px 12px rgba(0,0,0,0.07), 0 0 0 1px var(--border);
  --shadow-hover: 0 10px 32px rgba(0,0,0,0.13), 0 0 0 1px var(--border-h);
}

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

/* Author rules setting `display` below would otherwise beat the UA
   stylesheet's [hidden] rule since author styles always win the cascade. */
[hidden] { display: none !important; }

body
{
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image: radial-gradient(circle, rgba(0,0,0,0.065) 1px, transparent 1px);
  background-size: 26px 26px;
}

button { font: inherit; }

/* ── Back nav ── */
.back-nav
{
  padding: 28px 28px 0;
  opacity: 0;
  animation: fadeUp 0.4s ease forwards;
  animation-delay: 0.02s;
}

.back-link
{
  font-family: var(--font-mono);
  font-size: 0.688rem;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.06em;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s;
}

.back-link:hover { color: var(--gold); }

@keyframes fadeUp
{
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════
   Shared layout
══════════════════════════════════════ */
.rk-app
{
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 20px 96px;
}

.rk-card
{
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 28px;
  width: 100%;
  max-width: 560px;
  opacity: 0;
  animation: fadeUp 0.4s ease forwards;
  animation-delay: 0.08s;
}

.rk-label
{
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 10px;
}

.rk-pill
{
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}

.rk-pill:hover     { border-color: var(--gold-border); color: var(--text); }
.rk-pill:active    { transform: scale(0.97); }
.rk-pill.active
{
  background: var(--gold-bg);
  border-color: var(--gold-border);
  color: var(--gold-dim);
}

.rk-btn-primary
{
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dim) 100%);
  color: #fff8ea;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s, transform .1s;
  box-shadow: 0 4px 16px rgba(138,98,0,0.28);
}

.rk-btn-primary:hover  { filter: brightness(1.08); }
.rk-btn-primary:active { transform: scale(0.98); }

.rk-btn-block { width: 100%; max-width: 560px; }

.rk-btn-text
{
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color .15s;
}

.rk-btn-text:hover { color: var(--text); }

.rk-btn-sm
{
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--font-display);
  color: var(--text-sec);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.rk-btn-sm:hover { border-color: var(--gold-border); color: var(--gold-dim); }

.rk-error
{
  color: var(--neg);
  font-size: 12.5px;
  font-family: var(--font-mono);
  margin-top: 10px;
}

/* ══════════════════════════════════════
   Setup screen
══════════════════════════════════════ */
.rk-setup { width: 100%; display: flex; justify-content: center; padding-top: 24px; }

.rk-setup-card
{
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 40px 32px;
}

.rk-tile-icon
{
  width: 64px;
  height: 64px;
  border-radius: 14px;
  background: linear-gradient(160deg, #fffdf7 0%, #f2ead4 100%);
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 3px 0 rgba(0,0,0,0.12), 0 6px 14px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 12px;
}

.rk-tile-icon .tr { color: var(--tile-red); }
.rk-tile-icon .tb { color: var(--tile-black); }

.rk-setup-card h1
{
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.rk-sub
{
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.65;
  max-width: 40ch;
  margin-bottom: 12px;
}

.rk-field { width: 100%; text-align: left; margin-top: 14px; }

.rk-count-pills { display: flex; gap: 8px; flex-wrap: wrap; }

.rk-name-inputs { display: flex; flex-direction: column; gap: 8px; }

.rk-name-input
{
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text);
  font-family: var(--font-body);
  transition: border-color .15s, background .15s;
}

.rk-name-input:focus
{
  outline: none;
  border-color: var(--gold-border);
  background: var(--surface);
}

.rk-setup-card .rk-btn-primary { margin-top: 24px; }

/* ══════════════════════════════════════
   Game screen
══════════════════════════════════════ */
.rk-game
{
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Scoreboard ── */
.rk-scoreboard
{
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  opacity: 0;
  animation: fadeUp 0.4s ease forwards;
  animation-delay: 0.02s;
}

.rk-score-pill
{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: box-shadow .2s, transform .15s, border-color .15s;
}

.rk-score-pill:hover  { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.rk-score-pill.active { border-color: var(--gold-border); }

.rk-score-pill.leader { border-color: rgba(138,98,0,0.4); background: var(--gold-bg); }

.rk-score-pill .name
{
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sec);
}

.rk-score-pill .total
{
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.rk-score-pill .total.pos { color: var(--pos); }
.rk-score-pill .total.neg { color: var(--neg); }
.rk-score-pill .crown { font-size: 13px; }

/* ── Round bar ── */
.rk-round-bar
{
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rk-round-label
{
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.rk-round-label span { color: var(--gold-dim); font-weight: 600; }

/* ── Winner card ── */
.rk-winner-pills { display: flex; gap: 8px; flex-wrap: wrap; }

.rk-pill-draw.active
{
  background: var(--surface2);
  border-color: var(--border-h);
  color: var(--text);
}

/* ── Calculator card ── */
.rk-calc-card { display: flex; flex-direction: column; gap: 0; padding: 0; overflow: hidden; }

.rk-calc-tabs
{
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.rk-calc-tab
{
  flex: 1 0 auto;
  background: none;
  border: none;
  padding: 14px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}

.rk-calc-tab:hover  { color: var(--text-sec); }
.rk-calc-tab.active { color: var(--gold-dim); border-color: var(--gold); background: var(--surface); }

.rk-calc-body { padding: 22px 24px 26px; display: flex; flex-direction: column; gap: 16px; }

/* Tile chips */
.rk-tile-chips
{
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
}

.rk-chip-empty
{
  font-size: 12.5px;
  color: var(--dim);
  font-family: var(--font-mono);
  align-self: center;
}

.rk-chip
{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 8px;
  padding: 5px 6px 5px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: #fff8ea;
  animation: scaleIn 0.2s ease;
}

@keyframes scaleIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }

.rk-chip .rm
{
  background: rgba(255,255,255,0.2);
  border: none;
  color: inherit;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s;
}

.rk-chip .rm:hover { background: rgba(255,255,255,0.36); }

.rk-chip-red    { background: var(--tile-red); }
.rk-chip-blue   { background: var(--tile-blue); }
.rk-chip-black  { background: var(--tile-black); }
.rk-chip-orange { background: var(--tile-orange); }
.rk-chip-joker  { background: linear-gradient(135deg, var(--gold) 0%, var(--tile-red) 50%, var(--tile-blue) 100%); }

.rk-calc-subtotal
{
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
}

.rk-calc-subtotal span
{
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Winner note */
.rk-winner-note
{
  background: var(--gold-bg);
  border: 1px solid var(--gold-border);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--gold-dim);
  font-weight: 600;
}

/* Tile grid — 14 buttons: 1–13 + Joker, one tap adds a tile */
.rk-tile-grid
{
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.rk-tile-btn
{
  aspect-ratio: 1;
  background: linear-gradient(160deg, #fffdf7 0%, #f2ead4 100%);
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  box-shadow: 0 2px 0 rgba(0,0,0,0.1), 0 3px 7px rgba(0,0,0,0.08);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .1s, box-shadow .15s;
}

.rk-tile-btn:hover  { transform: translateY(-2px); box-shadow: 0 4px 0 rgba(0,0,0,0.1), 0 8px 14px rgba(0,0,0,0.12); }
.rk-tile-btn:active { transform: translateY(1px) scale(0.95); box-shadow: 0 1px 0 rgba(0,0,0,0.1); }

/* cycle tile-number colours like the real game */
.rk-tile-btn:nth-child(4n+1) { color: var(--tile-red); }
.rk-tile-btn:nth-child(4n+2) { color: var(--tile-blue); }
.rk-tile-btn:nth-child(4n+3) { color: var(--tile-black); }
.rk-tile-btn:nth-child(4n)   { color: var(--tile-orange); }

.rk-tile-btn-joker
{
  background: linear-gradient(135deg, var(--gold) 0%, var(--tile-red) 50%, var(--tile-blue) 100%);
  color: #fff8ea;
  flex-direction: column;
  gap: 1px;
  font-size: 18px;
}

.rk-tile-joker-value
{
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  opacity: 0.85;
}

/* ── History ── */
.rk-history-card { padding: 22px 22px 26px; }

.rk-history-header
{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.rk-history-header span
{
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}

.rk-history-scroll { overflow-x: auto; }

.rk-history-empty
{
  font-size: 12.5px;
  color: var(--dim);
  font-family: var(--font-mono);
  text-align: center;
  padding: 8px 0 2px;
}

#history-table { width: 100%; border-collapse: collapse; min-width: 340px; }

#history-table th
{
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  text-align: left;
  padding: 6px 10px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

#history-table td
{
  font-family: var(--font-mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-sec);
  white-space: nowrap;
}

#history-table tbody tr:hover { background: rgba(0,0,0,0.02); }

.rk-round-cell { color: var(--dim); font-weight: 600; }

.rk-draw-tag
{
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  text-transform: uppercase;
}

#history-table td.pos { color: var(--pos); }
#history-table td.neg { color: var(--neg); }

.rk-total-row td
{
  font-weight: 700;
  border-bottom: none;
  border-top: 2px solid var(--border);
  color: var(--text);
}

/* ══════════════════════════════════════
   Final results modal
══════════════════════════════════════ */
.rk-modal-overlay
{
  position: fixed;
  inset: 0;
  background: rgba(26,24,20,0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
  animation: fadeUp 0.25s ease;
}

.rk-modal
{
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-hover);
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rk-modal-icon { font-size: 40px; margin-bottom: 4px; }

.rk-modal h2
{
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 14px;
}

.rk-final-list { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.rk-final-row
{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.rk-final-row.winner
{
  background: var(--gold-bg);
  border-color: var(--gold-border);
}

.rk-final-row .rank
{
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  width: 24px;
}

.rk-final-row .name
{
  flex: 1;
  text-align: left;
  font-weight: 600;
  font-size: 14px;
}

.rk-final-row .total
{
  font-family: var(--font-mono);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.rk-final-row .total.pos { color: var(--pos); }
.rk-final-row .total.neg { color: var(--neg); }

.rk-modal-actions { display: flex; gap: 16px; align-items: center; margin-top: 10px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gold-border); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 600px)
{
  .rk-app { padding: 20px 14px 72px; }
  .rk-setup-card { padding: 32px 22px; }
  .rk-calc-body { padding: 18px 16px 22px; }
  .rk-tile-grid { grid-template-columns: repeat(5, 1fr); }
}
