:root {
    color-scheme: light;
    --text: #172033;
    --muted: #667085;
    --border: #d8dee8;
    --soft: #f3f5f8;
    --blue: #2458d3;
    --green: #16805c;
    --orange: #c65f15;
    --red: #b42332;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: #fff;
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

button {
    font: inherit;
    touch-action: manipulation;
}

.shell {
    width: min(760px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2rem 0;
}

.topbar {
    margin-bottom: 2.5rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: #465269;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
}

.back-link:hover {
    color: var(--blue);
    text-decoration: underline;
}

.back-link:focus-visible,
.button:focus-visible {
    outline: 3px solid rgba(36, 88, 211, 0.2);
    outline-offset: 3px;
}

.hero {
    margin-bottom: 2.5rem;
}

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

h1 {
    margin-bottom: 0.5rem;
    font-size: clamp(2rem, 7vw, 3rem);
    line-height: 1.1;
    letter-spacing: -0.035em;
}

h2 {
    margin-bottom: 0.25rem;
    font-size: 1rem;
}

.lede {
    max-width: 620px;
    margin-bottom: 0;
    color: var(--muted);
}

.panel {
    margin-bottom: 1.5rem;
    padding: 1.25rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.bucket-panel {
    padding-top: 0;
    border-top: 0;
}

.bucket-heading {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
}

.hint,
.refill-status {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.token-value {
    font-size: 1.2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.meter {
    height: 12px;
    margin: 1rem 0 0.55rem;
    overflow: hidden;
    border-radius: 2px;
    background: #e7eaf0;
}

.meter-fill {
    width: 100%;
    height: 100%;
    background: var(--green);
    transition: width 100ms linear, background-color 160ms ease;
}

.meter-fill.low {
    background: var(--orange);
}

.meter-fill.empty {
    background: var(--red);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    margin: 0 0 1.75rem;
}

.button {
    padding: 0.58rem 0.8rem;
    border: 1px solid #aeb7c5;
    border-radius: 4px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
}

.button:hover:not(:disabled) {
    background: var(--soft);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

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

.button.primary:hover:not(:disabled) {
    background: #1d49b3;
}

.button.danger {
    border-color: #303a4d;
    background: #303a4d;
    color: #fff;
}

.run-state {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.85rem;
}

.run-state.active {
    color: var(--red);
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin-bottom: 1.75rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.stat {
    padding: 0.8rem 0.9rem;
    border-right: 1px solid var(--border);
}

.stat:first-child {
    padding-left: 0;
}

.stat:last-child {
    border-right: 0;
}

.stat span {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
}

.stat strong {
    display: block;
    margin-top: 0.1rem;
    font-size: 1.45rem;
    font-variant-numeric: tabular-nums;
}

.stat.success strong {
    color: var(--green);
}

.stat.limited strong {
    color: var(--orange);
}

.stat.error strong {
    color: var(--red);
}

.response-log {
    height: 180px;
    margin: 0.75rem 0 0;
    padding: 0;
    overflow: auto;
    list-style: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
}

.response-log li {
    display: grid;
    grid-template-columns: 5rem 3.2rem 1fr;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid #eceff3;
}

.response-log .empty-log {
    display: block;
    color: var(--muted);
}

.status-ok {
    color: var(--green);
}

.status-limited,
.status-error {
    color: var(--red);
}

@media (max-width: 560px) {
    .shell {
        padding-top: 1.25rem;
    }

    .topbar {
        margin-bottom: 2rem;
    }

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

    .stat:nth-child(2) {
        border-right: 0;
    }

    .stat:nth-child(-n + 2) {
        border-bottom: 1px solid var(--border);
    }

    .stat:nth-child(3) {
        padding-left: 0;
    }

    .run-state {
        width: 100%;
        margin-left: 0;
    }
}
