@font-face {
    font-family: 'NeueHaasGrotesk';
    src: url('fonts/NeueHaasDisplay-Bold.ttf') format('truetype');
    font-weight: 700;
}

:root {
    --navy: #023149;
    --blue: #689ABB;
    --blue-soft: #e6eff5;
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #13212b;
    --muted: #5f6f7b;
    --border: #dde3e8;
    --live: #1a7f4b;
    --live-bg: #e3f4ea;
    --draft: #8a5a00;
    --draft-bg: #fdf1d6;
    --empty: #5f6f7b;
    --empty-bg: #eceff2;
    --danger: #b42318;
    --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.4rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; margin-top: 2rem; }
h3 { font-size: 1rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--blue-soft); padding: 1px 6px; border-radius: 6px; }
a { color: var(--navy); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.8rem; font-weight: 400; }
.right { text-align: right; }

/* ---------------------------------------------------------------- chrome */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.75rem 1.5rem;
    background: var(--navy);
    color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; }
.brand img { height: 28px; }
.topbar nav { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.topbar nav a, .topbar .linkish { color: #fff; text-decoration: none; font-size: 0.9rem; opacity: 0.9; }
.topbar nav a:hover, .topbar .linkish:hover { opacity: 1; text-decoration: underline; }
.topbar .muted { color: rgba(255, 255, 255, 0.6); }
.topbar form { margin: 0; }
.linkish { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }

.page { max-width: 1180px; margin: 0 auto; padding: 1.5rem 16px 6rem; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head > div:first-child { flex: 1 1 320px; }
.back { display: inline-block; margin-bottom: 0.4rem; text-decoration: none; font-size: 0.9rem; }
.head-actions { display: flex; gap: 0.5rem; }

.flash { padding: 0.7rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-size: 0.9rem; }
.flash-ok { background: var(--live-bg); color: var(--live); }
.flash-error { background: #fdecea; color: var(--danger); }

/* ---------------------------------------------------------------- forms */
input, select, textarea {
    font: inherit;
    color: var(--text);
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
textarea { resize: vertical; width: 100%; }
input[type=color] { padding: 2px; height: 40px; width: 64px; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.row > input, .row > select { flex: 1 1 160px; }
.stack { display: flex; flex-direction: column; gap: 1rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--navy);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { border-color: var(--blue); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #04476a; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-outline { color: var(--danger); border-color: #f1b8b3; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.82rem; }

/* ---------------------------------------------------------------- login */
.login-card { max-width: 380px; margin: 10vh auto 0; padding: 2rem; text-align: center; }
.login-card form { text-align: left; margin-top: 1.25rem; }
.login-logo { height: 56px; margin-bottom: 0.75rem; }

/* ---------------------------------------------------------------- dashboard */
.new-year { flex: 0 1 520px; display: flex; flex-direction: column; gap: 0.5rem; margin: 0; }
.legend { display: flex; gap: 0.5rem 0.75rem; align-items: center; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); margin-bottom: 0.5rem; }
.legend .pill { margin-left: 0.5rem; }
.legend .pill:first-child { margin-left: 0; }

.pill { display: inline-block; white-space: nowrap; flex-shrink: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.pill-live { background: var(--live-bg); color: var(--live); }
.pill-draft { background: var(--draft-bg); color: var(--draft); }
.pill-empty { background: var(--empty-bg); color: var(--empty); }

.show-block { margin-top: 2rem; }
.show-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; border-bottom: 2px solid var(--navy); padding-bottom: 0.4rem; margin-bottom: 1rem; }
.show-head h2 { margin: 0; }
.show-head a { font-size: 0.85rem; }
.code { background: var(--navy); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: 0.85em; margin-right: 0.3rem; }

.year-row { display: grid; grid-template-columns: 70px 1fr; gap: 1rem; margin-bottom: 1.25rem; }
.year-label { font-weight: 700; font-size: 1.1rem; color: var(--navy); padding-top: 0.25rem; }
.asset-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.asset-tile { display: block; background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; text-decoration: none; color: inherit; transition: border-color 0.15s, box-shadow 0.15s; }
.asset-tile:hover { border-color: var(--blue); box-shadow: 0 4px 14px rgba(2, 49, 73, 0.08); }
.asset-tile .thumb { aspect-ratio: 1200 / 627; background: var(--empty-bg); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 0.8rem; }
.asset-tile .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-tile.missing { opacity: 0.5; }
.tile-meta { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; padding: 0.5rem 0.65rem; }
.uid { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: 0.75rem; }
.admin-only { margin-top: 2.5rem; }

@media (max-width: 860px) {
    .asset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .year-row { grid-template-columns: 1fr; gap: 0.4rem; }
}

/* ---------------------------------------------------------------- asset editor */
.uid-big { font-size: 1.3rem; background: none; padding: 0; }
.public-link { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding: 0.75rem 1rem; }
.public-link span { font-weight: 600; font-size: 0.85rem; }
.public-link input { flex: 1 1 260px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; background: var(--bg); }
.public-link:not(.is-live) span::after { content: ' (works once published)'; color: var(--muted); font-weight: 400; }

.frames-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 960px) { .frames-grid { grid-template-columns: 1fr; } }
.frame-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin-bottom: 0.75rem; }
.frame-head h3 { margin: 0; }
.spec { font-size: 0.78rem; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.frame-stage { position: relative; width: 100%; border-radius: 8px; overflow: hidden; background: repeating-conic-gradient(#eef1f4 0% 25%, #fff 0% 50%) 50% / 20px 20px; outline: 1px solid var(--border); }
.frame-stage canvas { display: block; width: 100%; height: auto; }
.frame-stage canvas.dragging { cursor: grabbing !important; }
.frame-stage.over { outline: 3px dashed var(--blue); }
.frame-stage.busy { opacity: 0.5; pointer-events: none; }
.empty-frame { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: rgba(244, 246, 248, 0.82); color: var(--muted); font-size: 0.85rem; text-align: center; padding: 0.5rem; pointer-events: none; }
.empty-frame strong { color: var(--navy); }
.frame-stage.has-frame .empty-frame { display: none; }
.frame-error { margin: 0.75rem 0 0; }
.frame-controls { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-top: 0.75rem; }
.frame-controls .slider { flex: 1 1 140px; font-weight: 500; font-size: 0.8rem; color: var(--muted); }
.frame-controls input[type=range] { padding: 0; accent-color: var(--navy); }
.test-tools { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.test-tools label:first-child { flex: 0 1 200px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }

.danger-zone { margin-top: 2.5rem; border-color: #f1b8b3; }
.danger-zone summary { color: var(--danger); }

.savebar {
    position: fixed;
    left: 50%;
    bottom: 1.25rem;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--navy);
    color: #fff;
    padding: 0.6rem 0.75rem 0.6rem 1.25rem;
    border-radius: 999px;
    box-shadow: 0 10px 30px rgba(2, 49, 73, 0.35);
    z-index: 20;
    max-width: calc(100vw - 32px);
    flex-wrap: wrap;
}
.savebar[hidden] { display: none; }
.savebar .btn-primary { background: var(--blue); border-color: var(--blue); }

/* ---------------------------------------------------------------- tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 0.5rem; border-bottom: 1px solid var(--border); }
.table td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); }
.table form { margin: 0; }

/* ---------------------------------------------------------------- text on/off */
.text-toggle { display: flex; align-items: center; gap: 1rem; padding: 0.9rem 1.25rem; }
.text-toggle div { display: flex; flex-direction: column; }
.text-toggle .muted { font-size: 0.85rem; }
.switch { position: relative; display: inline-block; flex: 0 0 auto; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { display: block; width: 46px; height: 26px; border-radius: 999px; background: #c5cdd4; transition: background 0.15s; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--navy); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--blue); outline-offset: 2px; }
.no-text .text-only { display: none; }
