/* Togyz — steppe sand, walnut board, sky-blue and gold accents. Mobile first. */

:root {
    --sand: #f4ecdf;
    --sand-deep: #e9dcc6;
    --paper: #fffaf1;
    --ink: #2b2118;
    --ink-soft: #6b5a48;
    --line: #dccdb4;
    --sky: #0f6e84;
    --sky-dark: #0a5466;
    --sky-soft: #d9eef2;
    --gold: #fec50c;
    --gold-dark: #c99700;
    --wood: #6b4226;
    --wood-dark: #4a2c18;
    --wood-light: #8a5a36;
    --pit: #3b2313;
    --stone-light: #fff6e0;
    --stone-dark: #cbb489;
    --win: #1d7a46;
    --win-soft: #dff3e6;
    --loss: #b3372f;
    --loss-soft: #fbe3e0;
    --warn: #8a5a00;
    --warn-soft: #fff1cf;
    --radius: 14px;
    --shadow: 0 2px 10px rgb(60 40 20 / 10%);
    --tabbar-height: 62px;
    color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--sand);
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); }
h2 { font-size: 1.2rem; display: flex; align-items: center; gap: .45rem; }
h3 { font-size: 1rem; margin-top: 1rem; color: var(--ink-soft); }
p { margin: 0 0 .8rem; }
a { color: var(--sky-dark); }
a:hover { color: var(--sky); }
h1:focus { outline: none; }
code { background: var(--sand-deep); padding: .1rem .35rem; border-radius: 6px; font-size: .85em; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.preserve-lines { white-space: pre-line; }
.icon { flex: none; vertical-align: -4px; }

/* Splash shown until the WebAssembly app has rendered ------------------------------------------------------------ */

#app-splash {
    position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 1.2rem; background: var(--sand); z-index: 50;
}
body:has(.app-shell) #app-splash { display: none; }

/* Shell ---------------------------------------------------------------------------------------------------------- */

.app-shell { min-height: 100vh; display: flex; flex-direction: column; padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom)); }

.topbar {
    position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
    padding: .55rem clamp(.75rem, 3vw, 2rem); background: var(--sky); color: #fff; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.25rem; letter-spacing: .02em; }
.brand:hover { color: #fff; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 9px; flex: none;
    background:
        radial-gradient(circle at 50% 50%, var(--gold) 0 17%, transparent 18%),
        radial-gradient(circle at 20% 20%, var(--stone-light) 0 13%, transparent 14%),
        radial-gradient(circle at 80% 20%, var(--stone-light) 0 13%, transparent 14%),
        radial-gradient(circle at 20% 80%, var(--stone-light) 0 13%, transparent 14%),
        radial-gradient(circle at 80% 80%, var(--stone-light) 0 13%, transparent 14%),
        var(--sky-dark);
}
.brand-mark--large { width: 72px; height: 72px; border-radius: 20px; }

.topnav { display: none; gap: .15rem; flex: 1; }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.inline-form { display: inline; margin: 0; }

.nav-item {
    display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .75rem; border-radius: 999px;
    color: #e6f5f8; text-decoration: none; font-weight: 500; white-space: nowrap;
}
.nav-item:hover { background: rgb(255 255 255 / 14%); color: #fff; }
.nav-item.active { background: #fff; color: var(--sky-dark); }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(6, 1fr);
    height: calc(var(--tabbar-height) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--paper); border-top: 1px solid var(--line);
}
.tabbar .nav-item {
    flex-direction: column; justify-content: center; gap: .1rem; padding: .3rem .1rem; border-radius: 0;
    color: var(--ink-soft); font-size: .68rem; min-width: 0;
}
.tabbar .nav-item span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tabbar .nav-item.active { color: var(--sky-dark); background: var(--sky-soft); }
.tabbar .nav-item--primary .icon { color: var(--gold-dark); }

.account-chip { display: inline-flex; align-items: center; gap: .35rem; color: #fff; text-decoration: none; font-weight: 600; max-width: 38vw; }
.account-chip:hover { color: #fff; text-decoration: underline; }
.account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.culture-switch { display: inline-flex; margin: 0; border-radius: 999px; overflow: hidden; border: 1px solid rgb(255 255 255 / 45%); }
.culture-option { border: 0; background: transparent; color: #e6f5f8; padding: .3rem .6rem; font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer; }
.culture-option.is-active { background: #fff; color: var(--sky-dark); }

.content { flex: 1; width: 100%; }
.page { width: min(1180px, 100%); margin: 0 auto; padding: 1rem clamp(.75rem, 3vw, 2rem) 2rem; display: flex; flex-direction: column; gap: 1rem; }
.page.narrow { width: min(560px, 100%); }
.page--game { width: min(1320px, 100%); }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; }

/* Building blocks ------------------------------------------------------------------------------------------------ */

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.card-header h2 { margin: 0; }

.grid { display: grid; gap: 1rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .55rem 1rem; min-height: 42px;
    border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); font: inherit; font-weight: 600;
    text-decoration: none; cursor: pointer; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--sand); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .pit:focus-visible, .chip:focus-visible, .segment:focus-visible, .tab:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.btn--primary { background: var(--sky); border-color: var(--sky); color: #fff; }
.btn--primary:hover { background: var(--sky-dark); color: #fff; }
.btn--accent { background: var(--gold); border-color: var(--gold-dark); color: var(--ink); }
.btn--danger { background: var(--loss); border-color: var(--loss); color: #fff; }
.btn--danger:hover { background: #962b24; color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; color: inherit; }
.btn--ghost:hover { background: rgb(255 255 255 / 16%); color: inherit; }
.card .btn--ghost:hover, .pager .btn--ghost:hover { background: var(--sand); }
.btn--icon { padding: .45rem; min-width: 42px; }
.btn--small { min-height: 32px; padding: .25rem .7rem; font-size: .85rem; }
.btn--large { min-height: 50px; font-size: 1.05rem; padding: .7rem 1.4rem; }
.btn--hero { min-height: 56px; font-size: 1.15rem; padding: .8rem 1.7rem; }
.btn--block { width: 100%; margin-top: 1rem; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }

.tag {
    display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .6rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
    background: var(--sand-deep); color: var(--ink-soft); white-space: nowrap;
}
.tag .icon { width: 14px; height: 14px; }
.tag--win { background: var(--win-soft); color: var(--win); }
.tag--loss { background: var(--loss-soft); color: var(--loss); }
.tag--draw { background: var(--sky-soft); color: var(--sky-dark); }
.tag--warning { background: var(--warn-soft); color: var(--warn); }
.tag--tuzdyk { background: var(--gold); color: var(--ink); }
.tag--status-registration, .tag--status-running { background: var(--win-soft); color: var(--win); }
.tag--status-draft, .tag--status-cancelled { background: var(--warn-soft); color: var(--warn); }
.tag-row { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0; }

.notice { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .7rem 1rem; border-radius: var(--radius); border: 1px solid transparent; }
.notice > h1, .notice > h2, .notice > p { flex-basis: 100%; margin-bottom: .2rem; }
.notice--info { background: var(--sky-soft); border-color: #b5dbe3; }
.notice--warning { background: var(--warn-soft); border-color: #ecd693; }
.notice--error { background: var(--loss-soft); border-color: #eab8b3; color: #6d1f1a; }
.notice--error .btn--ghost:hover { background: rgb(0 0 0 / 6%); }

.loading { display: flex; align-items: center; gap: .6rem; padding: 1rem 0; color: var(--ink-soft); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--sky); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.form { display: flex; flex-direction: column; gap: .85rem; }
.field { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; font-size: .92rem; }
.field-row { display: grid; gap: .85rem; }
.input { width: 100%; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; color: var(--ink); }
.input:focus { outline: 3px solid var(--sky-soft); border-color: var(--sky); }
.input--short { max-width: 7rem; text-transform: uppercase; }
.input.invalid { border-color: var(--loss); }
.toggle { display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--sky); }
.copy-row { display: flex; gap: .5rem; width: 100%; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; max-width: 100%; }
.segment { border: 0; background: transparent; padding: .5rem 1rem; font: inherit; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.segment.is-selected { background: var(--sky); color: #fff; }
.segment:disabled { cursor: not-allowed; opacity: .6; }

.chip-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: .5rem; }
.chip { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .55rem .4rem; border: 1px solid var(--line); border-radius: 12px; background: #fff; font: inherit; cursor: pointer; color: var(--ink); }
.chip strong { font-size: 1.1rem; }
.chip small { color: var(--ink-soft); font-size: .7rem; text-align: center; }
.chip.is-selected { border-color: var(--sky); background: var(--sky-soft); box-shadow: inset 0 0 0 1px var(--sky); }
.chip:disabled { opacity: .6; cursor: not-allowed; }

.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: transparent; padding: .6rem 1rem; font: inherit; font-weight: 600; color: var(--ink-soft); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tab.is-selected { color: var(--sky-dark); border-bottom-color: var(--sky); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .55rem .5rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.is-me, .match-row.is-me { background: var(--sky-soft); }

.pager { display: flex; align-items: center; justify-content: center; gap: .75rem; margin-top: .75rem; }
.pager-status { color: var(--ink-soft); font-size: .9rem; }

.plain-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; }
.facts, .stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin: .5rem 0 1rem; }
.facts dt, .stat-grid dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
.facts dd, .stat-grid dd { margin: 0; font-weight: 700; }
.stat-grid dd { font-size: 1.4rem; font-variant-numeric: tabular-nums; }

/* Players -------------------------------------------------------------------------------------------------------- */

.player-badge { display: inline-flex; align-items: center; gap: .45rem; text-decoration: none; color: var(--ink); font-weight: 600; min-width: 0; }
.player-badge:hover .player-name { text-decoration: underline; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-rating { color: var(--ink-soft); font-weight: 500; font-variant-numeric: tabular-nums; }
.player-country { font-size: .7rem; font-weight: 700; padding: .05rem .3rem; border-radius: 5px; background: var(--sand-deep); color: var(--ink-soft); }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; border: 0;
    font-weight: 700; font-size: .9rem; color: #fff; background: var(--sky); box-shadow: inset 0 -3px 6px rgb(0 0 0 / 22%), inset 0 2px 4px rgb(255 255 255 / 35%);
}
.avatar--large { width: 64px; height: 64px; font-size: 1.6rem; }
.avatar--empty { background: var(--sand-deep); color: var(--ink-soft); }
.avatar--stone-1 { background: #0f6e84; }
.avatar--stone-2 { background: #b3372f; }
.avatar--stone-3 { background: #1d7a46; }
.avatar--stone-4 { background: #c99700; }
.avatar--stone-5 { background: #6b4226; }
.avatar--stone-6 { background: #5b4b9a; }
.avatar--stone-7 { background: #2f4858; }
.avatar--stone-8 { background: #c2571a; }
.avatar-picker { display: flex; flex-wrap: wrap; gap: .5rem; }
.avatar--pick { width: 44px; height: 44px; cursor: pointer; font-size: 1.1rem; }
.avatar--pick.is-selected { outline: 3px solid var(--gold); outline-offset: 2px; }
.player-stats-head { display: flex; align-items: center; gap: .9rem; }
.player-stats-head h2 { margin: 0; }
.player-admin-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.confirm-text { font-weight: 600; color: var(--loss); }

/* Home ----------------------------------------------------------------------------------------------------------- */

.hero {
    display: grid; gap: 1.2rem; align-items: center; padding: clamp(1.2rem, 4vw, 2.4rem); border-radius: 22px; color: #fff;
    background: linear-gradient(135deg, var(--sky-dark), var(--sky) 60%, #1790a8);
    box-shadow: var(--shadow);
}
.hero p { font-size: 1.05rem; color: #e1f3f6; max-width: 46ch; }
.hero .btn { border-color: transparent; }
.hero .btn--primary { background: var(--gold); color: var(--ink); }
.hero .btn--primary:hover { background: #ffd23d; color: var(--ink); }
.hero-board { display: none; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 18px; border-radius: 20px; background: var(--wood); box-shadow: inset 0 0 0 4px var(--wood-dark); }
.hero-pit { aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 35% 30%, var(--stone-light), var(--stone-dark)); box-shadow: 0 3px 6px rgb(0 0 0 / 35%); }
.hero-pit:nth-child(5) { background: radial-gradient(circle at 35% 30%, #fff1b0, var(--gold-dark)); }

.leader-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.leader-list li { display: flex; align-items: center; gap: .6rem; }
.leader-rank { width: 1.7rem; height: 1.7rem; border-radius: 50%; display: grid; place-items: center; background: var(--sand-deep); font-weight: 700; font-size: .8rem; flex: none; }
.leader-list li:first-child .leader-rank { background: var(--gold); }
.leader-rating { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

.game-list { list-style: none; margin: 0; padding: 0; }
.game-row + .game-row { border-top: 1px solid var(--line); }
.game-row-link { display: flex; flex-direction: column; gap: .3rem; padding: .6rem .2rem; text-decoration: none; color: var(--ink); }
.game-row-link:hover { background: var(--sand); color: var(--ink); }
.game-row-players { display: flex; align-items: center; gap: .6rem; font-weight: 600; flex-wrap: wrap; }
.game-row-score { font-variant-numeric: tabular-nums; padding: .05rem .5rem; border-radius: 8px; background: var(--sand-deep); }
.game-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; font-size: .85rem; }
.is-winner { color: var(--win); }
.rating-change { font-weight: 700; font-variant-numeric: tabular-nums; }
.rating-change.is-up { color: var(--win); }
.rating-change.is-down { color: var(--loss); }

.searching { display: flex; align-items: center; gap: .7rem; margin-top: 1rem; padding: .7rem 1rem; border-radius: var(--radius); background: var(--sky-soft); font-weight: 600; }
.searching .btn { margin-left: auto; }
.invite-card { display: flex; flex-direction: column; align-items: flex-start; gap: .5rem; }

/* Tournaments ---------------------------------------------------------------------------------------------------- */

.tournament-card { display: block; text-decoration: none; color: var(--ink); transition: transform .1s, box-shadow .1s; }
.tournament-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgb(60 40 20 / 16%); color: var(--ink); }
.round + .round { margin-top: 1.2rem; }
.round-header { display: flex; align-items: center; gap: .6rem; }
.round-header h3 { margin: 0; color: var(--ink); }
.match-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.match-row { display: grid; grid-template-columns: 2rem 1fr; gap: .3rem .6rem; align-items: center; padding: .55rem .4rem; border-top: 1px solid var(--line); }
.match-board { font-weight: 700; color: var(--ink-soft); text-align: center; }
.match-players { display: flex; flex-wrap: wrap; gap: .4rem; font-weight: 600; }
.match-result, .match-actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.workflow { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; padding: 0; counter-reset: step; }
.workflow li { counter-increment: step; padding: .25rem .75rem; border-radius: 999px; background: var(--sand-deep); color: var(--ink-soft); font-size: .85rem; font-weight: 600; }
.workflow li::before { content: counter(step) ". "; }
.workflow li.is-done { background: var(--win-soft); color: var(--win); }
.workflow li.is-current { background: var(--sky); color: #fff; }

/* Game ----------------------------------------------------------------------------------------------------------- */

.game-layout { display: grid; gap: 1rem; }
.game-layout:focus { outline: none; }
.game-main { display: flex; flex-direction: column; gap: .6rem; min-width: 0; }
.game-side { display: flex; flex-direction: column; gap: .8rem; min-width: 0; }
.game-info { display: flex; flex-wrap: wrap; gap: .35rem; }

.player-area { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .45rem .7rem; border-radius: var(--radius); background: var(--paper); border: 2px solid var(--line); }
.player-area.is-to-move { border-color: var(--gold-dark); background: #fff7dc; }
.player-area-main { display: flex; align-items: center; gap: .45rem; min-width: 0; flex-wrap: wrap; }
.player-area-side { display: flex; align-items: center; gap: .6rem; flex: none; }
.turn-indicator { font-size: .78rem; font-weight: 700; color: var(--gold-dark); text-transform: uppercase; letter-spacing: .04em; }
.presence { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.presence--online { background: #2db567; box-shadow: 0 0 0 3px rgb(45 181 103 / 25%); }
.presence--offline { background: #b9ab97; }

.clock { display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .7rem; border-radius: 10px; background: var(--sand-deep); color: var(--ink-soft); font-weight: 700; font-size: 1.2rem; font-variant-numeric: tabular-nums; min-width: 5.6rem; justify-content: center; }
.clock.is-running { background: var(--ink); color: #fff; }
.clock.is-running.is-low { background: var(--loss); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .75; } }

.board {
    position: relative; display: flex; flex-direction: column; gap: clamp(6px, 1.4vw, 12px); padding: clamp(8px, 1.8vw, 18px);
    border-radius: clamp(12px, 2vw, 22px); background: linear-gradient(160deg, var(--wood-light), var(--wood) 45%, var(--wood-dark));
    box-shadow: inset 0 0 0 3px rgb(0 0 0 / 22%), 0 8px 22px rgb(60 30 10 / 30%); user-select: none;
}
.board-defs { position: absolute; }
.board--finished { filter: saturate(.75); }
.pit-row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: clamp(3px, .9vw, 10px); }

.pit {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px; min-width: 0;
    height: clamp(104px, 22vw, 190px); padding: 4px 2px; border: 2px solid transparent; border-radius: clamp(10px, 2vw, 22px);
    background: radial-gradient(ellipse at 50% 35%, #52321c, var(--pit)); box-shadow: inset 0 4px 10px rgb(0 0 0 / 55%);
    color: var(--stone-light); font: inherit; cursor: default; transition: border-color .15s, box-shadow .15s, transform .1s;
}
.pit--top { flex-direction: column-reverse; }
.pit:disabled { opacity: 1; }
.pit-number { font-size: clamp(.62rem, 1.5vw, .8rem); font-weight: 700; color: #cdb48c; }
.pit-count { font-size: clamp(.85rem, 2.3vw, 1.25rem); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.stones { flex: 1; width: 100%; min-height: 0; max-width: 58px; }
.pit--top .stones { transform: scaleY(-1); }

.pit--playable { cursor: pointer; border-color: rgb(254 197 12 / 55%); }
.pit--playable:hover { border-color: var(--gold); transform: translateY(-2px); box-shadow: inset 0 4px 10px rgb(0 0 0 / 55%), 0 0 0 3px rgb(254 197 12 / 35%); }
.pit--selected, .pit--selected:hover { border-color: #fff; box-shadow: inset 0 4px 10px rgb(0 0 0 / 55%), 0 0 0 4px var(--gold); transform: translateY(-3px); }
.pit--last-source { border-color: rgb(120 200 255 / 80%); border-style: dashed; }
.pit--last-target { border-color: #7fd4ff; box-shadow: inset 0 4px 10px rgb(0 0 0 / 55%), 0 0 12px rgb(127 212 255 / 60%); animation: landed .6s ease-out; }
@keyframes landed { from { transform: scale(1.07); } to { transform: scale(1); } }

.pit--tuzdyk { background: repeating-linear-gradient(135deg, #7a5a12 0 8px, #5d4410 8px 16px); border-color: var(--gold); }
.pit-tuzdyk { flex: 1; display: grid; place-items: center; writing-mode: vertical-rl; font-size: clamp(.6rem, 1.6vw, .85rem); font-weight: 800; letter-spacing: .08em; color: var(--gold); text-transform: uppercase; }

.kazans { display: flex; flex-direction: column; gap: clamp(4px, 1vw, 8px); }
.kazan { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr; align-items: center; gap: 0 .6rem; padding: .3rem .7rem; border-radius: 999px; background: radial-gradient(ellipse at 50% 30%, #52321c, var(--pit)); box-shadow: inset 0 4px 10px rgb(0 0 0 / 55%); color: var(--stone-light); border: 2px solid transparent; }
.kazan-label { grid-column: 1; font-size: clamp(.62rem, 1.5vw, .78rem); color: #cdb48c; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kazan-stones { grid-column: 1; width: 100%; height: clamp(14px, 3vw, 24px); }
.kazan-count { grid-column: 2; grid-row: 1 / span 2; font-size: clamp(1.3rem, 4vw, 2rem); font-weight: 800; font-variant-numeric: tabular-nums; min-width: 2.2ch; text-align: right; }
.kazan--gained { border-color: var(--gold); animation: gained .8s ease-out; }
@keyframes gained { from { box-shadow: inset 0 4px 10px rgb(0 0 0 / 55%), 0 0 0 6px rgb(254 197 12 / 60%); } to { box-shadow: inset 0 4px 10px rgb(0 0 0 / 55%), 0 0 0 0 rgb(254 197 12 / 0%); } }

.action-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.action-bar .toggle { margin-left: auto; font-size: .9rem; color: var(--ink-soft); }

.result-card { text-align: center; border-width: 2px; }
.result-card h2 { justify-content: center; font-size: 1.6rem; }
.result-card .button-row { justify-content: center; }
.result-card--win { background: var(--win-soft); border-color: var(--win); }
.result-card--loss { background: var(--loss-soft); border-color: var(--loss); }
.result-card--draw { background: var(--sky-soft); border-color: var(--sky); }
.result-score { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.move-history { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.move-history-header { display: flex; align-items: center; justify-content: space-between; }
.move-history-header h2 { margin: 0 0 .4rem; }
.hint { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--sand-deep); color: var(--ink-soft); font-weight: 700; font-size: .8rem; cursor: help; }
.move-list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; font-variant-numeric: tabular-nums; }
.move-row { display: grid; grid-template-columns: 2.4rem 1fr 1fr; gap: .3rem; padding: .12rem 0; align-items: center; }
.move-index { color: var(--ink-soft); font-size: .85rem; }
.move-cell { display: inline-flex; align-items: baseline; gap: .3rem; padding: .15rem .45rem; border-radius: 7px; border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--ink); text-align: left; }
button.move-cell { cursor: pointer; }
button.move-cell:hover { background: var(--sand-deep); }
.move-cell small { color: var(--win); font-weight: 700; }
.move-cell.is-tuzdyk { color: var(--gold-dark); }
.move-cell.is-current { background: var(--sky); color: #fff; }
.move-cell.is-current small { color: #d6ffe6; }

.replay-player { display: flex; align-items: center; gap: .5rem; }
.replay-controls { display: flex; align-items: center; justify-content: center; gap: .5rem; }
.replay-position { min-width: 8rem; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.replay-slider { width: 100%; accent-color: var(--sky); }
.replay-details p { margin-bottom: .4rem; }

.prose h2 { margin-top: 1.2rem; }
.terms { display: grid; gap: .6rem; margin: 0; }
.terms dt { font-weight: 800; color: var(--sky-dark); }
.terms dd { margin: 0; }

#blazor-error-ui { display: none; position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom)); z-index: 100; padding: .7rem 1.2rem; background: var(--warn-soft); border-top: 1px solid #ecd693; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

.hide-on-mobile { display: none; }

/* Portrait phones: the board turns so the rows run top to bottom and pits become wide instead of tall. */
@media (orientation: portrait) and (max-width: 540px) {
    .board { flex-direction: row; align-items: stretch; }
    .pit-row { grid-template-columns: 1fr; grid-template-rows: repeat(9, minmax(0, 1fr)); flex: 1; }
    .pit-row--top { order: 3; }
    .pit-row--top .pit:nth-child(n) { order: 0; }
    .kazans { order: 2; flex-direction: row; flex: none; width: clamp(64px, 20vw, 86px); }
    .pit-row--bottom { order: 1; }
    .pit, .pit--top { flex-direction: row; height: clamp(40px, 7.2vh, 58px); padding: 2px 8px; justify-content: space-between; }
    .pit--top { flex-direction: row-reverse; }
    .stones { transform: rotate(-90deg) scaleX(-1); max-width: none; width: 46px; height: 100%; flex: none; }
    .pit--top .stones { transform: rotate(90deg) scaleX(-1); }
    .pit-tuzdyk { writing-mode: horizontal-tb; }
    .kazan { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; border-radius: 18px; padding: .5rem .2rem; flex: 1; justify-items: center; }
    .kazan-label { writing-mode: vertical-rl; max-height: 9rem; }
    .kazan-stones { display: none; }
    .kazan-count { grid-column: 1; grid-row: 3; text-align: center; }
}

@media (min-width: 720px) {
    .grid--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .field-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .hero { grid-template-columns: 1.6fr 1fr; }
    .hero-board { display: grid; width: 100%; max-width: 260px; justify-self: end; }
    .hide-on-mobile { display: revert; }
    .plain-list--columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .match-row { grid-template-columns: 2rem 2fr 1.2fr auto; }
    .match-result, .match-actions { grid-column: auto; }
    .game-row-link { flex-direction: row; align-items: center; justify-content: space-between; }
}

@media (min-width: 980px) {
    .app-shell { padding-bottom: 0; }
    .topnav { display: flex; }
    .tabbar { display: none; }
    #blazor-error-ui { bottom: 0; }
    .game-layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
    .move-list { max-height: 460px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
