@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@400;500;600;700;800&display=swap');

:root {
    --bg:        #EEF0F3;
    --surface:   #FFFFFF;
    --ink:       #14161A;
    --muted:     #6B717B;
    --line:      #DDE1E7;
    --gold:      #F5C518;
    --gold-deep: #C79A00;
    --red:       #E23B33;
    --blue:      #2E7FD4;
    --white-ring:#FFFFFF;
    --miss:      #9AA1AB;
    --good:      #1E8F5B;
    --radius:    14px;
    --shadow:    0 1px 2px rgba(20,22,26,.06), 0 8px 24px rgba(20,22,26,.05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

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

.wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 16px 96px;
}
.wrap.narrow { max-width: 460px; }
.wrap.wide   { max-width: 1040px; }

/* ---------- Header ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    background: var(--ink);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar a { color: #fff; text-decoration: none; }
.brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; letter-spacing: -.01em;
}
.brand .rings {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--gold);
    box-shadow: inset 0 0 0 3px var(--ink), inset 0 0 0 6px var(--red);
    flex: none;
}
.topbar-actions { display: flex; gap: 14px; font-size: .9rem; font-weight: 500; }

/* ---------- Typography ---------- */
.page-title {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -.02em;
    margin: 18px 0 4px;
}
.page-sub { color: var(--muted); margin: 0 0 22px; font-size: .95rem; }
h2.section { font-size: 1.05rem; font-weight: 700; margin: 30px 0 12px; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 14px;
}
.card-flat { box-shadow: none; border: 1px solid var(--line); }

/* ---------- Forms ---------- */
label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=date], select {
    width: 100%;
    padding: 13px 14px;
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    appearance: none;
}
input:focus, select:focus, button:focus-visible, a:focus-visible {
    outline: 3px solid rgba(46,127,212,.35);
    outline-offset: 2px;
}
.field { margin-bottom: 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.code-input {
    text-align: center;
    font-size: 1.7rem;
    font-weight: 800;
    letter-spacing: .28em;
    text-transform: uppercase;
    padding: 16px 10px 16px 24px;
}

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 18px;
    font: inherit;
    font-weight: 600;
    border: 0;
    border-radius: 10px;
    background: var(--ink);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    min-height: 46px;
}
button:active { transform: translateY(1px); }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-gold  { background: var(--gold); color: var(--ink); }
.btn-danger{ background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn-sm    { padding: 8px 12px; min-height: 38px; font-size: .85rem; }

/* ---------- Notes ---------- */
.note { padding: 14px 16px; border-radius: 10px; font-size: .92rem; margin-bottom: 16px; }
.note p { margin: 6px 0 0; }
.note-bad  { background: #FDECEA; color: #8E1F19; }
.note-good { background: #E7F5EE; color: #14603F; }
.note-info { background: #EAF2FC; color: #1A4E86; }

/* ---------- Code chips ---------- */
.chip {
    display: inline-block;
    font-weight: 700;
    letter-spacing: .12em;
    background: var(--ink);
    color: #fff;
    padding: 5px 10px;
    border-radius: 7px;
    font-size: .85rem;
}
.chip-gold { background: var(--gold); color: var(--ink); }
.chip-line { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* ---------- Standings ---------- */
.standings { display: flex; flex-direction: column; gap: 8px; }
.rowcard {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 34px 1fr auto;
    align-items: center;
    gap: 12px;
}
.rank {
    font-weight: 800;
    font-size: 1.05rem;
    text-align: center;
    color: var(--muted);
}
.rowcard.top1 { box-shadow: inset 3px 0 0 var(--gold), var(--shadow); }
.rowcard.top1 .rank { color: var(--gold-deep); }
.rowcard.top2 { box-shadow: inset 3px 0 0 #B9BEC6, var(--shadow); }
.rowcard.top3 { box-shadow: inset 3px 0 0 #C98B4B, var(--shadow); }
.who { min-width: 0; }
.who .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .meta { font-size: .78rem; color: var(--muted); }
.totals { text-align: right; }
.totals .pts { font-weight: 800; font-size: 1.25rem; letter-spacing: -.02em; }
.totals .brk { font-size: .74rem; color: var(--muted); }

/* ---------- Target group ---------- */
.tgroup-head {
    display: flex; align-items: center; justify-content: space-between;
    margin: 26px 0 10px;
}
.tgroup-head h3 { margin: 0; font-size: .95rem; font-weight: 700; }

/* ---------- Scorecard ---------- */
.archer-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; }
.archer-tabs button {
    flex: none;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 9px 14px;
    font-size: .9rem;
    min-height: 42px;
}
.archer-tabs button[aria-selected="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

.ends { display: flex; flex-direction: column; gap: 8px; }
.end {
    display: grid;
    grid-template-columns: 28px 1fr 52px;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border-radius: 12px;
    padding: 8px 12px 8px 8px;
    box-shadow: var(--shadow);
}
.end-no { text-align: center; font-size: .8rem; font-weight: 700; color: var(--muted); }
.arrows { display: flex; gap: 6px; }
.slot {
    flex: 1;
    aspect-ratio: 1 / 1;
    max-width: 54px;
    min-height: 44px;
    border-radius: 9px;
    border: 1px dashed var(--line);
    background: #F7F8FA;
    color: var(--muted);
    font-weight: 700;
    font-size: 1.02rem;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    min-height: 44px;
}
.slot.filled { border-style: solid; }
.slot.sel { box-shadow: 0 0 0 3px rgba(46,127,212,.45); }
.end-sum { text-align: right; font-weight: 700; }
.slot.is-x { box-shadow: inset 0 0 0 3px rgba(20,22,26,.18); }

/* ring colours */
.v-gold  { background: var(--gold);   color: #14161A; border-color: var(--gold-deep); }
.v-red   { background: var(--red);    color: #fff;    border-color: #B92A23; }
.v-blue  { background: var(--blue);   color: #fff;    border-color: #1F5FA3; }
.v-black { background: #14161A;       color: #fff;    border-color: #000; }
.v-white { background: #fff;          color: #14161A; border-color: #B9BEC6; }
.v-miss  { background: var(--miss);   color: #fff;    border-color: #7B828C; }

/* ---------- Keypad ---------- */
.keypad {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    z-index: 40;
    transform: translateY(110%);
    transition: transform .18s ease-out;
    box-shadow: 0 -8px 30px rgba(20,22,26,.12);
}
.keypad.open { transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .keypad { transition: none; } }
.keypad-head {
    display: flex; align-items: center; justify-content: space-between;
    font-size: .85rem; color: var(--muted); margin-bottom: 10px;
}
.keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; max-width: 520px; margin: 0 auto; }
.keys button {
    padding: 0;
    height: 50px;
    font-size: 1.05rem;
    font-weight: 700;
    border: 1px solid transparent;
}
.keys button.v-white { border-color: #B9BEC6; }
.keys button.v-gold  { border-color: var(--gold-deep); }
body.keypad-open .wrap { padding-bottom: 280px; }
.keys .k-wide { grid-column: span 2; }

/* ---------- Tables (admin) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.table { width: 100%; min-width: 460px; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.table th { font-size: .76rem; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: .85rem; }
.right { text-align: right; }
.spacer { height: 8px; }

.or {
    display: flex; align-items: center; gap: 12px;
    color: var(--muted); font-size: .85rem;
    margin: 4px 0 14px;
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.status-live, .status-finished {
    font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 20px;
}
.status-live { background: #E7F5EE; color: var(--good); }
.status-finished { background: #EDEFF2; color: var(--muted); }

.saving-dot {
    position: fixed; top: 66px; right: 14px; z-index: 50;
    background: var(--ink); color: #fff; font-size: .78rem;
    padding: 6px 12px; border-radius: 20px; opacity: 0;
    transition: opacity .2s;
}
.saving-dot.show { opacity: 1; }

@media (min-width: 640px) {
    .page-title { font-size: 2rem; }
    .end { grid-template-columns: 40px 1fr 64px; }
}
