/* ============================================================
   Readwise Reader Uploader — v3
   ============================================================ */

:root {
    --font-body:
        "Inter", "Segoe UI Variable", "Microsoft YaHei UI", system-ui,
        sans-serif;
    --font-serif:
        "Noto Serif SC", "Source Han Serif SC", "STSong", Georgia, serif;
    --font-mono: "JetBrains Mono", "Cascadia Code", "Consolas", monospace;

    --bg: #f6f1e9;
    --bg-gradient-a: rgba(176, 74, 42, 0.07);
    --bg-gradient-b: rgba(45, 107, 69, 0.06);
    --card: rgba(255, 253, 249, 0.88);
    --card-solid: #fffdf8;
    --card-border: rgba(80, 56, 36, 0.09);
    --card-shadow:
        0 1px 3px rgba(80, 56, 36, 0.06), 0 12px 40px rgba(80, 56, 36, 0.1);

    --text: #1a1410;
    --text-secondary: #5c4d3e;
    --text-tertiary: #8c7c6a;
    --border: rgba(80, 56, 36, 0.12);
    --border-focus: rgba(157, 63, 39, 0.5);
    --input-bg: rgba(255, 255, 255, 0.65);
    --input-focus-bg: #fff;

    --accent: #b04a2a;
    --accent-hover: #943e22;
    --accent-subtle: rgba(176, 74, 42, 0.08);
    --accent-ring: rgba(176, 74, 42, 0.15);

    --green: #2d6b45;
    --green-bg: #eaf5ee;
    --red: #b33a30;
    --red-bg: #fbeaea;
    --amber: #8a6d2b;
    --amber-bg: #fdf6e3;

    --code-bg: #1e1a16;
    --code-text: #e8dfd4;
    --preview-bg: #fffdf8;

    --radius-sm: 10px;
    --radius: 16px;
    --radius-lg: 22px;
    --radius-xl: 28px;

    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Theme: Cool Ink ---- */
body[data-theme="cool"] {
    --bg: #edf0f5;
    --bg-gradient-a: rgba(59, 91, 160, 0.07);
    --bg-gradient-b: rgba(59, 91, 160, 0.04);
    --card: rgba(255, 255, 255, 0.9);
    --card-solid: #f9fafb;
    --card-border: rgba(30, 55, 100, 0.08);
    --card-shadow:
        0 1px 3px rgba(30, 55, 100, 0.06), 0 12px 40px rgba(30, 55, 100, 0.09);
    --text: #141820;
    --text-secondary: #404a5c;
    --text-tertiary: #6b7a94;
    --border: rgba(30, 55, 100, 0.12);
    --border-focus: rgba(59, 91, 160, 0.5);
    --input-bg: rgba(255, 255, 255, 0.7);
    --accent: #3b5ba0;
    --accent-hover: #2d4a85;
    --accent-subtle: rgba(59, 91, 160, 0.08);
    --accent-ring: rgba(59, 91, 160, 0.15);
    --code-bg: #1c2030;
    --code-text: #d4dce8;
    --preview-bg: #f9fafb;
}

/* ---- Theme: Forest ---- */
body[data-theme="forest"] {
    --bg: #edf2ec;
    --bg-gradient-a: rgba(56, 102, 65, 0.07);
    --bg-gradient-b: rgba(56, 102, 65, 0.04);
    --card: rgba(252, 255, 252, 0.88);
    --card-solid: #f7faf7;
    --card-border: rgba(36, 70, 40, 0.08);
    --card-shadow:
        0 1px 3px rgba(36, 70, 40, 0.06), 0 12px 40px rgba(36, 70, 40, 0.09);
    --text: #141a14;
    --text-secondary: #3e5040;
    --text-tertiary: #607560;
    --border: rgba(36, 70, 40, 0.12);
    --border-focus: rgba(56, 102, 65, 0.5);
    --input-bg: rgba(255, 255, 255, 0.65);
    --accent: #386641;
    --accent-hover: #2a5032;
    --accent-subtle: rgba(56, 102, 65, 0.08);
    --accent-ring: rgba(56, 102, 65, 0.15);
    --code-bg: #1a221a;
    --code-text: #d4e0d6;
    --preview-bg: #f7faf7;
}

/* ---- Theme: Midnight ---- */
body[data-theme="midnight"] {
    --bg: #141218;
    --bg-gradient-a: rgba(200, 150, 80, 0.04);
    --bg-gradient-b: rgba(200, 150, 80, 0.03);
    --card: rgba(28, 25, 32, 0.92);
    --card-solid: #1e1b22;
    --card-border: rgba(255, 255, 255, 0.07);
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 12px 40px rgba(0, 0, 0, 0.3);
    --text: #e8e4ec;
    --text-secondary: #b0a8b8;
    --text-tertiary: #9890a0;
    --border: rgba(255, 255, 255, 0.1);
    --border-focus: rgba(220, 170, 80, 0.5);
    --input-bg: rgba(255, 255, 255, 0.06);
    --input-focus-bg: rgba(255, 255, 255, 0.1);
    --accent: #d4a04a;
    --accent-hover: #c08a30;
    --accent-subtle: rgba(212, 160, 74, 0.1);
    --accent-ring: rgba(212, 160, 74, 0.2);
    --green: #5cba7d;
    --green-bg: rgba(92, 186, 125, 0.12);
    --red: #e06060;
    --red-bg: rgba(224, 96, 96, 0.12);
    --amber: #d4a04a;
    --amber-bg: rgba(212, 160, 74, 0.12);
    --code-bg: #0e0d12;
    --code-text: #d4cce0;
    --preview-bg: #1a1820;
}

/* ---- Theme: Lavender ---- */
body[data-theme="lavender"] {
    --bg: #f0ecf5;
    --bg-gradient-a: rgba(120, 80, 160, 0.06);
    --bg-gradient-b: rgba(120, 80, 160, 0.04);
    --card: rgba(255, 253, 255, 0.9);
    --card-solid: #faf8fc;
    --card-border: rgba(80, 50, 110, 0.08);
    --card-shadow:
        0 1px 3px rgba(80, 50, 110, 0.06), 0 12px 40px rgba(80, 50, 110, 0.09);
    --text: #1a141e;
    --text-secondary: #504060;
    --text-tertiary: #7c6c8e;
    --border: rgba(80, 50, 110, 0.12);
    --border-focus: rgba(120, 80, 160, 0.5);
    --input-bg: rgba(255, 255, 255, 0.7);
    --accent: #7850a0;
    --accent-hover: #603e85;
    --accent-subtle: rgba(120, 80, 160, 0.08);
    --accent-ring: rgba(120, 80, 160, 0.15);
    --code-bg: #1e1a24;
    --code-text: #dcd4e6;
    --preview-bg: #faf8fc;
}

/* ---- Theme: Minimal ---- */
body[data-theme="minimal"] {
    --bg: #f8f8f8;
    --bg-gradient-a: transparent;
    --bg-gradient-b: transparent;
    --card: rgba(255, 255, 255, 0.95);
    --card-solid: #ffffff;
    --card-border: rgba(0, 0, 0, 0.06);
    --card-shadow:
        0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
    --text: #111111;
    --text-secondary: #444444;
    --text-tertiary: #888888;
    --border: rgba(0, 0, 0, 0.1);
    --border-focus: rgba(0, 0, 0, 0.4);
    --input-bg: rgba(255, 255, 255, 0.8);
    --accent: #333333;
    --accent-hover: #111111;
    --accent-subtle: rgba(0, 0, 0, 0.04);
    --accent-ring: rgba(0, 0, 0, 0.1);
    --code-bg: #1a1a1a;
    --code-text: #ddd;
    --preview-bg: #ffffff;
}

/* --- Reset & base --- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

html,
body {
    margin: 0;
    height: 100dvh;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    background-image:
        radial-gradient(
            ellipse at 20% 0%,
            var(--bg-gradient-a) 0%,
            transparent 50%
        ),
        radial-gradient(
            ellipse at 80% 100%,
            var(--bg-gradient-b) 0%,
            transparent 50%
        );
    background-attachment: fixed;
    transition:
        background-color 350ms ease,
        color 350ms ease;
    display: flex;
    flex-direction: column;
}

/* --- Shell --- */

.shell {
    width: min(1680px, calc(100% - 48px));
    margin: 0 auto;
    padding: 24px 0 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* --- Hero --- */

.hero {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--card-shadow);
    padding: 20px 24px;
    animation: rise 500ms ease-out both;
    transition:
        background 350ms ease,
        border-color 350ms ease,
        box-shadow 350ms ease;
}

.hero-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.hero-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.hero h1 {
    margin: 0;
    font-family: var(--font-serif);
    font-size: clamp(1.5rem, 2.8vw, 2.2rem);
    font-weight: 700;
    line-height: 1.2;
    color: var(--text);
}

.lead {
    max-width: 600px;
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: 0.86rem;
    line-height: 1.6;
}

/* --- Status bar --- */

.status-bar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    padding: 5px 12px;
    min-height: 28px;
    border-radius: 999px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 500;
    cursor: default;
    transition: all var(--transition);
}

button.status-pill {
    cursor: pointer;
}

button.status-pill:hover {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px var(--accent-ring);
}

button.status-pill:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-tertiary);
    flex-shrink: 0;
    transition: background var(--transition);
}

.dot-ok { background: var(--green); }
.dot-error { background: var(--red); }
.dot-warning { background: var(--amber, #8a6d2b); }
.dot-checking {
    background: var(--text-tertiary);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.status-pill.ok {
    color: var(--green);
    background: var(--green-bg);
    border-color: rgba(45, 107, 69, 0.15);
}

.status-pill.error {
    color: var(--red);
    background: var(--red-bg);
    border-color: rgba(179, 58, 48, 0.15);
}

.status-pill.warning {
    color: var(--amber);
    background: var(--amber-bg);
    border-color: rgba(138, 109, 43, 0.15);
}

.status-pill.checking {
    color: var(--text-tertiary);
}

.status-pill.muted {
    color: var(--text-tertiary);
    background: var(--card-border);
    border-color: transparent;
    padding: 2px 8px;
    font-size: 0.72rem;
}

/* --- Theme switcher --- */

.theme-switcher {
    display: flex;
    gap: 6px;
    padding: 4px 0;
}

.theme-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition:
        transform var(--transition),
        border-color var(--transition),
        box-shadow var(--transition);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.theme-dot:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.theme-dot:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.theme-dot:active {
    transform: scale(0.95);
}

.theme-dot.active {
    border-color: var(--text);
    box-shadow:
        0 0 0 2px var(--bg),
        0 0 0 4px var(--text-tertiary);
}

.theme-dot[data-theme=""] {
    background: linear-gradient(135deg, #f6f1e9, #b04a2a);
}
.theme-dot[data-theme="cool"] {
    background: linear-gradient(135deg, #edf0f5, #3b5ba0);
}
.theme-dot[data-theme="forest"] {
    background: linear-gradient(135deg, #edf2ec, #386641);
}
.theme-dot[data-theme="midnight"] {
    background: linear-gradient(135deg, #141218, #d4a04a);
}
.theme-dot[data-theme="lavender"] {
    background: linear-gradient(135deg, #f0ecf5, #7850a0);
}
.theme-dot[data-theme="minimal"] {
    background: linear-gradient(135deg, #f8f8f8, #333333);
}

/* --- Layout --- */

.layout {
    display: grid;
    grid-template-columns: 5fr 6fr;
    gap: 20px;
    margin-top: 16px;
    align-items: stretch;
    flex: 1;
    min-height: 0;
}

.panel {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--card-shadow);
    animation: rise 560ms ease-out both;
    transition:
        background 350ms ease,
        border-color 350ms ease,
        box-shadow 350ms ease;
}

.form-panel {
    padding: 22px 24px 0;
    display: flex;
    flex-direction: column;
}

.preview-panel {
    padding: 18px;
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    max-height: calc(100dvh - 32px);
}

.form-panel form {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-panel .editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-panel .drop-zone {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-panel textarea {
    flex: 1;
}

.panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding: 0 4px;
    flex-shrink: 0;
}

.panel-head h2 {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-hint {
    color: var(--text-tertiary);
    font-size: 0.76rem;
}

.preview-mode-btn {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--input-bg);
    color: var(--text-tertiary);
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.03em;
}

.preview-mode-btn:hover {
    border-color: var(--border-focus);
    color: var(--text-secondary);
}

.preview-mode-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.preview-mode-btn.active {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent-ring);
}

/* --- Form elements --- */

form {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field > span {
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.field-title {
    margin-bottom: 2px;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select {
    width: 100%;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    padding: 0 12px;
    outline: none;
    transition:
        border-color var(--transition),
        box-shadow var(--transition),
        background var(--transition);
    font-size: 0.88rem;
}

input[type="date"] {
    font-variant-numeric: tabular-nums;
}

input::placeholder {
    color: var(--text-tertiary);
    opacity: 0.7;
}

input:focus-visible,
select:focus-visible {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-ring);
    background: var(--input-focus-bg);
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238c7c6a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

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

/* --- Collapsible metadata --- */

.collapsible-wrap {
    margin: 6px 0 0;
}

.toggle-meta {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 0;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: color var(--transition);
    box-shadow: none;
}

.toggle-meta:hover {
    color: var(--accent);
    box-shadow: none;
    transform: none;
}

.toggle-meta:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.toggle-icon {
    transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.toggle-meta.open .toggle-icon {
    transform: rotate(90deg);
}

.toggle-hint {
    color: var(--text-tertiary);
    font-weight: 400;
    font-size: 0.76rem;
}

.meta-fields {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

.meta-fields.open {
    grid-template-rows: 1fr;
}

.meta-inner {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 0;
    transition:
        padding var(--transition),
        background var(--transition);
    border-radius: var(--radius-sm);
}

.meta-fields.open .meta-inner {
    padding: 10px 12px 10px;
    background: var(--accent-subtle);
}

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

.editor-section {
    margin-top: 10px;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 2px;
    margin-bottom: 6px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-label {
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.lang-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-subtle);
    border: 1px solid transparent;
    font-family: var(--font-mono);
    transition: all var(--transition);
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.word-count {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--input-bg);
    border: 1px solid transparent;
    font-variant-numeric: tabular-nums;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--input-bg);
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: none;
}

.toolbar-btn:hover {
    background: var(--input-focus-bg);
    border-color: var(--border-focus);
    color: var(--text);
    box-shadow: none;
    transform: none;
}

.toolbar-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.toolbar-btn svg {
    flex-shrink: 0;
    opacity: 0.65;
}

/* --- Drop zone & textarea --- */

.drop-zone {
    position: relative;
}

textarea {
    width: 100%;
    min-height: 280px;
    max-height: 600px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--text);
    padding: 14px 16px;
    outline: none;
    resize: vertical;
    line-height: 1.7;
    font-size: 0.88rem;
    font-family: var(--font-mono);
    transition:
        border-color var(--transition),
        box-shadow var(--transition),
        background var(--transition);
    field-sizing: content;
}

textarea::placeholder {
    color: var(--text-tertiary);
    opacity: 0.6;
    font-family: var(--font-body);
}

textarea:focus-visible {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-ring);
    background: var(--input-focus-bg);
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

textarea.shake {
    animation: shake 400ms ease-out;
    border-color: var(--red) !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-4px); }
    40% { transform: translateX(4px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

.drop-overlay {
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    background: var(--accent-subtle);
    border: 2px dashed var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
    z-index: 5;
}

.drop-zone.dragover .drop-overlay {
    opacity: 1;
}

.drop-zone.dragover textarea {
    border-color: transparent;
}

.drop-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    font-size: 0.88rem;
    font-weight: 500;
}

/* --- Sticky actions bar --- */

.actions-sticky {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--card) 60%, transparent);
    padding: 16px 0 22px;
    margin: 0 -24px;
    padding-left: 24px;
    padding-right: 24px;
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    z-index: 3;
}

.actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

#submit-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: none;
    border-radius: 999px;
    padding: 11px 24px;
    min-height: 44px;
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
}

#submit-button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

#submit-button:active:not(:disabled) {
    transform: scale(0.98);
}

#submit-button:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

#submit-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

#submit-button.success {
    background: linear-gradient(135deg, var(--green), #1f5535);
}

.btn-icon,
.btn-check {
    flex-shrink: 0;
}

.spinner {
    animation: spin 800ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.shortcut-hint {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
}

/* --- Account switcher --- */

.account-switcher {
    order: -1;
}

.account-select {
    height: 30px;
    padding: 0 28px 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--input-bg);
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238c7c6a' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    transition: all var(--transition);
    max-width: 200px;
}

.account-select:hover {
    border-color: var(--border-focus);
}

.account-select:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* --- Scroll navigation buttons --- */

.scroll-nav {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 6;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.scroll-nav.visible {
    opacity: 1;
    pointer-events: auto;
}

.drop-zone:hover .scroll-nav.visible,
.preview-scroll-wrap:hover .scroll-nav.visible {
    opacity: 1;
}

.scroll-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-solid);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    padding: 0;
    backdrop-filter: blur(8px);
}

.scroll-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent-ring);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
    transform: scale(1.1);
}

.scroll-btn:active {
    transform: scale(0.95);
}

.scroll-btn:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.preview-scroll-wrap {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* --- Preview panel --- */

.preview-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    border-radius: var(--radius-lg);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.preview-page {
    border-radius: var(--radius-lg);
    background: var(--preview-bg);
    border: 1px solid var(--card-border);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
    min-height: 400px;
    transition: background 350ms ease;
}

#preview {
    padding: 28px 32px;
    max-width: 720px;
    margin: 0 auto;
    font-family: var(--font-body);
    font-size: 0.94rem;
    line-height: 1.8;
    color: var(--text);
    overflow-wrap: break-word;
}

.preview-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.preview-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-tertiary);
    opacity: 0.45;
    text-align: center;
}

.preview-placeholder svg {
    opacity: 0.4;
}

.preview-placeholder p {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.6;
}

/* --- Preview typography --- */

#preview h1,
#preview h2,
#preview h3,
#preview h4,
#preview h5,
#preview h6 {
    font-family: var(--font-serif);
    line-height: 1.25;
    color: var(--text);
}

#preview h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.8em;
    padding-bottom: 0.45em;
    border-bottom: 1px solid var(--border);
}

#preview h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 1.8em 0 0.5em;
}

#preview h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 1.5em 0 0.4em;
}

#preview h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 1.3em 0 0.35em;
}

#preview h5 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 1.2em 0 0.3em;
}

#preview h6 {
    font-size: 0.85rem;
    font-weight: 600;
    margin: 1.1em 0 0.3em;
    color: var(--text-secondary);
}

#preview h1:first-child,
#preview h2:first-child,
#preview h3:first-child {
    margin-top: 0;
}

#preview p {
    margin: 0 0 0.9em;
}

#preview ul,
#preview ol {
    padding-left: 1.4em;
    margin: 0 0 0.9em;
}

#preview li {
    margin-bottom: 0.25em;
}

#preview li > p {
    margin-bottom: 0.35em;
}

#preview a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-color: var(--accent-ring);
    transition: text-decoration-color var(--transition);
}

#preview a:hover {
    text-decoration-color: var(--accent);
}

#preview strong {
    font-weight: 600;
    color: var(--text);
}

#preview code {
    font-family: var(--font-mono);
    font-size: 0.84em;
    padding: 0.12em 0.4em;
    border-radius: 5px;
    background: var(--accent-subtle);
    color: var(--accent-hover);
}

#preview pre {
    margin: 1.1em 0;
    padding: 0;
    border-radius: var(--radius-sm);
    background: var(--code-bg);
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

#preview pre code {
    display: block;
    padding: 16px 18px;
    background: transparent;
    color: var(--code-text);
    font-size: 0.8em;
    line-height: 1.65;
    overflow-x: auto;
    border-radius: 0;
}

#preview blockquote {
    margin: 1.1em 0;
    padding: 10px 18px;
    border-left: 3px solid var(--accent);
    background: var(--accent-subtle);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

#preview blockquote p:last-child {
    margin-bottom: 0;
}

#preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.1em 0;
    font-size: 0.86rem;
}

#preview thead th {
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 12px;
    border-bottom: 2px solid var(--border);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

#preview td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--card-border);
}

#preview tbody tr:hover {
    background: var(--accent-subtle);
}

#preview img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 0.6em 0;
}

#preview hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 1.8em 0;
}

#preview mark {
    background: var(--amber-bg);
    padding: 0.1em 0.3em;
    border-radius: 3px;
}

#preview details {
    margin: 1em 0;
    padding: 0.5em 1em;
    background: var(--accent-subtle);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

#preview summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}

#preview del {
    color: var(--text-tertiary);
}

/* --- Toast --- */

.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    animation: toastIn 350ms cubic-bezier(0.16, 1, 0.3, 1) both;
    max-width: 480px;
    backdrop-filter: blur(12px);
    cursor: pointer;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-copy {
    flex-shrink: 0;
    border: 1px solid currentColor;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    background: transparent;
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity var(--transition);
}

.toast-copy:hover {
    opacity: 1;
}

.toast.success {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid rgba(45, 107, 69, 0.2);
}

.toast.error {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid rgba(179, 58, 48, 0.2);
}

.toast.warning {
    background: var(--amber-bg);
    color: var(--amber);
    border: 1px solid rgba(138, 109, 43, 0.2);
}

.toast a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.toast.leaving {
    animation: toastOut 280ms ease-in both;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toastOut {
    to {
        opacity: 0;
        transform: translateX(30px) scale(0.96);
    }
}

/* --- Responsive --- */

@media (max-width: 1080px) {
    html, body {
        height: auto;
        min-height: 100dvh;
    }

    .shell {
        flex: none;
    }

    .layout {
        grid-template-columns: 1fr;
        flex: none;
    }

    .preview-panel {
        position: static;
        max-height: none;
    }

    .preview-scroll {
        max-height: 70vh;
    }

    .preview-page {
        min-height: 320px;
    }

    .preview-empty {
        min-height: 300px;
    }
}

@media (max-width: 720px) {
    .shell {
        width: calc(100% - 20px);
        padding-top: 16px;
    }

    .hero {
        padding: 14px 16px;
        border-radius: var(--radius-lg);
    }

    .hero-row {
        flex-direction: column;
        gap: 10px;
    }

    .hero-right {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }

    .status-bar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    .panel {
        border-radius: var(--radius-lg);
    }

    .form-panel {
        padding: 16px 16px 0;
    }

    .actions-sticky {
        margin: 0 -16px;
        padding-left: 16px;
        padding-right: 16px;
    }

    .preview-panel {
        padding: 12px;
        margin-top: 16px;
        border-top: 1px solid var(--border);
    }

    .grid,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    #preview {
        padding: 18px;
    }

    textarea {
        min-height: 200px;
    }

    .actions {
        flex-direction: column;
        align-items: stretch;
    }

    #submit-button {
        justify-content: center;
    }

    .shortcut-hint {
        display: none;
    }

    .toast-container {
        left: 12px;
        right: 12px;
        top: env(safe-area-inset-top, 12px);
    }

    .toast {
        max-width: none;
    }

    .toolbar-btn {
        min-height: 44px;
        padding: 8px 14px;
    }

    .theme-dot {
        width: 32px;
        height: 32px;
    }

    button.status-pill {
        min-height: 36px;
    }

    .account-select {
        max-width: none;
        width: 100%;
    }

    .scroll-btn {
        width: 36px;
        height: 36px;
    }
}

/* --- Animations --- */

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
