/* App styles (everything except the game tables). Colors, sizes and spacing come from tokens.css. */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--text-base);
    line-height: 1.45;
    -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p { margin: 0; }
/* The router focuses each page's h1 for screen readers; it doesn't need a visible ring. */
h1:focus { outline: none; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- page frames ---------- */
.page {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-4) var(--space-4) var(--space-8);
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}
.page--narrow { max-width: 560px; }
.page--center { min-height: 100dvh; justify-content: center; align-items: center; }
.page__title { font-size: var(--text-xl); font-weight: 800; letter-spacing: -0.02em; }
.section-title { font-size: var(--text-base); font-weight: 700; }
.eyebrow { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.topbar {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
}
.topbar__middle { flex: 1; }

.wordmark {
    font-weight: 800;
    font-size: var(--text-lg);
    letter-spacing: -0.03em;
    color: var(--ink);
    text-decoration: none;
}
.wordmark span { color: var(--accent); font-weight: 600; }
.wordmark--lg { font-size: 40px; }

.avatar {
    width: 36px; height: 36px;
    flex: none;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 700;
    text-decoration: none;
}
.avatar--small { width: 28px; height: 28px; font-size: var(--text-sm); }
.avatar--away { opacity: 0.45; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-4);
    box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: var(--space-3); align-items: flex-start; }
.row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; justify-content: center; }

.pill {
    display: inline-block;
    padding: 0 var(--space-2);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: var(--text-xs);
    font-weight: 700;
    line-height: 20px;
    white-space: nowrap;
}

/* ---------- buttons and fields ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 48px;
    padding: 0 var(--space-5);
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: transform 80ms ease, opacity 120ms ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn--quiet { background: transparent; color: var(--muted); border-color: var(--line); min-height: 40px; padding: 0 var(--space-4); border-radius: var(--radius-sm); }
.btn--text { background: none; color: var(--accent); min-height: 40px; padding: 0 var(--space-2); }
.btn--muted { color: var(--muted); }
.btn--danger { background: var(--danger); color: var(--surface); }
.btn--text.btn--danger { background: none; color: var(--danger); }
.btn--small { min-height: 36px; padding: 0 var(--space-3); border-radius: var(--radius-sm); font-size: var(--text-sm); }
.btn--wide { width: 100%; }
.btn--call { background: var(--call); color: var(--call-ink); }
.btn--call-outline { background: none; color: var(--call); border-color: var(--call); min-height: 36px; padding: 0 var(--space-3); border-radius: var(--radius-sm); font-size: var(--text-sm); }

.form { display: flex; flex-direction: column; gap: var(--space-4); width: 100%; }
.form__footer { display: flex; justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__label { font-size: var(--text-sm); font-weight: 600; color: var(--muted); }
.input {
    min-height: 48px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.input--code { font-size: var(--text-lg); font-weight: 700; letter-spacing: 0.3em; text-transform: uppercase; }
.hint { font-size: var(--text-sm); color: var(--muted); }
.error-text { font-size: var(--text-sm); color: var(--danger); font-weight: 600; }
.banner { background: var(--accent-soft); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); }
.banner__title { font-weight: 700; }
.banner__text { font-size: var(--text-sm); }

/* ---------- welcome / sign-in ---------- */
.welcome { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: var(--space-6); align-items: center; }
.welcome__hero { text-align: center; display: flex; flex-direction: column; gap: var(--space-2); }
.welcome__tag { color: var(--muted); }

/* ---------- home: tiles ---------- */
.hello { display: flex; flex-direction: column; gap: var(--space-1); }
.hello__title { font-size: var(--text-xl); font-weight: 800; letter-spacing: -0.02em; }
.hello__text { color: var(--muted); }

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
}
.tile {
    display: flex;
    flex-direction: column;
    text-align: left;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
}
.tile:hover:not(:disabled) { transform: translateY(-2px); }
.tile:disabled { cursor: default; }
.tile--soon { box-shadow: none; }
.tile--soon .tile__art { filter: grayscale(0.7); opacity: 0.7; }
.tile__art { display: block; aspect-ratio: 3 / 2; background: var(--felt); }
.tile--tavli .tile__art { background: #6E4A2E; }
.tile--xeri .tile__art { background: #3B4C6B; }
.tile--biriba .tile__art { background: #6B3B4C; }
.tile__body { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-4); flex: 1; }
.tile__name { font-size: var(--text-lg); font-weight: 800; }
.tile__blurb { font-size: var(--text-sm); color: var(--muted); flex: 1; }
.tile__meta { display: flex; justify-content: space-between; align-items: center; margin-top: var(--space-2); font-size: var(--text-sm); color: var(--muted); }
.tile__cta { color: var(--accent); font-weight: 700; }

.art { width: 100%; height: 100%; display: block; }
.art__card { fill: var(--card); stroke: var(--card-line); stroke-width: 1; }
.art__card--gold { fill: var(--special-tint); }
.art__ink--jade { fill: var(--suit-jade); }
.art__ink--star { fill: var(--suit-star); }
.art__ink--gold { fill: var(--special-dragon); }
.art__label { fill: var(--suit-pagoda); font: 700 16px var(--font); }
.art__board { fill: #E8D3B0; }
.art__point { fill: #8C2F1F; }
.art__point--alt { fill: #2F4F3A; }
.art__piece { fill: #FFF8EC; stroke: #5B4330; }
.art__piece--dark { fill: #3A2A1E; }

.join__form { display: flex; gap: var(--space-2); max-width: 320px; }
.join__input { flex: 1; min-width: 0; }

/* ---------- lobby ---------- */
.lobby__invite { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.lobby__code { font-size: 36px; font-weight: 800; letter-spacing: 0.15em; }
.teams { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.team { display: flex; flex-direction: column; gap: var(--space-2); }
.team__title { font-size: var(--text-sm); font-weight: 700; color: var(--muted); }
.team--a .team__title { color: var(--accent); }
.team--b .team__title { color: var(--call); }
.seat {
    display: flex; align-items: center; gap: var(--space-2);
    flex-wrap: wrap;
    min-height: 64px;
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--line);
}
.seat--empty { border-style: dashed; background: transparent; }
.seat--me { border-color: var(--accent); }
.seat__name { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.seat--empty .seat__name { color: var(--muted); font-weight: 500; }
.presence { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.presence--on { background: var(--ok); }
.lobby__start { display: flex; flex-direction: column; gap: var(--space-2); align-items: center; text-align: center; }

/* ---------- states ---------- */
.empty { display: flex; flex-direction: column; gap: var(--space-3); align-items: center; text-align: center; max-width: 360px; }
.empty__title { font-size: var(--text-lg); font-weight: 800; }
.empty__text { color: var(--muted); }

.loading { min-height: 50dvh; display: flex; gap: var(--space-2); align-items: center; justify-content: center; }
.loading__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite ease-in-out; }
.loading__dot:nth-child(2) { animation-delay: 0.15s; }
.loading__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }

.connection-banner {
    position: sticky; top: 0; z-index: 20;
    display: flex; gap: var(--space-2); align-items: center; justify-content: center;
    padding: var(--space-2) var(--space-4);
    background: var(--call-soft);
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: 600;
}

@media (max-width: 420px) {
    .teams { grid-template-columns: 1fr; }
    .lobby__invite { flex-direction: column; align-items: stretch; text-align: center; }
}
