:root {
    --ink: #f4f4f5; --muted: #a1a1aa; --paper: #09090b; --paper-top: #18181b;
    --surface: #18181b; --surface-soft: rgba(24, 24, 27, 0.92); --input: #0f0f11;
    --green: #52525b; --green-light: #fafafa; --gold: #ffffff; --red: #ef5350;
    --line: rgba(255, 255, 255, 0.15); --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
    --header: rgba(5, 5, 6, 0.96); --team-bg: #242427; --card-text: #ffffff;
    --on-accent: #ffffff; --decoration: rgba(255, 255, 255, 0.10); --glow: rgba(255, 255, 255, 0.055);
    --radius: 22px;
}

[data-theme="graphite"] {
    --paper: #111318; --paper-top: #20242c; --surface: #20242a; --surface-soft: rgba(32, 36, 42, 0.94);
    --input: #12151a; --green: #64748b; --green-light: #dbeafe; --gold: #cbd5e1; --header: rgba(10, 12, 16, 0.96);
    --team-bg: #2c3440; --decoration: rgba(203, 213, 225, 0.13); --glow: rgba(100, 116, 139, 0.18);
}

[data-theme="midnight"] {
    --paper: #07111f; --paper-top: #0d2038; --surface: #10243d; --surface-soft: rgba(16, 36, 61, 0.94);
    --input: #071626; --green: #2563eb; --green-light: #67e8f9; --gold: #93c5fd; --header: rgba(4, 12, 24, 0.96);
    --team-bg: #12345c; --decoration: rgba(103, 232, 249, 0.14); --glow: rgba(37, 99, 235, 0.22);
}

[data-theme="emerald"] {
    --paper: #04150f; --paper-top: #0b291e; --surface: #0d2b21; --surface-soft: rgba(13, 43, 33, 0.94);
    --input: #061b14; --green: #07875f; --green-light: #6ee7b7; --gold: #a7f3d0; --header: rgba(2, 16, 11, 0.96);
    --team-bg: #0b4a37; --decoration: rgba(167, 243, 208, 0.14); --glow: rgba(7, 135, 95, 0.22);
}

[data-theme="ruby"] {
    --paper: #1a080b; --paper-top: #351016; --surface: #35151a; --surface-soft: rgba(53, 21, 26, 0.94);
    --input: #200a0f; --green: #b4233d; --green-light: #fda4af; --gold: #fecdd3; --header: rgba(22, 5, 9, 0.96);
    --team-bg: #5b1724; --decoration: rgba(254, 205, 211, 0.13); --glow: rgba(180, 35, 61, 0.23);
}

[data-theme="amber"] {
    --paper: #1b1206; --paper-top: #35230a; --surface: #382810; --surface-soft: rgba(56, 40, 16, 0.94);
    --input: #211606; --green: #b7791f; --green-light: #fcd34d; --gold: #fde68a; --header: rgba(24, 15, 3, 0.96);
    --team-bg: #5c3b0c; --decoration: rgba(253, 230, 138, 0.14); --glow: rgba(183, 121, 31, 0.24);
}

[data-theme="violet"] {
    --paper: #14091f; --paper-top: #28113e; --surface: #2b1740; --surface-soft: rgba(43, 23, 64, 0.94);
    --input: #190c26; --green: #7c3aed; --green-light: #d8b4fe; --gold: #e9d5ff; --header: rgba(16, 5, 27, 0.96);
    --team-bg: #4b2375; --decoration: rgba(233, 213, 255, 0.14); --glow: rgba(124, 58, 237, 0.24);
}

[data-theme="ocean"] {
    --paper: #04171a; --paper-top: #083036; --surface: #0b343a; --surface-soft: rgba(11, 52, 58, 0.94);
    --input: #051d21; --green: #0f7890; --green-light: #67e8f9; --gold: #a5f3fc; --header: rgba(2, 18, 21, 0.96);
    --team-bg: #0c5260; --decoration: rgba(165, 243, 252, 0.14); --glow: rgba(15, 120, 144, 0.24);
}

[data-theme="coffee"] {
    --paper: #1a110d; --paper-top: #302019; --surface: #35251e; --surface-soft: rgba(53, 37, 30, 0.94);
    --input: #211510; --green: #8b5a3c; --green-light: #e7c6a5; --gold: #f0d2b2; --header: rgba(22, 13, 10, 0.96);
    --team-bg: #583725; --decoration: rgba(240, 210, 178, 0.14); --glow: rgba(139, 90, 60, 0.23);
}

[data-theme="contrast"] {
    --ink: #ffffff; --muted: #d4d4d4; --paper: #000000; --paper-top: #000000; --surface: #0a0a0a;
    --surface-soft: #0a0a0a; --input: #000000; --green: #ffffff; --green-light: #ffffff; --gold: #ffff00;
    --line: rgba(255, 255, 255, 0.55); --header: #000000; --team-bg: #0a0a0a; --on-accent: #000000;
    --decoration: rgba(255, 255, 255, 0.18); --glow: rgba(255, 255, 255, 0.03);
}

[data-theme="paper"] {
    --ink: #1f2937; --muted: #626b77; --paper: #f5f1e8; --paper-top: #fffdf7;
    --surface: #ffffff; --surface-soft: rgba(255, 255, 255, 0.94); --input: #f2ede2;
    --green: #b45309; --green-light: #9a3412; --gold: #fbbf24; --red: #b42318;
    --line: rgba(31, 41, 55, 0.16); --shadow: 0 18px 46px rgba(91, 69, 38, 0.14);
    --header: rgba(25, 29, 36, 0.97); --header-control: #303641; --header-control-text: #ffffff;
    --team-bg: #8b4513; --card-text: #ffffff; --on-accent: #ffffff;
    --decoration: rgba(255, 255, 255, 0.13); --glow: rgba(180, 83, 9, 0.12);
}

[data-theme="ice"] {
    --ink: #10243b; --muted: #5a6d80; --paper: #edf7ff; --paper-top: #ffffff;
    --surface: #ffffff; --surface-soft: rgba(255, 255, 255, 0.94); --input: #e6f2fb;
    --green: #0369a1; --green-light: #075985; --gold: #7dd3fc; --red: #b4233d;
    --line: rgba(16, 36, 59, 0.15); --shadow: 0 18px 46px rgba(31, 91, 126, 0.14);
    --header: rgba(8, 31, 52, 0.97); --header-control: #123c5d; --header-control-text: #ffffff;
    --team-bg: #075985; --card-text: #ffffff; --on-accent: #ffffff;
    --decoration: rgba(255, 255, 255, 0.13); --glow: rgba(3, 105, 161, 0.13);
}

[data-theme="sage"] {
    --ink: #183126; --muted: #5b6d63; --paper: #edf5ed; --paper-top: #fbfefb;
    --surface: #ffffff; --surface-soft: rgba(255, 255, 255, 0.94); --input: #e4efe6;
    --green: #357a57; --green-light: #236444; --gold: #a7f3d0; --red: #a93232;
    --line: rgba(24, 49, 38, 0.16); --shadow: 0 18px 46px rgba(48, 92, 68, 0.14);
    --header: rgba(18, 43, 32, 0.97); --header-control: #285542; --header-control-text: #ffffff;
    --team-bg: #326b50; --card-text: #ffffff; --on-accent: #ffffff;
    --decoration: rgba(255, 255, 255, 0.14); --glow: rgba(53, 122, 87, 0.13);
}

[data-theme="sand"] {
    --ink: #38291f; --muted: #766457; --paper: #f7efe2; --paper-top: #fffaf2;
    --surface: #fffdf9; --surface-soft: rgba(255, 253, 249, 0.94); --input: #efe2d1;
    --green: #9a5b2b; --green-light: #7c441e; --gold: #fed7aa; --red: #a83d32;
    --line: rgba(56, 41, 31, 0.16); --shadow: 0 18px 46px rgba(111, 78, 48, 0.15);
    --header: rgba(48, 34, 25, 0.97); --header-control: #5a4030; --header-control-text: #ffffff;
    --team-bg: #86502c; --card-text: #ffffff; --on-accent: #ffffff;
    --decoration: rgba(255, 255, 255, 0.14); --glow: rgba(154, 91, 43, 0.13);
}

* { box-sizing: border-box; }

html {
    min-height: 100%;
    background: var(--paper);
    -webkit-text-size-adjust: 100%;
}

body {
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    color: var(--ink);
    background: radial-gradient(circle at 10% 5%, var(--glow), transparent 25rem), linear-gradient(180deg, var(--paper-top) 0%, var(--paper) 100%);
    font-family: ui-monospace, "SFMono-Regular", "Roboto Mono", Consolas, "Liberation Mono", monospace;
    line-height: 1.5;
    letter-spacing: 0.025em;
    text-transform: uppercase;
}

button, input { font: inherit; text-transform: uppercase; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
    flex-direction: column;
}

.app-header {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    min-height: 74px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: max(12px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 12px max(20px, env(safe-area-inset-left));
    color: #fff;
    background: var(--header);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-family: inherit;
    font-size: clamp(1.4rem, 4vw, 2rem);
    font-weight: 400;
    letter-spacing: -0.06em;
    line-height: 1;
    text-decoration: none;
}

.brand img {
    width: 46px;
    height: 46px;
    object-fit: contain;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}

.brand-name { display: flex; align-items: baseline; }
.brand strong { color: var(--gold); font-weight: 700; }

.header-tools {
    display: flex;
    align-items: center;
    gap: 9px;
}

.timer {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--header-control, var(--surface));
    font-variant-numeric: tabular-nums;
}

.timer[hidden] { display: none; }

.timer-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.timer-value { min-width: 5.2ch; color: #fff; font-size: 1.08rem; font-weight: 800; letter-spacing: 0.08em; }
.timer.is-ended .timer-value { color: #ffd0c8; }

.theme-picker { position: relative; }

.theme-toggle, .fullscreen-toggle {
    display: flex;
    min-width: 46px;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 7px 11px;
    color: var(--header-control-text, var(--ink));
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--header-control, var(--surface));
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 800;
}

.fullscreen-toggle {
    width: 46px;
    flex: 0 0 46px;
    padding: 7px;
}

.fullscreen-icon {
    width: 18px;
    height: 18px;
    background:
        linear-gradient(currentColor, currentColor) left top / 7px 2px no-repeat,
        linear-gradient(currentColor, currentColor) left top / 2px 7px no-repeat,
        linear-gradient(currentColor, currentColor) right top / 7px 2px no-repeat,
        linear-gradient(currentColor, currentColor) right top / 2px 7px no-repeat,
        linear-gradient(currentColor, currentColor) left bottom / 7px 2px no-repeat,
        linear-gradient(currentColor, currentColor) left bottom / 2px 7px no-repeat,
        linear-gradient(currentColor, currentColor) right bottom / 7px 2px no-repeat,
        linear-gradient(currentColor, currentColor) right bottom / 2px 7px no-repeat;
    transition: transform 160ms ease;
}

.fullscreen-toggle.is-active .fullscreen-icon { transform: scale(0.72); }

.theme-toggle-icon {
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-radius: 50%;
    background: linear-gradient(90deg, currentColor 50%, transparent 50%);
}

.theme-panel {
    position: absolute;
    z-index: 40;
    top: calc(100% + 12px);
    right: 0;
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100dvh - 88px);
    overflow-y: auto;
    padding: 18px;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.48);
}

.theme-panel::before {
    position: absolute;
    top: -7px;
    right: 15px;
    width: 12px;
    height: 12px;
    border-top: 1px solid var(--line);
    border-left: 1px solid var(--line);
    background: var(--surface);
    content: "";
    transform: rotate(45deg);
}

.theme-panel > strong { display: block; font-size: 1rem; }
.theme-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }

.theme-option {
    display: flex;
    min-width: 0;
    min-height: 47px;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    color: var(--option-color, var(--ink));
    border: 1px solid var(--line);
    border-color: color-mix(in srgb, var(--option-color, var(--ink)) 24%, transparent);
    border-radius: 9px;
    background: var(--option-background, var(--input));
    cursor: pointer;
    text-align: left;
}

.theme-option.is-selected {
    border-color: var(--option-accent, var(--green-light));
    box-shadow: inset 0 0 0 2px var(--option-accent, var(--green-light)), 0 0 0 1px var(--surface);
}

.theme-swatch {
    width: 27px;
    height: 27px;
    flex: 0 0 27px;
    border: 1px solid rgba(255, 255, 255, 0.32);
    border-radius: 7px;
    background: linear-gradient(135deg, var(--swatch-background) 0 54%, var(--swatch-accent) 55% 100%);
}

.theme-option-label { overflow: hidden; font-size: 0.67rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }

.app-main {
    width: min(1180px, 100%);
    flex: 1;
    margin: 0 auto;
    padding: clamp(28px, 6vw, 68px) clamp(16px, 4vw, 36px) 56px;
}

.intro { max-width: 720px; margin: 0 auto 36px; text-align: center; }

.how-open { display: none; }

.eyebrow {
    margin: 0 0 5px;
    color: var(--green-light);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1, h2 { font-family: inherit; line-height: 1.12; letter-spacing: -0.055em; }
h1 { margin-bottom: 12px; font-size: clamp(2.25rem, 7vw, 4.7rem); }
h2 { margin-bottom: 0; font-size: clamp(1.45rem, 4vw, 2.2rem); }

.intro > p:not(.eyebrow) {
    max-width: 590px;
    margin-right: auto;
    margin-bottom: 24px;
    margin-left: auto;
    color: var(--muted);
    font-size: 1.02rem;
}

.how-it-works {
    margin: 0 auto 20px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface-soft);
    box-shadow: var(--shadow);
    text-align: left;
}

.how-heading {
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.how-heading h2 {
    font-size: clamp(1.15rem, 3vw, 1.55rem);
    letter-spacing: -0.04em;
}

.how-steps {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.how-steps li {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    gap: 11px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--input);
}

.step-number {
    flex: 0 0 auto;
    color: var(--green-light);
    font-size: 0.72rem;
    font-weight: 800;
}

.how-steps strong {
    display: block;
    margin-bottom: 4px;
    font-size: 0.76rem;
}

.how-steps p {
    margin: 0;
    color: var(--muted);
    font-size: 0.67rem;
    line-height: 1.45;
}

.start-panel {
    position: relative;
    overflow: hidden;
    margin: 26px auto 0;
    padding: clamp(20px, 4vw, 30px);
    border: 1px solid var(--line);
    border-color: color-mix(in srgb, var(--green-light) 50%, transparent);
    border-radius: 22px;
    background: var(--surface-soft);
    background:
        linear-gradient(135deg, color-mix(in srgb, var(--green) 20%, transparent), transparent 55%),
        var(--surface-soft);
    box-shadow: var(--shadow);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35), inset 0 0 0 1px color-mix(in srgb, var(--green) 18%, transparent);
    text-align: left;
    isolation: isolate;
}

.start-panel::after {
    position: absolute;
    z-index: -1;
    top: -85px;
    right: -70px;
    width: 210px;
    height: 210px;
    border: 42px solid color-mix(in srgb, var(--green-light) 9%, transparent);
    border-radius: 50%;
    content: "";
}

.start-panel-heading {
    display: flex;
    align-items: center;
    gap: 13px;
}

.start-panel-heading h2 { font-size: clamp(1.45rem, 4vw, 2rem); }

.start-beacon {
    position: relative;
    width: 15px;
    height: 15px;
    flex: 0 0 15px;
    border: 3px solid var(--surface);
    border-radius: 50%;
    background: var(--green-light);
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--green-light) 16%, transparent), 0 0 24px var(--green-light);
    animation: start-pulse 2.4s ease-in-out infinite;
}

@keyframes start-pulse {
    0%, 100% { transform: scale(0.92); opacity: 0.72; }
    50% { transform: scale(1); opacity: 1; }
}

.start-panel-copy {
    margin: 12px 0 20px;
    color: var(--muted);
    font-size: 0.78rem;
}

.duration-setting {
    display: flex;
    width: min(390px, 100%);
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 16px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    text-align: left;
}

.start-panel .duration-setting { width: 100%; }

.duration-setting label {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 800;
}

.duration-input {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
}

.duration-input input {
    width: 72px;
    min-height: 42px;
    padding: 7px 8px;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--input);
    font-size: 1.1rem;
    font-weight: 800;
    text-align: center;
}

.duration-input span {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 800;
}

.mode-actions, .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.start-panel .mode-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.start-panel .mode-actions button {
    display: flex;
    min-height: 68px;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-radius: 13px;
    text-align: left;
}

.start-panel .mode-actions button::after {
    content: "→";
    font-size: 1.25rem;
}

.start-panel .mode-actions button small {
    margin-left: auto;
    color: currentColor;
    font-size: 0.6rem;
    opacity: 0.72;
}

.start-panel-note {
    margin: 15px 0 0;
    color: var(--green-light);
    font-size: 0.66rem;
    font-weight: 800;
    text-align: center;
}

.primary-button, .secondary-button, .close-round, .text-button {
    min-height: 48px;
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 800;
    transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.primary-button, .secondary-button { padding: 12px 22px; }

.primary-button, .close-round {
    color: var(--on-accent);
    background: var(--green);
    box-shadow: var(--shadow);
}

.secondary-button { color: var(--ink); border: 1px solid var(--line); background: var(--surface); }
button:active { transform: translateY(1px); }

button:focus-visible, input:focus-visible {
    outline: 3px solid var(--gold);
    outline-offset: 2px;
}

.restore-message, .form-message { border-radius: 14px; font-weight: 700; text-align: center; }

.restore-message {
    max-width: 560px;
    margin: -18px auto 28px;
    padding: 10px 14px;
    color: var(--ink);
    background: var(--surface);
}

.game-toolbar, .section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.game-toolbar { margin-bottom: 22px; }
.toolbar-actions { justify-content: flex-end; }

.table-context {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 800;
}

.text-button {
    min-height: 40px;
    padding: 8px 14px;
    color: var(--ink);
    border: 1px solid var(--line);
    background: transparent;
    font-size: 0.84rem;
}

.switch-tables.is-emphasized {
    color: var(--on-accent);
    border-color: var(--green-light);
    background: var(--green);
    box-shadow: 0 10px 28px var(--glow), inset 0 0 0 1px color-mix(in srgb, var(--green-light) 42%, transparent);
}

.switch-tables.is-emphasized::before {
    margin-right: 7px;
    content: "⇄";
    font-size: 1.05rem;
}

.danger-button {
    color: #ffb4b0;
    border-color: rgba(239, 83, 80, 0.48);
}

.table-switcher {
    width: min(1050px, 100%);
    margin: 0 auto;
}

.switcher-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.switcher-heading h1 { margin-bottom: 8px; }
.switcher-heading p:not(.eyebrow) { margin-bottom: 0; color: var(--muted); }

.switcher-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 24px;
}

.table-list,
.final-session-tables {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: 14px;
}

.table-summary {
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface-soft);
    box-shadow: var(--shadow);
}

.table-summary.is-active {
    border-color: var(--green-light);
    box-shadow: inset 0 0 0 1px var(--green-light), var(--shadow);
}

.table-summary-heading,
.summary-team,
.final-session-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.table-summary-heading h3 {
    overflow: hidden;
    margin: 0;
    font-size: 1.05rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-mode {
    flex: 0 0 auto;
    padding: 4px 7px;
    border-radius: 6px;
    color: var(--muted);
    background: var(--input);
    font-size: 0.65rem;
    font-weight: 800;
}

.table-summary-meta {
    margin: 7px 0 13px;
    color: var(--muted);
    font-size: 0.7rem;
}

.table-summary-teams {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.summary-team {
    min-height: 39px;
    padding: 8px 10px;
    background: var(--input);
}

.summary-team + .summary-team { border-top: 1px solid var(--line); }
.summary-team span { overflow: hidden; font-size: 0.75rem; text-overflow: ellipsis; white-space: nowrap; }
.summary-team strong { flex: 0 0 auto; font-size: 1rem; font-variant-numeric: tabular-nums; }

.table-leader {
    min-height: 20px;
    margin: 12px 0;
    color: var(--green-light);
    font-size: 0.7rem;
    font-weight: 800;
}

.open-table {
    width: 100%;
    min-height: 43px;
    padding: 9px 12px;
    color: var(--on-accent);
    border: 0;
    border-radius: 9px;
    background: var(--green);
    cursor: pointer;
    font-weight: 800;
}

.final-results-section {
    width: min(1050px, 100%);
    margin: 12px auto 36px;
    padding-top: 28px;
    border-top: 1px solid var(--line);
}

.final-results { display: grid; gap: 18px; margin-top: 20px; }

.final-session {
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    transition: border-color 150ms ease, transform 150ms ease;
}

.final-session-heading {
    width: 100%;
    align-items: baseline;
    margin-bottom: 14px;
    padding: 0;
    color: var(--ink);
    border: 0;
    background: transparent;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.final-session-heading strong { font-size: 0.86rem; }
.final-session-heading span { color: var(--muted); font-size: 0.68rem; text-align: right; }

.final-session .table-summary {
    box-shadow: none;
}

.archive-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.archive-action {
    display: grid;
    min-width: 42px;
    min-height: 42px;
    place-items: center;
    padding: 8px 12px;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--input);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 800;
}

.archive-actions .archive-open { margin-right: auto; }
.archive-replay { color: var(--green-light); font-size: 1.25rem; }
.archive-delete { color: #ffb4b0; border-color: rgba(239, 83, 80, 0.48); font-size: 1.25rem; }

.standings, .score-inputs {
    display: grid;
    grid-template-columns: repeat(var(--team-count, 2), minmax(0, 1fr));
    gap: clamp(10px, 2.5vw, 22px);
}

.team-total {
    position: relative;
    min-width: 0;
    overflow: hidden;
    padding: clamp(18px, 4vw, 30px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    color: var(--card-text);
    background: var(--team-bg);
    box-shadow: var(--shadow);
}

.team-total::after {
    position: absolute;
    right: -28px;
    bottom: -42px;
    width: 120px;
    height: 120px;
    border: 24px solid var(--decoration);
    border-radius: 50%;
    content: "";
}

.team-total.has-photo {
    background-position: center;
    background-size: cover;
}

.team-total.has-photo::after { display: none; }

.team-name {
    position: relative;
    z-index: 1;
    width: 100%;
    min-height: 42px;
    padding: 7px 0;
    color: var(--card-text);
    border: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 0;
    outline: 0;
    background: transparent;
    font-size: clamp(0.9rem, 2.4vw, 1.08rem);
    font-weight: 700;
}

.team-name::placeholder { color: rgba(255, 255, 255, 0.55); }

.total-number {
    position: relative;
    z-index: 1;
    display: block;
    max-width: 100%;
    margin-top: 8px;
    color: var(--card-text);
    font-family: inherit;
    font-size: clamp(3.5rem, 11vw, 7.5rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.06em;
    line-height: 0.95;
    white-space: nowrap;
}

.difference {
    display: flex;
    min-height: 24px;
    align-items: center;
    flex-direction: column;
    gap: 9px;
    margin: 18px 0 30px;
    color: var(--muted);
    font-weight: 700;
    text-align: center;
}

.ranking-title {
    color: var(--green-light);
    font-size: 0.72rem;
    letter-spacing: 0.14em;
}

.ranking-list {
    display: grid;
    width: min(390px, 100%);
    gap: 6px;
}

.ranking-row {
    display: grid;
    min-width: 0;
    grid-template-columns: 32px 30px minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
    text-align: left;
}

.ranking-trophy {
    font-size: 1.2rem;
    line-height: 1;
    text-align: center;
}

.ranking-trophy::before { content: "🏆"; }
.rank-2 .ranking-trophy { filter: grayscale(0.82) brightness(1.5); }
.rank-3 .ranking-trophy { filter: sepia(0.75) saturate(1.5) brightness(0.8); }
.ranking-position { color: var(--muted); font-size: 0.72rem; font-weight: 800; }
.ranking-name { overflow: hidden; font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }
.ranking-score { font-size: 0.9rem; font-variant-numeric: tabular-nums; }

.round-entry, .history-section {
    padding: clamp(18px, 4vw, 30px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
    box-shadow: var(--shadow);
}

.round-number {
    flex: 0 0 auto;
    padding: 6px 11px;
    border-radius: 999px;
    color: var(--ink);
    background: var(--input);
    font-size: 0.78rem;
    font-weight: 800;
}

.score-inputs { margin-top: 24px; }

.score-card {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: var(--input);
}

.score-card h3 {
    overflow: hidden;
    margin: 0 0 14px;
    font-size: 0.95rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.score-field { min-width: 0; }

.score-field label {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.score-field input {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 9px 10px;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--input);
    font-size: 1.18rem;
    font-weight: 800;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.sign-button {
    width: 100%;
    min-height: 42px;
    margin-top: 10px;
    color: var(--red);
    border: 1px solid rgba(178, 58, 53, 0.24);
    border-radius: 11px;
    background: rgba(178, 58, 53, 0.06);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 800;
}

.sign-button.is-negative { color: #fff; background: var(--red); }

.close-round {
    display: block;
    width: min(420px, 100%);
    margin: 24px auto 0;
    padding: 13px 24px;
}

.form-message {
    margin: 14px 0 0;
    padding: 9px 12px;
    color: var(--red);
    background: rgba(178, 58, 53, 0.08);
}

.history-section { margin-top: 24px; }
.history { display: grid; gap: 10px; margin-top: 20px; }

.history-row {
    display: grid;
    grid-template-columns: minmax(76px, 0.55fr) repeat(var(--team-count, 2), minmax(0, 1fr));
    align-items: stretch;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--input);
}

.history-label, .history-score {
    display: flex;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    padding: 12px;
}

.history-label { color: var(--muted); background: var(--surface); font-size: 0.78rem; font-weight: 800; }
.history-score { border-left: 1px solid var(--line); text-align: center; }
.history-score strong { overflow: hidden; font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }
.history-score span { font-size: 1.08rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.history-score small { color: var(--muted); font-size: 0.68rem; }

.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px max(20px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    color: rgba(255, 255, 255, 0.65);
    background: var(--header);
    font-size: 0.78rem;
}

.footer-links { display: flex; align-items: center; gap: 14px; }
.app-footer a { color: var(--gold); }

.footer-button {
    padding: 0;
    color: var(--gold);
    border: 0;
    border-bottom: 1px solid currentColor;
    background: transparent;
    cursor: pointer;
    font-size: inherit;
}
[hidden] { display: none !important; }

body.modal-open { overflow: hidden; }

.modal-backdrop {
    position: fixed;
    z-index: 100;
    inset: 0;
    display: grid;
    overflow-y: auto;
    place-items: center;
    padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    background: rgba(0, 0, 0, 0.76);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.app-modal {
    position: relative;
    width: min(500px, 100%);
    padding: clamp(22px, 5vw, 32px);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.62);
}

.app-modal h2 {
    padding-right: 28px;
    font-size: clamp(1.4rem, 5vw, 2rem);
}

.modal-message {
    margin: 14px 0 24px;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.65;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    padding: 0;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--input);
    cursor: pointer;
    font-size: 1.35rem;
    line-height: 1;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-actions button { min-width: 120px; }
.primary-button.is-danger { background: var(--red); }
.modal-alternate.is-danger-alternate { color: #ffb4b0; border-color: rgba(239, 83, 80, 0.48); }

.history-detail-modal { place-items: start center; }

.history-detail-dialog {
    position: relative;
    width: min(1050px, 100%);
    max-height: calc(100dvh - 36px);
    overflow-y: auto;
    padding: clamp(22px, 4vw, 34px);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--paper);
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.62);
}

.history-detail-dialog > h2 { padding-right: 44px; }
.history-detail-meta { margin: 10px 0 24px; color: var(--muted); font-size: 0.74rem; font-weight: 800; }
.history-detail-content { display: grid; gap: 22px; }

.archived-game-detail {
    min-width: 0;
    padding: clamp(16px, 3vw, 26px);
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface-soft);
}

.archived-game-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
}

.archived-game-heading h3 { margin: 0; font-size: 1.15rem; }
.readonly-team-name { display: block; }
.readonly-ranking { margin-bottom: 22px; }
.readonly-history-section { margin-top: 0; box-shadow: none; }
.readonly-history-section h3 { margin: 0; font-size: 1.05rem; }
.archive-empty { margin: 18px 0 0; color: var(--muted); font-size: 0.76rem; text-align: center; }

.how-modal-steps {
    grid-template-columns: 1fr;
    margin-top: 20px;
}

.visually-hidden {
    position: fixed !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    white-space: nowrap !important;
}

.photo-control { display: none; }

@media (min-width: 721px) {
    body.game-active .app-main { padding-top: clamp(16px, 3vw, 34px); }
}

@media (max-width: 1024px) {
    .photo-control {
        position: absolute;
        z-index: 4;
        top: 8px;
        display: grid;
        width: 32px;
        height: 32px;
        place-items: center;
        padding: 0;
        color: #fff;
        border: 1px solid rgba(255, 255, 255, 0.42);
        border-radius: 9px;
        background: rgba(0, 0, 0, 0.34);
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.24);
        backdrop-filter: blur(5px);
        -webkit-backdrop-filter: blur(5px);
        cursor: pointer;
    }

    .photo-take { right: 8px; }
    .photo-remove { left: 8px; font-size: 1.35rem; line-height: 1; }

    .camera-icon {
        position: relative;
        width: 17px;
        height: 12px;
        border: 2px solid currentColor;
        border-radius: 3px;
    }

    .camera-icon::before {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 5px;
        height: 5px;
        border: 1.5px solid currentColor;
        border-radius: 50%;
        content: "";
        transform: translate(-50%, -50%);
    }

    .camera-icon::after {
        position: absolute;
        top: -5px;
        left: 2px;
        width: 7px;
        height: 3px;
        border-radius: 2px 2px 0 0;
        background: currentColor;
        content: "";
    }

    .team-total.has-photo {
        background-position: center;
        background-size: cover;
    }

    .team-total.has-photo::after { display: none; }
    .team-total .team-name { padding-right: 32px; }
    .team-total.has-photo .team-name { padding-left: 32px; text-align: center; text-shadow: 0 1px 5px rgba(0, 0, 0, 0.9); }
    .team-total.has-photo .total-number { text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9); }
}

@media (hover: hover) {
    .primary-button:hover, .close-round:hover {
        background: var(--green);
        box-shadow: var(--shadow);
        filter: brightness(1.14);
        transform: translateY(-1px);
    }
    .primary-button.is-danger:hover { background: var(--red); }
    .secondary-button:hover, .text-button:hover { background: var(--surface); filter: brightness(1.16); }
    .switch-tables.is-emphasized:hover { background: var(--green); }
    .final-session:hover { border-color: var(--green-light); transform: translateY(-1px); }
    .archive-action:hover { filter: brightness(1.16); }
}

@media (max-width: 720px) {
    .app-header { min-height: 64px; gap: 8px; padding-right: 12px; padding-left: 12px; }
    .header-tools { gap: 5px; }
    .fullscreen-toggle, .theme-toggle { min-width: 40px; width: 40px; flex-basis: 40px; }
    .app-main { padding-top: 30px; }
    .how-it-works { display: none; }
    .how-open {
        display: flex;
        width: 100%;
        min-height: 66px;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        margin: 0 auto 20px;
        padding: 13px 16px;
        color: var(--ink);
        border: 1px solid var(--line);
        border-radius: 15px;
        background: var(--surface-soft);
        box-shadow: var(--shadow);
        cursor: pointer;
        font-weight: 800;
        text-align: left;
    }
    .how-open span:first-child { display: grid; gap: 2px; }
    .how-open small { color: var(--green-light); font-size: 0.62rem; letter-spacing: 0.1em; }
    .how-open span:last-child {
        display: grid;
        width: 34px;
        height: 34px;
        flex: 0 0 34px;
        place-items: center;
        border-radius: 50%;
        color: var(--on-accent);
        background: var(--green);
        font-size: 1.05rem;
    }
    .how-modal .app-modal { max-height: calc(100dvh - 24px); overflow-y: auto; }
    .game-toolbar { align-items: flex-start; flex-direction: column; }
    .toolbar-actions { width: 100%; justify-content: flex-start; }
    .switcher-heading { flex-direction: column; }
    .switcher-actions button { flex: 1 1 180px; }
    .standings { gap: 8px; }
    .team-total {
        display: flex;
        flex-direction: column;
        padding: 42px 12px 15px;
        border-radius: 17px;
    }
    .total-number { order: 1; margin-top: 0; font-size: clamp(2.7rem, 15vw, 5rem); }
    .team-total .team-name,
    .team-total.has-photo .team-name {
        order: 2;
        margin-top: 11px;
        padding: 7px 0;
        text-align: center;
    }
    .standings.has-team-photos .team-total {
        min-height: clamp(240px, 65vw, 330px);
        justify-content: space-between;
    }
    .standings.has-team-photos .team-total.has-photo { background-position: center 28%; }
    .score-inputs { grid-template-columns: 1fr; }
    .score-card {
        display: grid;
        grid-template-columns: minmax(76px, 0.7fr) minmax(0, 1.6fr) minmax(86px, 0.75fr);
        align-items: end;
        gap: 10px;
    }
    .score-card h3 { align-self: center; margin: 0; white-space: normal; }
    .sign-button { margin-top: 0; }
}

@media (max-width: 480px) {
    .brand { gap: 5px; font-size: 0.78rem; letter-spacing: -0.08em; }
    .brand img { width: 32px; height: 32px; }
    .brand-name > span { display: inline; }
    .timer-label { display: none; }
    .theme-toggle-label { display: none; }
    .timer { padding-right: 8px; padding-left: 8px; }
    .mode-actions { flex-direction: column; }
    .mode-actions button { width: 100%; }
    .start-panel {
        margin: 26px -8px 0;
        padding: 20px 16px 18px;
        border-color: color-mix(in srgb, var(--green-light) 72%, transparent);
        border-radius: 20px;
        box-shadow: 0 22px 60px rgba(0, 0, 0, 0.48), 0 0 30px var(--glow);
        box-shadow: 0 22px 60px rgba(0, 0, 0, 0.48), 0 0 30px var(--glow), inset 0 0 0 1px color-mix(in srgb, var(--green-light) 18%, transparent);
    }
    .start-panel-copy { margin-bottom: 17px; line-height: 1.55; }
    .start-panel .duration-setting { align-items: center; flex-direction: row; padding: 13px; }
    .start-panel .duration-setting label { max-width: 140px; color: var(--ink); }
    .start-panel .duration-input { width: auto; }
    .start-panel .duration-input input { width: 78px; flex: 0 0 78px; font-size: 1.35rem; }
    .start-panel .mode-actions { grid-template-columns: 1fr; }
    .start-panel .mode-actions button { min-height: 70px; padding: 14px 17px; }
    .start-panel .mode-actions button span { font-size: 0.95rem; }
    .how-steps { grid-template-columns: 1fr; }
    .duration-input { width: 100%; }
    .duration-input input { flex: 1; }
    .toolbar-actions button { flex: 1 1 calc(50% - 5px); }
    .toolbar-actions .switch-tables.is-emphasized { flex: 1 1 100%; min-height: 52px; }
    .final-session-heading { align-items: flex-start; flex-direction: column; }
    .final-session-heading span { text-align: left; }
    .archive-actions { display: grid; grid-template-columns: 1fr 46px 46px; }
    .archive-actions .archive-open {
        display: flex;
        min-height: 46px;
        align-items: center;
        justify-content: center;
        margin-right: 0;
        line-height: 1.1;
        text-align: center;
    }
    .history-detail-modal {
        padding: max(12px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }
    .history-detail-dialog {
        max-height: calc(100dvh - max(12px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
        padding: 20px 12px;
        border-radius: 16px;
    }
    .archived-game-detail { padding: 14px 8px; }
    .intro { margin-bottom: 28px; }
    .standings { margin-right: -8px; margin-left: -8px; }
    .team-name { font-size: 0.78rem; }
    .round-entry, .history-section { margin-right: -8px; margin-left: -8px; border-radius: 18px; }
    .score-card { grid-template-columns: 1fr; gap: 9px; }
    .score-card h3 { text-align: center; }
    .history-row { grid-template-columns: 62px repeat(var(--team-count, 2), minmax(0, 1fr)); }
    .history-label, .history-score { padding: 9px 5px; }
    .history-score small { display: none; }
    .app-footer { flex-direction: column; gap: 8px; }
    .footer-links { gap: 18px; }
    .modal-actions { flex-direction: column-reverse; }
    .modal-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; transition: none !important; }
}
