:root {
    --paper: #f3efe6;
    --paper-deep: #e7e1d4;
    --card: #fbf8f2;
    --ink: #1a1714;
    --ink-soft: #5e574e;
    --line: #ddd4c6;
    --green: #1e4636;
    --green-deep: #16362a;
    --brass: #8a5a2a;
    --danger: #8d2f2f;
    --warn-bg: #f8f1e6;
    --ok-bg: #e7f0eb;
    --danger-bg: #f8eceb;
    --serif: "Fraunces", "Iowan Old Style", Palatino, "Palatino Linotype", serif;
    --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", monospace;
    --shadow: 0 24px 50px rgba(48, 36, 18, 0.06);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
    font-weight: 400;
}

body::before {
    content: "";
    position: fixed;
    inset: 0 auto 0 0;
    width: 8px;
    background: var(--green);
    pointer-events: none;
}

h1, h2, h3 {
    font-family: var(--serif);
    font-weight: 560;
    letter-spacing: -0.03em;
}

h1 {
    margin: 0;
    font-size: clamp(2.7rem, 6vw, 4.7rem);
    line-height: 0.94;
}

.hero h1 {
    font-size: clamp(1.75rem, 2.6vw, 2.35rem);
    line-height: 1.12;
    letter-spacing: -0.02em;
}

h2 {
    margin: 0;
    font-size: 1.55rem;
    line-height: 1.15;
}

p {
    margin: 0;
}

a {
    color: inherit;
}

button, input, select {
    font: inherit;
    color: inherit;
}

::placeholder {
    color: #9a9186;
}

::selection {
    background: #d5e4db;
}

:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
}

.skip {
    position: absolute;
    left: 12px;
    top: -40px;
    background: white;
    padding: 8px 12px;
    z-index: 20;
}

.skip:focus {
    top: 12px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.wrap {
    width: min(920px, calc(100% - 48px));
    margin: 0 auto;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 28px 0 8px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--ink);
}

.brand-mark {
    width: 14px;
    height: 14px;
    background: var(--green);
    box-shadow: 5px 5px 0 var(--paper-deep);
    flex: 0 0 auto;
}

.brand-name {
    font-family: var(--serif);
    font-size: 1.45rem;
    letter-spacing: -0.03em;
    line-height: 1;
}

.kicker {
    margin: 0 0 12px;
    color: var(--green);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.lede {
    max-width: 42rem;
    color: var(--ink-soft);
    font-size: 1.12rem;
}

.hero {
    padding: 64px 0 28px;
}

.composer, .card, .notice, .empty {
    background: var(--card);
}

.composer, .card {
    border: 1px solid var(--ink);
    box-shadow: var(--shadow);
}

.composer {
    padding: 22px 22px 18px;
}

.card {
    padding: 20px;
    border-color: var(--line);
}

.stack {
    display: grid;
    gap: 16px;
}

.field {
    display: grid;
    gap: 6px;
}

.field label, .stat-label, .hint, .sub, .signed-in {
    color: var(--ink-soft);
}

.field label {
    font-size: 0.92rem;
}

.optional {
    color: #8d8478;
    font-weight: 400;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="url"],
select {
    width: 100%;
    height: 48px;
    border: 1px solid var(--line);
    background: white;
    padding: 0 12px;
    border-radius: 0;
}

.composer input[type="text"] {
    border: 0;
    border-bottom: 1px solid var(--ink);
    background: transparent;
    padding-left: 0;
    padding-right: 0;
}

.field.is-invalid input,
.field.is-invalid select {
    border-color: var(--danger);
}

.hint {
    margin: 0;
    font-size: 0.92rem;
}

.composer-actions, .form-actions, .result-actions, .action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
}

.composer-actions {
    margin-top: 8px;
}

.composer-actions .hint, .result .hint {
    flex: 1 1 220px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    text-decoration: none;
    cursor: pointer;
}

.btn:hover {
    background: var(--green);
    border-color: var(--green);
}

.btn-ghost {
    background: transparent;
    color: var(--ink);
}

.btn-ghost:hover {
    background: var(--ink);
    color: var(--paper);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.btn-small {
    min-height: 34px;
    padding: 0 10px;
    font-size: 0.92rem;
}

.btn[hidden] {
    display: none;
}

.text-link, .text-btn {
    color: inherit;
    text-underline-offset: 3px;
}

.text-btn {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    text-decoration: underline;
}

.notice {
    border: 1px solid var(--green);
    background: var(--ok-bg);
    padding: 12px 14px;
    margin: 0 0 18px;
}

.notice-error {
    border-color: var(--danger);
    background: var(--danger-bg);
}

.notice-warn {
    border-color: var(--brass);
    background: var(--warn-bg);
}

.notice a {
    color: inherit;
}

.error-list {
    margin: 0;
    padding-left: 18px;
}

.result {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--ink);
}

.result-url, .mono {
    font-family: var(--mono);
}

.result-url {
    margin: 0 0 14px;
    font-size: clamp(1.05rem, 2vw, 1.45rem);
    line-height: 1.35;
    word-break: break-all;
}

.points {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 22px;
    margin: 42px 0 0;
    padding: 22px 0 0;
    border-top: 1px solid var(--line);
}

.points strong {
    display: block;
    margin-bottom: 6px;
}

.points span, .colophon {
    color: var(--ink-soft);
}

.colophon {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px 24px;
    margin-top: 56px;
    padding: 22px 0 36px;
    border-top: 1px solid var(--line);
    font-size: 0.92rem;
}

.legal-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.legal-nav a,
.legal-note a,
.legal a {
    color: inherit;
}

.legal {
    max-width: 68ch;
    padding: 56px 0 8px;
}

.legal h1 {
    font-size: clamp(2.4rem, 5vw, 3.5rem);
    margin-bottom: 12px;
}

.legal h2 {
    margin: 32px 0 8px;
    font-size: 1.45rem;
}

.legal h3 {
    margin: 22px 0 6px;
    font-size: 1.12rem;
    letter-spacing: -0.02em;
}

.legal p,
.legal li {
    font-size: 1.02rem;
}

.legal p + p,
.legal ul,
.legal p + ul,
.legal ul + p,
.legal .updated {
    margin-top: 10px;
}

.legal ul {
    margin-bottom: 0;
    padding-left: 1.2rem;
}

.legal li + li {
    margin-top: 6px;
}

.legal .updated,
.legal-note {
    color: var(--ink-soft);
    margin-top: 14px;
}

.narrow {
    max-width: 460px;
    padding: 56px 0 24px;
}

.narrow .lede, .admin-lede {
    margin: 12px 0 22px;
}

.narrow-form {
    max-width: 680px;
}

.status-block,
.gate {
    padding: 72px 0 12px;
}

.gate {
    max-width: 34rem;
}

.gate-count {
    margin: 18px 0 0;
    font-family: var(--serif);
    font-size: clamp(4.5rem, 12vw, 7rem);
    line-height: 0.9;
    letter-spacing: -0.04em;
}

.gate-unit {
    margin: 8px 0 22px;
    color: var(--ink-soft);
}

.gate-go,
#gate-go {
    margin-top: 8px;
}

.status-action {
    margin-top: 22px;
}

.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.check input {
    width: 16px;
    height: 16px;
    margin-top: 4px;
}

.page-admin {
    background: var(--paper);
}

.page-admin h1 {
    font-size: clamp(2.3rem, 4vw, 3.6rem);
}

.alias-title {
    font-family: var(--mono);
    font-weight: 500;
    font-size: clamp(1.8rem, 4vw, 3rem);
    word-break: break-all;
}

.admin-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 28px;
    height: 100vh;
    padding: 28px 20px;
    background: var(--ink);
    color: var(--paper);
}

.brand-inverse {
    color: var(--paper);
}

.sidebar .brand-mark {
    background: var(--paper);
    box-shadow: 5px 5px 0 #3a332c;
}

.side-brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.side-links {
    display: grid;
    gap: 4px;
}

.side-links a {
    display: block;
    padding: 8px 10px;
    text-decoration: none;
}

.side-links a:hover,
.side-links a[aria-current="page"] {
    background: var(--paper);
    color: var(--ink);
}

.side-foot {
    margin-top: auto;
}

.signed-in {
    margin-bottom: 8px;
    color: #d9d0c3;
    font-size: 0.92rem;
}

.nav-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.nav-toggle-btn {
    display: none;
    border: 1px solid currentColor;
    padding: 4px 10px;
    cursor: pointer;
}

.admin-main {
    width: min(1120px, 100%);
    padding: 36px 40px 72px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 8px 0 22px;
    border-top: 1px solid var(--ink);
    border-bottom: 1px solid var(--ink);
}

.stat {
    padding: 16px 16px 18px 0;
}

.stat + .stat {
    padding-left: 16px;
    border-left: 1px solid var(--line);
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.stat-value, .meta-num {
    font-family: var(--serif);
    font-size: 2.6rem;
    line-height: 1;
    letter-spacing: -0.04em;
    margin-top: 8px;
}

.card + .card, .history {
    margin-top: 22px;
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.chart {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(14, minmax(0, 1fr));
    gap: 8px;
    height: 168px;
    margin: 0;
    padding: 0;
}

.chart li {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: end;
    min-width: 0;
    height: 100%;
}

.bar-track {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    height: 100%;
    width: 100%;
}

.bar {
    display: block;
    width: min(100%, 22px);
    background: var(--green);
}

.day {
    margin-top: 8px;
    color: var(--ink-soft);
    font-size: 0.72rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.8fr);
    gap: 22px;
    align-items: start;
    margin-top: 22px;
}

.split > * {
    min-width: 0;
}

.split-even {
    grid-template-columns: minmax(0, 1.2fr) minmax(240px, 0.8fr);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

th {
    padding: 0 12px 10px 0;
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
}

td {
    padding: 14px 16px 14px 0;
    border-top: 1px solid var(--line);
    vertical-align: middle;
}

tbody tr:hover {
    background: rgba(30, 70, 54, 0.04);
}

.code-link {
    color: var(--ink);
    font-family: var(--mono);
    font-weight: 500;
    text-decoration: none;
}

.code-link:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.sub {
    display: block;
    margin-top: 2px;
    font-size: 0.86rem;
}

.truncate {
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.num, .nowrap {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid currentColor;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.badge-live {
    color: var(--green);
}

.badge-paused {
    color: var(--brass);
}

.rank {
    list-style: none;
    margin: 8px 0 0;
    padding: 0;
}

.rank-empty {
    margin-top: 14px;
}

.rank li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.rank a {
    font-family: var(--mono);
    text-decoration: none;
}

.rank a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 8px 0 18px;
}

.filters {
    display: flex;
    flex: 1 1 520px;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.filters input, .filters select {
    width: auto;
    background: white;
}

.filters input[type="search"] {
    flex: 1 1 220px;
    min-width: 180px;
}

.filters select {
    min-width: 150px;
}

.count-line {
    margin-bottom: 8px;
}

.pager {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
}

.pager a {
    color: var(--green);
}

.pager-disabled {
    color: #b3aa9e;
}

.empty {
    margin-top: 22px;
    padding: 8px 0 12px;
    background: transparent;
}

.empty h2 {
    margin-bottom: 8px;
}

.empty p {
    max-width: 46ch;
    margin-bottom: 16px;
    color: var(--ink-soft);
}

.meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 18px;
    margin: 0 0 14px;
}

.meta div {
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

.meta dt {
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.meta dd {
    margin: 4px 0 0;
}

.meta-text {
    font-size: 1rem;
}

.danger-zone {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.action-row {
    margin: 16px 0 8px;
}

.action-row form,
.row-actions form {
    margin: 0;
}

.row-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

@media (max-width: 900px) {
    .points, .split, .split-even, .stats {
        grid-template-columns: 1fr 1fr;
    }

    .split, .split-even {
        grid-template-columns: 1fr;
    }

    .stat:nth-child(n) {
        border-left: 0;
        border-top: 1px solid var(--line);
        padding-left: 0;
    }

    .stat:nth-child(-n+2) {
        border-top: 0;
    }

    .stat:nth-child(even) {
        padding-left: 16px;
        border-left: 1px solid var(--line);
    }

    .admin-shell {
        display: block;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 5;
        height: auto;
        gap: 14px;
    }

    .nav-toggle-btn {
        display: inline-flex;
    }

    .side-links, .side-foot {
        display: none;
    }

    .nav-toggle:checked ~ .side-links,
    .nav-toggle:checked ~ .side-foot {
        display: block;
    }

    .side-foot {
        margin-top: 8px;
    }

    .admin-main {
        padding: 24px 16px 56px;
    }
}

@media (max-width: 640px) {
    .wrap {
        width: min(100% - 32px, 920px);
    }

    .points, .stats, .meta, .colophon, .page-head {
        grid-template-columns: 1fr;
        display: grid;
    }

    .page-head, .colophon {
        align-items: start;
    }

    .stat:nth-child(n) {
        border-left: 0;
        padding-left: 0;
    }

    .stat + .stat, .stat:nth-child(n+2) {
        border-top: 1px solid var(--line);
    }

    .hero {
        padding-top: 36px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}
