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

:root {
    --bg:        #121213;
    --surface:   #1a1a1b;
    --border:    #3a3a3c;
    --text:      #ffffff;
    --muted:     #818384;
    --green:     #538d4e;
    --yellow:    #b59f3b;
    --tile-gray: #3a3a3c;
    --danger:    #c0392b;
    --warn:      #b59f3b;
    --font:      'Inter', Arial, sans-serif;
}

html { font-size: 16px; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.muted    { color: var(--muted); }
.accent   { color: var(--green); font-weight: 700; }
.card     { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; }

/* ── Tiles ────────────────────────────────────────────────────────────────── */
.tile-row {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.tile {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
    font-weight: 700;
    font-size: 1.25rem;
    text-transform: uppercase;
    border-radius: 3px;
    user-select: none;
}

.tile-gray   { background: var(--tile-gray); color: #fff; }
.tile-green  { background: var(--green);    color: #fff; }
.tile-yellow { background: var(--yellow);   color: #fff; }

@media (max-width: 600px) {
    .tile { width: 40px; height: 40px; font-size: 1rem; }
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.1rem;
    border-radius: 4px;
    font-family: var(--font);
    font-weight: 700;
    font-size: 0.875rem;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s, background 0.15s;
    white-space: nowrap;
}
.btn:hover { opacity: 0.85; }

.btn-primary { background: var(--green); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface); opacity: 1; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-block   { width: 100%; }
.btn-sm      { padding: 0.3rem 0.75rem; font-size: 0.8rem; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.input {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font);
    font-size: 1rem;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    width: 100%;
    outline: none;
    transition: border-color 0.15s;
}
.input:focus { border-color: var(--green); }
.input::placeholder { color: var(--muted); }
.input-sm { font-size: 0.875rem; padding: 0.3rem 0.6rem; }

/* ── Alerts ───────────────────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error   { background: #3a0e0e; border: 1px solid var(--danger); color: #ff8080; }
.alert-success { background: #0e2e14; border: 1px solid var(--green);  color: #7dcc87; }
.alert-warn    { background: #2e2700; border: 1px solid var(--warn);   color: #e0c84a; }

/* ── Form helpers ─────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label { font-size: 0.8rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.form-inline { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.form-inline .input { flex: 1; min-width: 160px; }

/* ══════════════════════════════════════════════════════════════════════════
   PUBLIC STATS PAGE
══════════════════════════════════════════════════════════════════════════ */

.page-wrap {
    max-width: 860px;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}

/* Site header */
.site-header {
    padding: 1.5rem 0 1.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}
.header-inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
}
.site-title {
    font-size: 1.5rem;
    letter-spacing: 0.15em;
    font-weight: 700;
    justify-self: start;
}
.site-subtitle {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--muted);
    text-transform: uppercase;
    justify-self: center;
}
.header-admin {
    justify-self: end;
}

/* Stats */
.stats-section { margin-bottom: 2rem; }

/* Score sections */
.score-section {
    margin-top: 1.25rem;
}
.score-section-label {
    text-align: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}
.score-box {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}
.score-tile {
    width: 52px;
    height: 52px;
    font-size: 1.5rem;
    font-weight: 700;
    flex-shrink: 0;
}
@media (max-width: 600px) {
    .score-tile { width: 40px; height: 40px; font-size: 1.2rem; }
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
}
.stat-card-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 0.08em;
    margin-bottom: 0.9rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}
.stat-rows { display: flex; flex-direction: column; gap: 0.45rem; }
.stat-row  { display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; }
.stat-label { color: var(--muted); }
.stat-value { font-weight: 700; }

/* Chart */
.chart-section { margin-bottom: 2rem; }
.chart-header  { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.chart-header h2 { font-size: 1rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.chart-toggle { display: flex; gap: 0.4rem; }
.chart-view-btn.active { background: var(--green); color: #fff; border-color: transparent; }
.chart-container { position: relative; height: 260px; }

/* Results list */
.results-section { }
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.results-header h2 { font-size: 1rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

.results-list { display: flex; flex-direction: column; gap: 0.75rem; }

.result-entry {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    gap: 0.5rem 1.25rem;
    align-items: start;
}
.result-date {
    color: var(--muted);
    font-size: 0.85rem;
    grid-column: 1;
    grid-row: 1;
    padding-top: 4px;
    white-space: nowrap;
}
.result-word { grid-column: 1; grid-row: 2; }
.result-players {
    grid-column: 2;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    justify-content: center;
}
.result-player {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
}
.result-winner { background: #0e2e14; border: 1px solid var(--green); }
.result-player-name { flex: 1; font-weight: 600; }
.result-tries { color: var(--muted); font-size: 0.85rem; }
.result-pts   { font-weight: 700; font-size: 0.85rem; }

.hidden-entry { display: none; }

@media (max-width: 500px) {
    .result-entry {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }
    .result-date   { grid-row: 1; }
    .result-word   { grid-row: 2; }
    .result-players { grid-column: 1; grid-row: 3; }
}

/* ══════════════════════════════════════════════════════════════════════════
   ADMIN PAGE
══════════════════════════════════════════════════════════════════════════ */

/* Login */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 360px;
}
.login-title { font-size: 1.75rem; letter-spacing: 0.1em; text-align: center; margin-bottom: 0.25rem; }
.login-sub   { color: var(--muted); text-align: center; font-size: 0.9rem; margin-bottom: 1.5rem; }
.login-box .form-group { margin-bottom: 1rem; }

/* Admin layout */
.admin-wrap {
    max-width: 1000px;
    margin: 0 auto;
    padding: 1.5rem 1rem 4rem;
}
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
    flex-wrap: wrap;
}
.admin-header h1 { font-size: 1.4rem; letter-spacing: 0.08em; }
.admin-header nav { display: flex; gap: 0.5rem; }

.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.admin-section h2 {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 1.25rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}

/* Add result form */
.result-form-row {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
@media (max-width: 500px) {
    .result-form-row { grid-template-columns: 1fr; }
}
.tries-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.tries-grid-label {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 0.75rem;
}
.tries-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.85rem 1.25rem;
    min-width: 200px;
}
.tries-player { font-weight: 700; margin-bottom: 0.6rem; font-size: 0.9rem; }
.tries-row    { display: flex; align-items: center; gap: 0.6rem; }
.tries-input  { width: 70px; text-align: center; }
.pts-preview  { color: var(--green); font-weight: 700; font-size: 0.9rem; white-space: nowrap; }

/* Results table */
.table-wrap   { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table  { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 500px; }
.admin-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}
.admin-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: rgba(255,255,255,0.02); }
.word-cell { font-weight: 600; letter-spacing: 0.05em; }

/* Player management */
.player-list   { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.25rem; }
.player-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 0.85rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    flex-wrap: wrap;
}
.player-name    { font-weight: 600; }
.player-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
.player-edit-form { display: flex; align-items: center; gap: 0.5rem; flex: 1; flex-wrap: wrap; }
.player-edit-form .input { flex: 1; min-width: 120px; }

.add-player-form { margin-top: 0.75rem; }
