:root {
    --bg: #f6f7f2;
    --panel: #ffffff;
    --panel-soft: #eef5f2;
    --ink: #17211d;
    --muted: #69746f;
    --line: #dde5df;
    --brand: #16735b;
    --brand-dark: #0e5744;
    --accent: #d67b32;
    --danger: #c94444;
    --warning: #c28b18;
    --ok: #2e8b57;
    --shadow: 0 18px 45px rgba(30, 45, 38, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

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

.app-shell {
    display: grid;
    grid-template-columns: 258px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: #10251f;
    color: #f8fbf6;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #f0b35a;
    color: #10251f;
    font-weight: 800;
}

.brand-title {
    font-weight: 800;
    line-height: 1.2;
}

.brand-subtitle {
    color: rgba(255, 255, 255, 0.62);
    font-size: 12px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 18px;
    flex: 1;
}

.nav .nav-bottom-start {
    margin-top: auto;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.78);
}

.nav a.active,
.nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

.nav a.nav-bottom-start {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    font-weight: 800;
}

.nav a.nav-logout {
    justify-content: center;
    margin-top: 10px;
    background: #ef4444;
    color: #fff;
    font-weight: 800;
}

.nav a.nav-logout:hover {
    background: #dc2626;
}

.nav-note {
    margin-left: auto;
    color: rgba(255, 255, 255, 0.58);
    font-size: 13px;
    font-weight: 400;
}

.nav-icon {
    width: 21px;
    text-align: center;
}

.main {
    min-width: 0;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 20px;
}

.page-title {
    margin: 0;
    font-size: 26px;
    line-height: 1.2;
}

.page-note {
    margin: 4px 0 0;
    color: var(--muted);
}

.user-menu {
    display: flex;
    gap: 10px;
    align-items: center;
    white-space: nowrap;
}

.grid {
    display: grid;
    gap: 16px;
}

.grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel,
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 18px;
}

.stat {
    padding: 18px;
}

.stat .num {
    font-size: 30px;
    font-weight: 800;
    line-height: 1;
}

.stat .label {
    color: var(--muted);
    margin-top: 6px;
}

.toolbar {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.section-title {
    margin: 0 0 12px;
    font-size: 18px;
}

.btn,
button {
    border: 0;
    border-radius: 8px;
    min-height: 38px;
    padding: 9px 13px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.btn:hover,
button:hover {
    background: var(--brand-dark);
}

.btn.secondary {
    background: #e7eee9;
    color: var(--ink);
}

.btn.secondary:hover {
    background: #d7e2dc;
}

.btn.danger {
    background: var(--danger);
}

.btn.small {
    min-height: 30px;
    padding: 6px 9px;
    font-size: 13px;
}

form.inline {
    display: inline;
}

label {
    font-weight: 700;
    display: block;
    margin-bottom: 6px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 10px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

textarea {
    min-height: 88px;
    resize: vertical;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid .span-2 {
    grid-column: 1 / -1;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 10px 11px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
    background: #f8faf8;
}

tr:last-child td {
    border-bottom: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--panel-soft);
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 12px;
}

.badge.warn {
    background: #fff4d8;
    color: #85620c;
}

.badge.danger {
    background: #ffe6e6;
    color: #9a2b2b;
}

.badge.ok {
    background: #e1f3e9;
    color: #1f6c42;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: inline-grid;
    place-items: center;
    background: #ddeee7;
    color: var(--brand-dark);
    font-weight: 800;
    margin-right: 8px;
}

.student-cell {
    display: flex;
    align-items: center;
}

.muted {
    color: var(--muted);
}

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid var(--line);
    background: #fff;
}

.flash.success {
    border-color: #b7dfc8;
    background: #ecf8f1;
}

.flash.error {
    border-color: #f0b8b8;
    background: #fff0f0;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 22px;
    background: linear-gradient(135deg, #10251f 0%, #22624f 55%, #e0a04a 100%);
}

.login-box {
    width: min(420px, 100%);
    padding: 24px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
}

.login-box h1 {
    margin: 0 0 8px;
    font-size: 24px;
}

.empty {
    padding: 24px;
    text-align: center;
    color: var(--muted);
    background: #fafcfb;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.print-only {
    display: none;
}

.settings-tabs {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid #bfd8ff;
    border-radius: 8px;
    background: #edf5ff;
}

.settings-tabs a {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border-radius: 8px;
    color: #123a74;
    font-weight: 800;
}

.settings-tabs a:hover {
    background: #dcecff;
}

.settings-card {
    min-height: 260px;
}

.games-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    padding: 22px;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, #15372e, #16735b 58%, #d67b32);
    box-shadow: var(--shadow);
}

.games-hero h2 {
    margin: 0 0 4px;
    font-size: 24px;
}

.games-hero p {
    margin: 0;
    color: rgba(255, 255, 255, 0.82);
}

.hero-count {
    min-width: 88px;
    min-height: 58px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.16);
    font-size: 22px;
    font-weight: 800;
}

.game-panel {
    min-height: 280px;
}

.wheel {
    width: min(280px, 78vw);
    aspect-ratio: 1;
    margin: 8px auto 14px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    position: relative;
    background: conic-gradient(#16735b 0 45deg, #f0b35a 45deg 90deg, #386b9f 90deg 135deg, #e2695f 135deg 180deg, #16735b 180deg 225deg, #f0b35a 225deg 270deg, #386b9f 270deg 315deg, #e2695f 315deg 360deg);
    border: 10px solid #fff;
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08), 0 14px 35px rgba(0, 0, 0, 0.12);
    transition: transform 1.4s cubic-bezier(.16, .84, .22, 1);
}

.wheel-pointer {
    position: absolute;
    top: -18px;
    width: 0;
    height: 0;
    border-left: 16px solid transparent;
    border-right: 16px solid transparent;
    border-top: 28px solid var(--ink);
    z-index: 2;
}

.wheel-inner {
    width: 48%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 12px;
    border-radius: 50%;
    background: #fff;
    color: var(--ink);
    font-weight: 800;
}

.game-result,
.challenge-box {
    min-height: 54px;
    padding: 12px;
    border-radius: 8px;
    background: #f8faf8;
    border: 1px solid var(--line);
    font-weight: 700;
}

.lucky-number {
    width: min(210px, 68vw);
    aspect-ratio: 1;
    margin: 12px auto;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #10251f;
    color: #f0b35a;
    font-size: 76px;
    font-weight: 900;
}

.mini-form {
    display: flex;
    align-items: end;
    gap: 8px;
}

.mini-form label {
    font-size: 12px;
    margin: 0 0 4px;
    color: var(--muted);
}

.mini-form input {
    width: 76px;
}

.team-board,
.pair-board {
    display: grid;
    gap: 10px;
}

.team {
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fbfcfb;
}

.team strong {
    display: block;
    margin-bottom: 4px;
}

.secret-cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.secret-card {
    min-height: 86px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #15372e;
    color: #fff;
    font-weight: 800;
}

.secret-card.open {
    background: #fff8ec;
    color: var(--ink);
}

.remark-text {
    min-width: 320px;
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .nav .nav-bottom-start,
    .nav a.nav-logout {
        margin-top: 0;
    }

    .nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid.cols-3,
    .grid.cols-4,
    .grid.cols-2,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .games-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .secret-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media print {
    .sidebar,
    .topbar,
    .toolbar,
    .no-print,
    .flash {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    body {
        background: #fff;
    }

    .main {
        padding: 0;
    }

    .panel,
    .card {
        box-shadow: none;
        border: 0;
    }

    .print-only {
        display: block;
    }
}
