:root {
    color-scheme: light;
    --canvas: #faf6ee;
    --surface: #fffdfa;
    --ink: #182820;
    --muted: #4d6256;
    --green: #24523d;
    --green-dark: #173e2c;
    --sage: #e7efe2;
    --border: #d9e0d3;
    --field-border: #758379;
    --clay: #a34b37;
    --radius: 18px;
    font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); }
p, h1, h2 { margin: 0; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 24px;
    max-width: 1280px;
    min-height: 74px;
    margin: auto;
    padding: 0 32px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: fit-content;
    color: var(--ink);
    font-size: 1.19rem;
    font-weight: 700;
    letter-spacing: -.035em;
    text-decoration: none;
}

.brand img { display: block; border-radius: 10px; }
.brand-label {
    margin-left: 2px;
    padding-left: 10px;
    border-left: 1px solid var(--border);
    color: var(--muted);
    font-size: .83rem;
    font-weight: 500;
    letter-spacing: 0;
}

.topnav { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.topnav a {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 7px 14px;
    border-radius: 9px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 550;
    white-space: nowrap;
}
.topnav a[aria-current] { background: var(--sage); color: var(--green); font-weight: 700; }
.topnav a:hover { color: var(--green); text-decoration: underline; }
.sign-out { justify-self: end; }

.page, .login-page {
    width: min(100%, 1280px);
    margin: auto;
    padding: 36px 32px 48px;
}

.page-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 24px;
}

h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.12;
    letter-spacing: -.05em;
    font-weight: 720;
}
h2 { font-size: 1.18rem; line-height: 1.25; letter-spacing: -.02em; }
.page-header p { margin-top: 7px; color: var(--muted); }
.muted { color: var(--muted); font-size: .92rem; }

.current-prompt {
    display: grid;
    gap: 2px;
    min-width: 180px;
    max-width: 360px;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--sage);
    color: var(--green);
    text-decoration: none;
    overflow-wrap: anywhere;
}
.current-prompt span { font-size: .78rem; }
.current-prompt strong { font-size: .91rem; font-weight: 650; }
.current-prompt:hover strong { text-decoration: underline; }

.surface { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.prompt-grid {
    display: grid;
    grid-template-columns: minmax(0, 264px) minmax(0, 1fr);
    align-items: start;
    gap: 22px;
}
.version-panel { padding: 21px 16px; }
.version-panel h2 { margin-left: 7px; margin-bottom: 15px; font-size: 1.02rem; }
.versions { display: grid; gap: 5px; padding: 0; margin: 0; list-style: none; }
.version {
    display: grid;
    gap: 4px;
    padding: 9px 11px;
    border-left: 3px solid transparent;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
    overflow-wrap: anywhere;
}
.version[aria-current] { border-left-color: var(--green); background: var(--sage); }
.version:hover strong { text-decoration: underline; }
.version-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .79rem; }
.version strong { font-size: .9rem; font-weight: 620; line-height: 1.35; }
.badge { padding: 1px 7px; border-radius: 20px; background: var(--green); color: white; font-size: .72rem; font-weight: 650; }
.pager { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 16px 7px 0; font-size: .83rem; }

.editor, .profile-panel, .login-card { padding: 24px; }
.editor-header { display: flex; align-items: start; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 23px; }
.editor-header .muted { margin-top: 5px; }
.fields { display: grid; gap: 18px; }
.field { display: grid; gap: 6px; min-width: 0; font-size: .91rem; font-weight: 630; }
.field input, .field select, .field textarea {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid var(--field-border);
    border-radius: 9px;
    background: white;
    color: var(--ink);
    font-size: 1rem;
    font-weight: 400;
}
.field textarea {
    display: block;
    min-height: 86px;
    resize: vertical;
    font: .88rem/1.65 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.field [aria-invalid="true"] { border-color: var(--clay); }
.field-error, .field-hint { color: var(--muted); font-size: .82rem; font-weight: 500; }
.field-error { color: var(--clay); }
.form-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: .9rem;
    font-weight: 650;
    text-align: center;
}
.button-primary { background: var(--green); color: white; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border-color: var(--field-border); background: var(--surface); color: var(--green); }
.button-plain { background: transparent; color: var(--green); }
.button-secondary:hover, .button-plain:hover { background: var(--sage); }
.notice { margin-bottom: 18px; padding: 10px 14px; border-radius: 10px; background: var(--sage); color: var(--green); font-weight: 600; }
.notice-error { background: var(--surface); color: var(--clay); }
.delete-version { border-top: 1px solid var(--border); margin-top: 22px; padding-top: 12px; }
.delete-version summary { width: fit-content; padding: 10px 0; color: var(--clay); font-weight: 650; cursor: pointer; }
.delete-version form { display: grid; gap: 10px; justify-items: start; }
.button-danger { border-color: var(--clay); background: var(--clay); color: white; }
.button-danger:hover { background: #883b2b; }

.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(100%, 430px); padding: 32px; }
.login-card h1 { font-size: 2.2rem; margin: 24px 0 22px; }
.profile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 22px; max-width: 1020px; }
.profile-panel h2 { margin-bottom: 18px; }
.ai-settings-panel { max-width: 560px; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
.badge-muted { background: var(--border); color: var(--muted); }
.table-panel { padding: 8px 20px; overflow-x: auto; }
.table-panel > .muted { padding: 16px 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data-table th { padding: 12px 10px; color: var(--muted); font-size: .8rem; font-weight: 650; text-align: left; }
.data-table td { padding: 12px 10px; border-top: 1px solid var(--border); vertical-align: middle; }
.data-table td a { font-weight: 650; }
.challenge-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.sticker-thumb { flex: none; object-fit: contain; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: end; gap: 6px; }
.challenge-editor { max-width: 860px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; }
.field textarea.plain-text { font: inherit; font-size: 1rem; }
.sticker-picker { margin: 0; padding: 0; border: 0; }
.sticker-picker legend { margin-bottom: 6px; padding: 0; }
.sticker-options { display: flex; flex-wrap: wrap; gap: 10px; }
.sticker-option {
    display: grid;
    justify-items: center;
    gap: 4px;
    width: 116px;
    padding: 10px 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: white;
    font-size: .8rem;
    font-weight: 550;
    text-align: center;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.sticker-option:has(input:checked) { border-color: var(--green); background: var(--sage); }
.sticker-option img { object-fit: contain; }
.checkbox-field { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: .91rem; font-weight: 630; }
.checkbox-field input { width: 20px; height: 20px; accent-color: var(--green); }
.sticker-layout { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); align-items: start; gap: 22px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; margin: 0; padding: 0; list-style: none; }
.sticker-card { display: grid; justify-items: center; gap: 10px; padding: 18px 16px; text-align: center; }
.sticker-card img { object-fit: contain; }
.rename-form { display: grid; gap: 8px; width: 100%; }
.button-plain-danger { color: var(--clay); }
.button-plain-danger:hover { background: transparent; text-decoration: underline; }

@media (max-width: 740px) {
    .sticker-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
    .table-panel { padding: 4px 12px; }
    .topbar-inner { grid-template-columns: minmax(0, 1fr) auto; gap: 5px 10px; padding: 10px 16px; }
    .topnav { grid-column: 1 / -1; grid-row: 2; }
    .sign-out { grid-row: 1; grid-column: 2; }
    .page, .login-page { padding: 24px 16px 36px; }
    .prompt-grid, .profile-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
    .editor, .profile-panel, .login-card { padding: 18px; }
    .version-panel { padding: 15px; }
    .versions { max-height: 12rem; overflow-y: auto; }
}

@media (max-width: 350px) {
    .topbar .brand-label { display: none; }
}
