:root {
    --bg: #1e1f22;
    --panel: #2b2d31;
    --panel-2: #313338;
    --border: #3f4147;
    --text: #e6e6e6;
    --muted: #9aa0a6;
    --accent: #2b5b84;
    --accent-2: #3f7bb0;
    --danger: #c0392b;
    --warn: #d4a017;
    --ok: #3fa45b;
    --pink: #f4a8c3;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
}

/* Tapping controls shouldn't flash a grey highlight or select text on mobile. */
.btn, .filechip, .regen, .toggle, .board-card, .file-btn, .replace-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none;
    left: 0;
    padding: .6rem 1.25rem .7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #111;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

/* ---------- Studio shell ---------- */

.studio { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* iOS standalone ("Add to Home Screen"): vh units are unreliable there - 100dvh
   is stale-small on cold launch (blank gap), and 100vh overshoots the real
   viewport (WebKit bug 292603: the root scroller extends by the home-indicator
   inset, adding a phantom scroll strip). Pin the shell to the layout viewport
   with fixed positioning instead; internal regions (.board, .detail, image
   strip) still scroll. Regular Safari keeps the dynamic 100dvh behaviour. */
@media all and (display-mode: standalone) {
    html, body { height: 100%; overflow: hidden; }
    .studio { position: fixed; inset: 0; height: auto; }
}
html.pwa-standalone, html.pwa-standalone body { height: 100%; overflow: hidden; }
html.pwa-standalone .studio { position: fixed; inset: 0; height: auto; }

.studio-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 18px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
/* Self-hosted so the LAN app renders it without a Google Fonts dependency. */
@font-face {
    font-family: "Great Vibes";
    src: url("fonts/great-vibes-latin.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

.brand { display: flex; flex-direction: column; gap: 1px; }
.brand-title {
    font-family: "Great Vibes", cursive;
    color: var(--pink);
    font-size: 27px; font-weight: 400; line-height: 1.15;
    letter-spacing: .3px; white-space: nowrap;
}
.brand-sub { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; }

.view-toggle { display: flex; background: var(--panel-2); border-radius: 8px; padding: 3px; }
.toggle {
    border: none; background: transparent; color: var(--muted);
    padding: 6px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.toggle.active { background: var(--accent); color: #fff; }
.toggle:hover:not(.active) { color: var(--text); }

.studio-toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: nowrap;
    padding: 10px 18px;
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
}
@media (max-width: 480px) {
    .studio-toolbar { flex-wrap: wrap; row-gap: 6px; }
}
.spacer { flex: 1; }

.btn {
    border: 1px solid var(--border); background: var(--panel);
    color: var(--text); padding: 7px 14px; border-radius: 7px;
    cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #3a3d42; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #1a1a1a; }

.file-btn {
    position: relative; overflow: hidden; display: inline-flex; align-items: center;
    border: 1px dashed var(--border); background: var(--panel);
    padding: 7px 14px; border-radius: 7px; cursor: pointer; font-size: 13px;
}
.file-btn:hover { background: #3a3d42; }
.file-btn.disabled { opacity: .45; pointer-events: none; }
.file-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.studio-statusbar {
    display: flex; align-items: center; gap: 12px;
    padding: 7px 18px; font-size: 12.5px; color: var(--muted);
    background: var(--bg); border-bottom: 1px solid var(--border);
}
.filechip {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--panel-2); border: 1px solid var(--border);
    padding: 5px 12px; border-radius: 20px; color: var(--text);
    cursor: pointer; font: inherit; font-size: 13px;
}
.filechip:hover { border-color: var(--accent-2); }
.filechip:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.filechip .chev { color: var(--accent-2); transition: transform .18s ease; flex: none; }
.filechip.open .chev { transform: rotate(90deg); }

.studio-image {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 12px 18px; background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.studio-image-strip {
    display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
    max-width: 100%; max-height: 46vh; overflow-y: auto;
}
.studio-image-strip img {
    max-width: 260px; max-height: 30vh;
    border: 1px solid var(--border); border-radius: 8px; object-fit: contain;
    background: #000;
}
.studio-image-thumb { position: relative; display: inline-block; line-height: 0; }
.thumb-remove {
    position: absolute; top: 6px; right: 6px; width: 28px; height: 28px;
    margin: 0; padding: 0; border-radius: 50%;
    border: 1px solid rgba(255,255,255,.35);
    background: rgba(0,0,0,.62);
    cursor: pointer; opacity: .88;
    -webkit-appearance: none; appearance: none;
    box-shadow: 0 1px 3px rgba(0,0,0,.55);
    transition: background .15s ease, opacity .15s ease;
}
/* Two bars instead of a text glyph - guarantees the X is dead centre. */
.thumb-remove::before,
.thumb-remove::after {
    content: "";
    position: absolute; left: 50%; top: 50%;
    width: 13px; height: 2.2px; border-radius: 2px;
    background: #fff;
}
.thumb-remove::before { transform: translate(-50%, -50%) rotate(45deg); }
.thumb-remove::after  { transform: translate(-50%, -50%) rotate(-45deg); }
.thumb-remove:hover { background: var(--danger); border-color: var(--danger); opacity: 1; }
.thumb-remove:disabled { opacity: .45; cursor: not-allowed; }
/* Touch devices keep the X always visible; pointer devices reveal it on hover. */
@media (hover: hover) and (pointer: fine) {
    .thumb-remove { opacity: 0; }
    .studio-image-thumb:hover .thumb-remove,
    .thumb-remove:focus-visible { opacity: .92; }
}
.studio-image-actions {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
}
.replace-btn { position: relative; overflow: hidden; border-style: dashed; }
.replace-btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.replace-btn:has(input:disabled) { opacity: .45; pointer-events: none; }

.studio-footer {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
    background: var(--panel-2);
    border-top: 1px solid var(--border);
}

.empty { margin: auto; text-align: center; color: var(--muted); padding: 60px 20px; }
.empty h2 { color: var(--text); }

/* ---------- Split editor ---------- */

.split { display: flex; flex: 1; min-height: 0; }

.booklist {
    width: 300px; min-width: 300px; overflow-y: auto;
    border-right: 1px solid var(--border); background: var(--panel);
}
.bookrow {
    display: flex; align-items: flex-start; gap: 10px; width: 100%;
    text-align: left; border: none; border-bottom: 1px solid var(--border);
    background: transparent; color: var(--text); padding: 11px 14px; cursor: pointer;
}
.bookrow:hover { background: var(--panel-2); }
.bookrow.selected { background: var(--accent); }
.bookrow-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.bookrow-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookrow-meta { font-size: 11.5px; color: var(--muted); }
.bookrow.selected .bookrow-meta { color: #dce6f0; }

.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; flex: none; }

.detail { flex: 1; overflow-y: auto; padding: 20px; min-width: 0; }
.muted { color: var(--muted); }

@media (max-width: 720px) {
    .split { flex-direction: column; }
    .booklist { width: 100%; min-width: 0; max-height: 30vh; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---------- Badges & controls ---------- */

.badge {
    display: inline-block; color: #fff; font-size: 11px; font-weight: 600;
    padding: 2px 9px; border-radius: 20px; margin-left: 6px; vertical-align: middle;
}
.badge.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }

.input {
    width: 100%; background: var(--panel); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 7px 10px; font-size: 13px; font-family: inherit;
}
.input:focus { outline: none; border-color: var(--accent-2); }

/* ---------- Editor ---------- */

.editor { display: flex; flex-direction: column; gap: 16px; }
.editor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.editor-head h2 { margin: 0 0 6px; font-size: 20px; }
.editor-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.issue-strip {
    display: flex; gap: 10px; align-items: baseline;
    background: #3a2f14; border: 1px solid var(--warn); color: #f0d9a0;
    padding: 9px 12px; border-radius: 8px; font-size: 13px;
}
.issue-strip strong { text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }

.editor-body { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.form { flex: 1; min-width: 320px; display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 5px; }
.form-row label { font-size: 12px; color: var(--muted); font-weight: 600; }
.form-row .hint { font-weight: 400; font-style: italic; color: #6d7278; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.clues-label { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.clue-row { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
.clue-label { font-weight: 600; }

.preview-wrap { display: flex; flex-direction: column; gap: 8px; }
.preview-caption { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

/* ---------- Board ---------- */

.board {
    flex: 1; overflow-y: auto; padding: 20px;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 18px; align-content: start;
}
.board-card {
    display: flex; flex-direction: column; gap: 10px; align-items: stretch;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 14px; cursor: pointer; text-align: left; color: var(--text);
    animation: bd-card-in .32s ease both;
}
.board-card:hover { border-color: var(--accent-2); }
.board-card.has-issue { border-color: var(--warn); }

@keyframes bd-card-in {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to { opacity: 1; transform: none; }
}

.board-card.loading {
    animation: bd-card-in .32s ease both, bd-loading-pulse 1.6s ease-in-out infinite;
}
@keyframes bd-loading-pulse {
    0%, 100% { border-color: var(--border); box-shadow: 0 0 0 0 rgba(63, 123, 176, 0); }
    50% { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(63, 123, 176, .18); }
}

.spinner {
    width: 13px; height: 13px; flex: none;
    border: 2px solid var(--border); border-top-color: var(--accent-2);
    border-radius: 50%; animation: bd-spin .7s linear infinite;
}
@keyframes bd-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .board-card, .board-card.loading { animation: none; }
    .spinner { animation-duration: 1.6s; }
}
.board-card-top { display: flex; align-items: center; gap: 8px; }
.board-card-heading { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.board-card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-card-author { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-card .dot { margin-top: 0; }
.pill { background: var(--panel-2); border: 1px solid var(--border); font-size: 11px; padding: 1px 7px; border-radius: 20px; white-space: nowrap; }
.board-card-footer { display: flex; align-items: center; gap: 10px; margin-top: 2px; }
.board-card-issue {
    font-size: 12px; color: #f0d9a0; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.regen {
    margin-left: auto; flex: none;
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; border: 1px solid var(--border); color: var(--muted);
    padding: 5px 11px; border-radius: 7px;
    font-size: 11.5px; font-weight: 500; letter-spacing: .1px; cursor: pointer;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.regen .regen-icon { flex: none; }
.regen:hover:not(:disabled) { color: var(--text); border-color: var(--accent-2); background: rgba(63, 123, 176, .14); }
.regen:active:not(:disabled) { transform: translateY(.5px); }
.regen:disabled { opacity: .55; cursor: progress; }

/* ---------- PDF preview overlay (iOS) ---------- */

.pdf-overlay {
    position: fixed; inset: 0; z-index: 900;
    display: flex; flex-direction: column;
    background: #1e1f22;
}
.pdf-overlay-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.pdf-overlay-name {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px; color: var(--muted);
}
.pdf-overlay iframe { flex: 1; width: 100%; border: 0; background: #525659; }
