/* ============================================================
   Oché – darts scorer
   Palette from the board itself: sisal cream, board red/green,
   brass ring, spider-wire lines on a late-night pub dark.
   ============================================================ */
:root {
    --bg:        #131715;
    --surface:   #1c221e;
    --surface-2: #232b26;
    --sisal:     #efe6d0;
    --sisal-dim: #b3aa93;
    --red:       #c63a2f;
    --red-soft:  #e0564a;
    --green:     #2e7d53;
    --green-soft:#3f9d6c;
    --brass:     #c9a44c;
    --wire:      #39423c;
    --danger:    #e0564a;
    --radius:    14px;
    --font-body: 'Barlow', system-ui, sans-serif;
    --font-num:  'Barlow Condensed', 'Barlow', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--sisal);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.45;
    min-height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { max-width: 560px; margin: 0 auto; padding: 16px 16px 32px; }
@media (min-width: 768px) { #app { max-width: 640px; padding-top: 28px; } }

h1, h2, h3 { font-family: var(--font-num); font-weight: 600; letter-spacing: .02em; margin: 0 0 .4em; }
h1 { font-size: 2rem; text-transform: uppercase; }
h2 { font-size: 1.35rem; }
p  { margin: 0 0 1em; color: var(--sisal-dim); }

a { color: var(--brass); }

/* ---------- shared components ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--wire);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
}

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    font-family: var(--font-num); font-weight: 600; font-size: 1.05rem;
    letter-spacing: .04em; text-transform: uppercase;
    background: var(--green); color: var(--sisal);
    border: none; border-radius: 12px;
    min-height: 50px; padding: 0 22px;
    width: 100%; cursor: pointer;
    transition: transform .06s ease, filter .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.btn.secondary { background: var(--surface-2); border: 1px solid var(--wire); }
.btn.danger    { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn.brass     { background: var(--brass); color: #1a1509; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn.small { min-height: 40px; font-size: .95rem; width: auto; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .85rem; color: var(--sisal-dim); margin-bottom: 6px; }
.field input, .field select {
    width: 100%; min-height: 50px;
    background: var(--surface-2); color: var(--sisal);
    border: 1px solid var(--wire); border-radius: 12px;
    padding: 0 14px; font-size: 1.05rem; font-family: var(--font-body);
}
.field input:focus, .field select:focus { outline: 2px solid var(--brass); outline-offset: -1px; border-color: var(--brass); }

.msg-error {
    background: rgba(198, 58, 47, .12); border: 1px solid var(--red);
    color: var(--red-soft); border-radius: 10px;
    padding: 10px 14px; margin-bottom: 14px; font-size: .95rem;
}

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px;
}
.topbar .logo { font-family: var(--font-num); font-weight: 700; font-size: 1.4rem;
    text-transform: uppercase; letter-spacing: .08em; }
.topbar .logo span { color: var(--red-soft); }
.topbar .who { font-size: .9rem; color: var(--sisal-dim); }
.topbar button.linklike {
    background: none; border: none; color: var(--brass);
    font: inherit; cursor: pointer; padding: 6px 0 6px 12px;
}

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button {
    flex: 1; min-height: 44px; border-radius: 10px;
    background: var(--surface); border: 1px solid var(--wire);
    color: var(--sisal-dim); font-family: var(--font-num); font-size: 1rem;
    text-transform: uppercase; letter-spacing: .04em; cursor: pointer;
}
.tabs button.active { color: var(--sisal); border-color: var(--brass); background: var(--surface-2); }

/* ---------- lobby ---------- */
.invite-code {
    font-family: var(--font-num); font-weight: 700;
    font-size: 3.2rem; letter-spacing: .35em; text-align: center;
    color: var(--brass); padding: 10px 0 4px; user-select: all;
}
.pulse-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%;
    background: var(--green-soft); margin-right: 8px; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }
@media (prefers-reduced-motion: reduce) { .pulse-dot { animation: none; } }

/* ---------- game screen ---------- */
.scoreboard { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.player-panel {
    background: var(--surface); border: 1px solid var(--wire);
    border-radius: var(--radius); padding: 12px 10px 14px; text-align: center;
    position: relative; overflow: hidden;
}
.player-panel.turn { border-color: var(--brass); }
.player-panel.turn::before {
    content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
    background: var(--brass);
}
.player-panel .pname {
    font-size: .95rem; color: var(--sisal-dim); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; padding: 0 4px;
}
.player-panel .legs { font-size: .8rem; color: var(--brass); letter-spacing: .1em; margin-top: 2px; }
.player-panel .remaining {
    font-family: var(--font-num); font-weight: 700; line-height: 1;
    font-size: clamp(3.4rem, 18vw, 5.6rem); margin: 6px 0 2px;
}
.player-panel .avg { font-size: .82rem; color: var(--sisal-dim); }
.player-panel.turn .remaining { color: var(--sisal); }
.player-panel:not(.turn) .remaining { color: var(--sisal-dim); }

/* signature: spider-wire leg progress, alternating board red/green */
.wire-strip { display: flex; gap: 3px; height: 6px; margin: 10px 2px 0; }
.wire-strip i { flex: 1; border-radius: 2px; background: var(--surface-2); }
.wire-strip i.on:nth-child(odd)  { background: var(--red); }
.wire-strip i.on:nth-child(even) { background: var(--green-soft); }

.checkout-hint {
    text-align: center; margin: 2px 0 10px;
    font-family: var(--font-num); font-size: 1.15rem; letter-spacing: .06em;
    color: var(--brass); min-height: 1.5em;
}
.checkout-hint b { color: var(--sisal); }

.visit-log { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; min-height: 30px; }
.visit-chip {
    font-family: var(--font-num); font-size: .95rem;
    background: var(--surface-2); border: 1px solid var(--wire);
    border-radius: 8px; padding: 3px 9px; color: var(--sisal-dim);
}
.visit-chip.p1 { border-left: 3px solid var(--red); }
.visit-chip.p2 { border-left: 3px solid var(--green-soft); }
.visit-chip.bust { color: var(--danger); text-decoration: line-through; }
.visit-chip.co { color: var(--brass); border-color: var(--brass); }

/* keypad */
.entry-display {
    font-family: var(--font-num); font-weight: 700; font-size: 2.4rem;
    text-align: center; min-height: 1.3em; line-height: 1.3;
    color: var(--sisal); margin-bottom: 8px;
}
.entry-display.invalid { color: var(--danger); }
.quick-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 8px; }
.quick-row button {
    min-height: 42px; border-radius: 10px; border: 1px solid var(--wire);
    background: var(--surface); color: var(--sisal-dim);
    font-family: var(--font-num); font-size: 1rem; cursor: pointer;
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
    min-height: 58px; font-size: 1.5rem; font-family: var(--font-num); font-weight: 600;
    background: var(--surface-2); color: var(--sisal);
    border: 1px solid var(--wire); border-radius: 12px; cursor: pointer;
}
.keypad button:active { transform: scale(.96); }
.keypad button.ok { background: var(--green); border-color: var(--green); }
.keypad button.del { color: var(--danger); }
.keypad button[disabled] { opacity: .4; }
@media (min-width: 480px) { .keypad button { min-height: 64px; } }

.game-actions { display: flex; gap: 10px; margin-top: 12px; }
.game-actions .btn { flex: 1; }

.waiting-note { text-align: center; color: var(--sisal-dim); padding: 24px 0; }

/* live stats table */
table.stats { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.stats td { padding: 7px 4px; border-bottom: 1px solid var(--wire); }
table.stats td:first-child { text-align: right; font-family: var(--font-num); font-size: 1.1rem; }
table.stats td:last-child  { text-align: left;  font-family: var(--font-num); font-size: 1.1rem; }
table.stats td.lbl { text-align: center; color: var(--sisal-dim); font-size: .82rem;
    text-transform: uppercase; letter-spacing: .06em; width: 44%; }

/* ---------- profile ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-box {
    background: var(--surface); border: 1px solid var(--wire); border-radius: 12px;
    padding: 12px 8px; text-align: center;
}
.stat-box .v { font-family: var(--font-num); font-weight: 700; font-size: 1.7rem; }
.stat-box .k { font-size: .72rem; color: var(--sisal-dim); text-transform: uppercase; letter-spacing: .06em; }
.stat-box.hero { grid-column: span 3; padding: 16px; }
.stat-box.hero .v { font-size: 3rem; color: var(--brass); }

.recent-game {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 2px; border-bottom: 1px solid var(--wire); font-size: .95rem;
}
.recent-game .res { font-family: var(--font-num); font-weight: 700; width: 28px; }
.recent-game .res.w { color: var(--green-soft); }
.recent-game .res.l { color: var(--red-soft); }
.recent-game .opp { flex: 1; padding: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-game .avg { color: var(--sisal-dim); font-family: var(--font-num); }

/* ---------- modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.6);
    display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
@media (min-width: 480px) { .modal-backdrop { align-items: center; } }
.modal {
    background: var(--surface); border: 1px solid var(--wire);
    border-radius: 18px 18px 0 0; width: 100%; max-width: 480px; padding: 20px;
}
@media (min-width: 480px) { .modal { border-radius: 18px; } }
.darts-choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.darts-choice button {
    min-height: 62px; font-family: var(--font-num); font-size: 1.4rem; font-weight: 600;
    background: var(--surface-2); border: 1px solid var(--wire); color: var(--sisal);
    border-radius: 12px; cursor: pointer;
}
.darts-choice button[disabled] { opacity: .35; }

.winner-banner {
    text-align: center; padding: 26px 0 10px;
}
.winner-banner .trophy { font-size: 3rem; }
.winner-banner h2 { color: var(--brass); font-size: 2rem; margin: 8px 0 2px; }
