:root {
    --page: #f3f4f1;
    --surface: #fff;
    --surface-soft: #f7f8f5;
    --border: #d7dbd3;
    --border-strong: #b8c0b5;
    --text: #202421;
    --muted: #626b64;
    --accent: #526f86;
    --accent-hover: #465f73;
    --accent-soft: #e8eef2;
    --danger: #8a4b46;
}

* { box-sizing: border-box; }

body {
    color: var(--text);
    background: var(--page);
    font-family: Arial, Helvetica, sans-serif;
}

.studio-page { height: 100dvh; }
.studio-layout { height: calc(100dvh - 55px); }

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

:is(button, a, input, select, textarea, summary):focus-visible {
    outline: 3px solid #a7bac8;
    outline-offset: 2px;
}

.app-header {
    width: 100%;
    height: 55px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.app-title { font-size: 1.05rem; font-weight: 700; }

.nav-arrow {
    width: 44px;
    height: 44px;
    padding: 3px;
    display: grid;
    place-items: center;
    border-radius: 6px;
}

.nav-arrow:hover { background: var(--accent-soft); }
.nav-arrow-image { width: 38px; height: 38px; object-fit: contain; }
.nav-arrow-forward { transform: scaleX(-1); }

.sidebar {
    flex-shrink: 0;
    color: var(--text);
    background: var(--surface-soft);
    border-right: 1px solid var(--border);
}

.control-panel {
    padding: 12px;
    background: rgba(255, 255, 255, .6);
    border-radius: 8px;
}

.section-heading {
    color: var(--text);
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.section-label, .muted-text { color: var(--muted); font-size: .78rem; }

.status-badge {
    padding: 2px 7px;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 999px;
    font-size: .68rem;
    font-weight: 600;
}

.quiet-button,
.plain-select,
.plain-input {
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 6px;
}

.quiet-button {
    min-height: 36px;
    padding: 7px 10px;
    font-size: .82rem;
    font-weight: 600;
    text-align: center;
}

.quiet-button:hover { background: #eef1ed; }
.quiet-button:disabled { cursor: wait; opacity: .65; }

.quiet-button:is(.active, .primary) {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.quiet-button:is(.active, .primary):hover { background: var(--accent-hover); }
.quiet-button.subtle, .library-options summary { color: var(--muted); }
.danger-text { color: var(--danger); }

.library-options summary,
.header-options summary { cursor: pointer; }

.library-options summary { padding: 6px 2px; font-size: .8rem; }

input[type="range"] { accent-color: var(--accent); }
.preset-row {
    display: grid;
    grid-template-columns: repeat(5, 30px);
    gap: 6px;
}

.preset-color {
    aspect-ratio: 1;
    width: 30px;
    height: 30px;
    padding: 0;
    background: var(--swatch);
    border: 2px solid var(--border-strong);
    border-radius: 999px;
}

.preset-color.selected {
    box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent);
}

#canvas {
    min-width: 0;
    min-height: 0;
    background: var(--surface);
}

#draw,
#cropCanvas {
    display: block;
    touch-action: none;
}

.move {
    position: absolute;
    width: 200px;
    height: 150px;
    background-size: 100% 100%;
    border-color: var(--border-strong);
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}

.move img { pointer-events: none; }
.move .customtext { touch-action: manipulation; }

.sound {
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 28px;
    height: 28px;
    background: rgba(32, 36, 33, .75) center / 17px 17px no-repeat;
    border: 1px solid #fff;
    border-radius: 50%;
    cursor: pointer;
}

.dropdown { width: 100%; display: flex; text-align: left; }

.library-category {
    color: var(--text);
    background: transparent;
    border: 0;
    border-radius: 6px;
}

.library-category:hover { background: var(--accent-soft); }

.dropdown-content {
    display: none;
    flex-direction: column;
    align-items: center;
}

.library-card,
#sentenceStrip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
}

.library-card { color: var(--text); }
.library-card:hover, .sentence-card:hover { border-color: var(--border-strong); }
.delete-card, .delete-card-btn, .token-remove { color: #fff; background: var(--danger); }

#toolCursor {
    position: fixed;
    z-index: 9999;
    display: none;
    pointer-events: none;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.resizable-note {
    min-width: 150px;
    min-height: 100px;
    overflow: auto;
    resize: both;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(32, 36, 33, .55);
}

.modal-content {
    width: 90%;
    max-width: 550px;
    max-height: 90vh;
    padding: 24px;
    overflow-y: auto;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(32, 36, 33, .18);
}

.modal-content :is(h3, label, p) { color: var(--text) !important; }

.modal-content :is(input, select, button) {
    color: var(--text) !important;
    background: var(--surface) !important;
    border: 1px solid var(--border-strong) !important;
    border-radius: 6px !important;
}

.modal-content button { box-shadow: none !important; }

.modal-content :is(#saveCardBtn, #addCategoryBtn, #doneCategoryManagerBtn, #appActionConfirm) {
    color: #fff !important;
    background: var(--accent) !important;
    border-color: var(--accent) !important;
}

.modal-content :is([class*="bg-indigo"], [class*="bg-slate"], [class*="bg-gray"]) {
    background-color: var(--surface-soft) !important;
    border-color: var(--border) !important;
}

.modal-overlay.hidden, #cropArea.hidden { display: none; }

.action-dialog-overlay {
    z-index: 12000;
}

.action-page-open { overflow: hidden !important; }

.action-dialog-content {
    max-width: 550px;
}

.action-dialog-header {
    padding-bottom: 2px;
}

.action-dialog-header h3 {
    margin: 0;
    font-size: 1.125rem;
    line-height: 1.2;
}

.action-page-message {
    margin: 0;
    color: var(--muted);
    font-size: .8rem;
    line-height: 1.5;
}

.action-page-input-wrap {
    display: grid;
    gap: 4px;
    color: var(--text);
    font-size: .8rem;
    font-weight: 700;
}

.action-page-input-wrap.hidden { display: none; }

.action-page-input-wrap input {
    width: 100%;
    padding: 8px 12px;
    color: var(--text);
    background: var(--surface-soft);
    border: 1px solid var(--border-strong);
    border-radius: 7px;
}

.action-page-input-wrap input[aria-invalid="true"] { border-color: var(--danger); }

.action-page-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.action-page-actions .quiet-button { min-width: 100px; }
.action-dialog-content[data-tone="danger"] #appActionConfirm {
    color: #fff !important;
    background: var(--danger) !important;
    border-color: var(--danger) !important;
}
.action-dialog-content[data-tone="danger"] #appActionConfirm:hover { background: #743f3b !important; }

.plain-select, .plain-input { padding: 7px 10px; font-size: .85rem; }

.header-options {
    position: relative;
    color: var(--muted);
    font-size: .85rem;
}

.header-menu {
    position: absolute;
    top: 32px;
    right: 0;
    z-index: 100;
    width: 150px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    box-shadow: 0 8px 24px rgba(32, 36, 33, .12);
}

#imageGrid { background: var(--page); }

.sentence-workspace {
    color: var(--text);
    background: rgba(255, 255, 255, .97);
    border-top: 1px solid var(--border);
}

#sentenceStrip { background: var(--surface-soft); }
.sentence-card, .sentence-token { border-color: var(--border); }
.sentence-card:hover { background: var(--surface-soft); }
.text-token { color: #fff; background: var(--accent); }

@media (max-width: 760px) {
    .studio-layout { flex-direction: column; }
    .studio-page .sidebar {
        width: 100% !important;
        height: auto;
        max-height: 44dvh;
        padding: 10px 12px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
    .studio-page #canvas { min-height: 0; }
    .app-header { padding: 0 12px; }
    .quiet-button { min-height: 44px; }
    .preset-row {
        grid-template-columns: repeat(5, 40px);
        justify-content: space-between;
    }
    .preset-color { width: 40px; height: 40px; }
    .modal-overlay { padding: 10px; }
    .modal-content { width: 100%; max-height: calc(100dvh - 20px); padding: 16px; }
    .sentence-workspace { max-height: 48dvh; overflow-y: auto; padding: 10px 12px; }
    .sentence-page #imageGrid { padding: 16px 12px 50dvh; }
    .sentence-workspace > div:last-child,
    .sentence-workspace > div:last-child > div:first-child { width: 100%; }
    .sentence-workspace #customText { width: 100%; min-width: 0; }
    .sentence-page .app-header {
        height: auto;
        min-height: 55px;
        padding-block: 8px;
        flex-wrap: wrap;
    }
    .action-page-actions { flex-direction: column-reverse; }
    .action-page-actions .quiet-button { width: 100%; }
}

@media (max-width: 760px) and (max-height: 500px) {
    .studio-page .sidebar { max-height: 36dvh; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}
