:root {
    color-scheme: light;
    --bg: #f6f7f4;
    --surface: #ffffff;
    --surface-soft: #eef3ef;
    --text: #1f2a24;
    --muted: #68736d;
    --line: #dce3de;
    --primary: #256f5a;
    --primary-dark: #174d3e;
    --accent: #d66b3d;
    --danger: #a83333;
    --good: #e8f5ee;
    --warn: #fff2df;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
}

a {
    color: inherit;
}

h1, h2, h3, p {
    margin-top: 0;
}

h1 {
    font-size: 1.65rem;
    line-height: 1.1;
}

h2 {
    font-size: 1.15rem;
}

h3 {
    font-size: 1rem;
    margin-bottom: .35rem;
}

input, select, textarea, button {
    font: inherit;
}

input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 48px;
    padding: .78rem .85rem;
    background: #fff;
    color: var(--text);
}

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

label {
    display: grid;
    gap: .35rem;
    color: var(--muted);
    font-size: .9rem;
}

label input,
label select,
label textarea {
    color: var(--text);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    gap: .75rem;
    padding: .8rem 1rem .65rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
}

.topbar-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.brand {
    font-weight: 800;
    text-decoration: none;
    line-height: 1.1;
}

.app-nav {
    display: flex;
    gap: .5rem;
    margin-inline: -1rem;
    padding: 0 1rem .15rem;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.app-nav::-webkit-scrollbar {
    display: none;
}

.app-nav a {
    flex: 0 0 auto;
    min-height: 40px;
    padding: .58rem .8rem;
    border-radius: 6px;
    background: var(--surface-soft);
    text-decoration: none;
    color: var(--text);
}

.app-nav a:hover {
    background: #dde8e0;
}

.page {
    width: min(1180px, calc(100% - 1rem));
    margin: .75rem auto 2rem;
}

.guest-body {
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-shell {
    width: min(440px, 100%);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 10px 24px rgba(31, 42, 36, .06);
}

.auth-panel {
    padding: 1.5rem;
}

.dashboard-head {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

.page-head {
    margin-bottom: 1rem;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .6rem;
}

.stat {
    display: grid;
    gap: .15rem;
    min-height: 92px;
    padding: .85rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.stat span,
.stat small {
    color: var(--muted);
}

.stat strong {
    font-size: 1.55rem;
    line-height: 1;
    overflow-wrap: anywhere;
}

.stat.good {
    background: var(--good);
}

.stat.warn {
    background: var(--warn);
}

.summary-grid .stat:last-child {
    grid-column: 1 / -1;
}

.grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

.grid.two {
    grid-template-columns: 1fr;
}

.stack {
    display: grid;
    gap: .85rem;
}

.compact {
    gap: .65rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: .75rem;
}

.inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: .5rem;
    align-items: stretch;
}

.inline-form input {
    width: 100%;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: .75rem 1rem;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
}

.button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.button.primary:hover {
    background: var(--primary-dark);
}

.button.danger {
    border-color: var(--danger);
    background: var(--danger);
    color: #fff;
}

.stack .button,
.panel > form .button {
    width: 100%;
}

.link-button {
    border: 0;
    background: transparent;
    color: var(--muted);
    min-height: 40px;
    padding: .45rem 0 .45rem .5rem;
    white-space: nowrap;
}

.notice {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .75rem .9rem;
    background: var(--surface);
}

.notice.success {
    border-color: #add8be;
    background: #effaf3;
}

.notice.error {
    border-color: #e1b2b2;
    background: #fff0f0;
}

.list {
    display: grid;
    gap: .45rem;
    margin-top: 1rem;
}

.list p {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    justify-content: space-between;
    gap: 1rem;
    margin: 0;
    padding: .65rem 0;
    border-top: 1px solid var(--line);
}

.list strong,
.list span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.list span,
.muted,
.fineprint {
    color: var(--muted);
}

.table-wrap {
    width: 100%;
    overflow: visible;
}

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

thead {
    display: none;
}

tbody,
tr,
td {
    display: block;
}

tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-bottom: .75rem;
    padding: .25rem .75rem;
    background: #fff;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: .65rem 0;
    text-align: right;
    white-space: normal;
}

td {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
    text-align: left;
}

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

th {
    color: var(--muted);
    font-size: .85rem;
    font-weight: 700;
}

.fineprint {
    margin-top: .85rem;
    font-size: .82rem;
}

.timer {
    font-size: clamp(2.4rem, 16vw, 4.2rem);
    font-weight: 800;
    line-height: 1;
    margin-bottom: .75rem;
}

canvas {
    display: block;
    width: 100%;
    height: 210px;
    max-height: 210px;
    margin-top: 1rem;
}

@media (min-width: 640px) {
    h1 {
        font-size: 2rem;
    }

    .page {
        width: min(1180px, calc(100% - 2rem));
        margin-top: 1.25rem;
    }

    .panel {
        padding: 1.25rem;
    }

    .summary-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: .75rem;
    }

    .summary-grid .stat:last-child {
        grid-column: auto;
    }

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

@media (min-width: 860px) {
    .topbar {
        display: flex;
        align-items: center;
        gap: 1.25rem;
        padding: .9rem clamp(1rem, 4vw, 2rem);
    }

    .topbar-main {
        display: contents;
    }

    .brand {
        white-space: nowrap;
    }

    .app-nav {
        flex: 1;
        margin: 0;
        padding: 0;
        overflow: visible;
    }

    .app-nav a {
        background: transparent;
        color: var(--muted);
        padding: .45rem .65rem;
    }

    .app-nav a:hover {
        background: var(--surface-soft);
        color: var(--text);
    }

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

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

    .stack .button,
    .panel > form .button {
        width: auto;
    }

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

    table {
        display: table;
    }

    thead {
        display: table-header-group;
    }

    tbody {
        display: table-row-group;
    }

    tr {
        display: table-row;
        border: 0;
        border-radius: 0;
        margin: 0;
        padding: 0;
        background: transparent;
    }

    td,
    th {
        display: table-cell;
        padding: .7rem .5rem;
        text-align: left;
        white-space: nowrap;
    }

    td::before {
        content: none;
    }

    td:last-child {
        border-bottom: 1px solid var(--line);
    }

    canvas {
        height: 220px;
        max-height: 220px;
    }
}
