/* BytePaint — main stylesheet.
   Themes via [data-theme] on <html>: dark (default), light, hi-contrast. */

:root,
html[data-theme="dark"] {
    --navy: #06171E;
    --navy-2: #0a2530;
    --navy-3: #0e2f3c;
    --teal: #015351;
    --teal-2: #027571;
    --orange: #FD7D00;
    --white: #FFFFFF;
    --ink: #cfd9de;
    --ink-dim: rgba(207, 217, 222, 0.6);
    --bg: var(--navy);
    --bg-panel: var(--navy-2);
    --bg-elev: var(--navy-3);
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.18);
    --hover: rgba(255, 255, 255, 0.05);
    --active: rgba(253, 125, 0, 0.16);
    --accent: var(--orange);
    --accent-strong: #ff9224;
    --canvas-bg: #2a3a44;
    --danger: #ff6b5a;

    --toolbar-w: 220px;
    --layers-w: 220px;
    --topbar-h: 48px;
    --statusbar-h: 28px;
}

html[data-theme="light"] {
    --navy:    #f4f6f8;
    --navy-2:  #ffffff;
    --navy-3:  #ebeff3;
    --bg:      #f4f6f8;
    --bg-panel:#ffffff;
    --bg-elev: #ebeff3;
    --ink:     #1d2935;
    --ink-dim: rgba(29, 41, 53, 0.6);
    --line: rgba(0, 0, 0, 0.08);
    --line-strong: rgba(0, 0, 0, 0.18);
    --hover: rgba(0, 0, 0, 0.04);
    --active: rgba(253, 125, 0, 0.18);
    --canvas-bg: #e6ebef;
    --accent: #d36900;
    --accent-strong: #fd7d00;
}

html[data-theme="hi-contrast"] {
    --navy: #000000;
    --navy-2: #0a0a0a;
    --navy-3: #1a1a1a;
    --bg: #000000;
    --bg-panel: #0a0a0a;
    --bg-elev: #1a1a1a;
    --ink: #ffffff;
    --ink-dim: #d0d0d0;
    --line: rgba(255, 255, 255, 0.4);
    --line-strong: rgba(255, 255, 255, 0.7);
    --hover: rgba(255, 255, 255, 0.15);
    --active: #ffd000;
    --accent: #ffd000;
    --accent-strong: #ffe040;
    --canvas-bg: #303030;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font: 13px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    overscroll-behavior: none;
}

body {
    display: grid;
    grid-template-rows: var(--topbar-h) 1fr var(--statusbar-h);
    min-height: 100dvh;
    user-select: none;
    -webkit-user-select: none;
}

a { color: var(--accent); }

/* ─── Topbar ──────────────────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: 0.02em; }
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { color: var(--ink); }
.brand-accent { color: var(--accent); }

.topbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.btn {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--hover); border-color: var(--line-strong); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--navy);
    font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.icon-btn { padding: 4px 8px; font-size: 16px; line-height: 1; min-width: 32px; }

/* ─── Stage ───────────────────────────────────────────────────────────── */
.stage {
    display: grid;
    grid-template-columns: var(--toolbar-w) 1fr var(--layers-w);
    min-height: 0;
}

.toolbar, .layers {
    background: var(--bg-panel);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.toolbar { padding: 10px; gap: 10px; border-right: 1px solid var(--line); }
.layers { border-left: 1px solid var(--line); }

/* ─── Tool groups ─────────────────────────────────────────────────────── */
.tool-group {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px 10px;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.tool-group legend {
    padding: 0 6px;
    color: var(--ink);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.tool-row { display: flex; gap: 3px; }
.tool-row-2col { flex-wrap: wrap; }
.tool-row-2col > .tool-btn { flex: 1 1 calc(50% - 2px); }
.tool-row > .tool-btn { flex: 1; }

.tool-btn {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    padding: 5px 2px;
    border: 1px solid var(--line);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    font-size: 11.5px;
    transition: background 0.1s, border-color 0.1s;
    color: var(--ink);
}
.tool-btn > input { position: absolute; opacity: 0; pointer-events: none; }
.tool-btn:hover { background: var(--hover); }
.tool-btn:has(input:checked) {
    background: var(--active);
    border-color: var(--accent);
    color: var(--ink);
}

input[type="color"] {
    width: 100%;
    height: 32px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    padding: 2px;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="number"], input[type="text"], select {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--ink);
    padding: 4px 6px;
    font: inherit;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
    outline: 1px solid var(--accent);
    border-color: var(--accent);
}

.color-sliders { display: flex; flex-direction: column; gap: 3px; }
.cs-row {
    display: grid;
    grid-template-columns: 16px 1fr;
    gap: 6px; align-items: center;
    font-size: 11px; color: var(--ink-dim);
}
.hex-input {
    text-align: center;
    font-family: ui-monospace, Menlo, monospace;
    text-transform: uppercase;
}

.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.palette-recents { grid-template-columns: repeat(8, 1fr); margin-top: 4px; }
.palette-recents::before {
    content: "Recent";
    grid-column: 1 / -1;
    color: var(--ink-dim);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.palette-harmony { grid-template-columns: repeat(5, 1fr); margin-top: 4px; }
.palette-harmony::before {
    content: "Harmony";
    grid-column: 1 / -1;
    color: var(--ink-dim);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.palette-tools { display: flex; gap: 4px; margin-top: 4px; }
.palette-tools select { flex: 1; font-size: 11px; padding: 3px 5px; }
.palette-load {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
}
.swatch {
    aspect-ratio: 1;
    border-radius: 3px;
    border: 1px solid var(--line);
    cursor: pointer;
    padding: 0;
    transition: transform 0.08s, border-color 0.08s;
}
.swatch:hover { transform: scale(1.1); border-color: var(--line-strong); }
.swatch.empty { opacity: 0.2; cursor: default; }
.swatch.empty:hover { transform: none; }

.cb { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ─── Canvas area ─────────────────────────────────────────────────────── */
.canvas-area {
    background:
        radial-gradient(ellipse at center, rgba(253, 125, 0, 0.03), transparent 60%),
        var(--canvas-bg);
    overflow: auto;
    position: relative;
}
.canvas-frame {
    min-width: 100%;
    min-height: 100%;
    padding: 30px;
    display: grid;
    place-items: center;
    position: relative;
}
#view {
    background: transparent;
    border-radius: 2px;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.5),
        0 30px 80px rgba(0, 0, 0, 0.6);
    cursor: crosshair;
    touch-action: none;
    image-rendering: auto;
    transform-origin: top left;
}
.overlay-canvas {
    position: absolute;
    pointer-events: none;
    transform-origin: top left;
    image-rendering: pixelated;
}
body[data-tool="eraser"] #view { cursor: cell; }
body[data-tool="eyedropper"] #view { cursor: copy; }
body[data-tool="hand"] #view, body[data-panning="1"] #view { cursor: grab; }
body[data-panning="2"] #view { cursor: grabbing; }
body[data-tool="marquee"] #view, body[data-tool="lasso"] #view, body[data-tool="wand"] #view { cursor: crosshair; }
body[data-tool="fill"] #view { cursor: pointer; }
body[data-tool="shape"] #view { cursor: crosshair; }
body[data-tool="text"] #view { cursor: text; }
body[data-tool="crop"] #view { cursor: crosshair; }
body[data-tool="move"] #view { cursor: move; }

/* ─── Layers panel ────────────────────────────────────────────────────── */
.layers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.layer-list {
    list-style: none;
    margin: 0; padding: 6px;
    display: flex; flex-direction: column;
    gap: 4px;
}
.layer-item {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: var(--bg);
    cursor: pointer;
    transition: border-color 0.1s, background 0.1s;
}
.layer-item:hover { background: var(--bg-elev); }
.layer-item.active { border-color: var(--accent); background: var(--active); }
.layer-vis {
    width: 22px; height: 22px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    padding: 0; font-size: 13px;
}
.layer-vis.off { opacity: 0.3; }
.layer-thumb {
    width: 28px; height: 28px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background-color: var(--bg-elev);
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    cursor: pointer;
}
.layer-thumb.target {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.layer-thumb-adj {
    display: flex;
    align-items: center; justify-content: center;
    font-weight: 700; font-size: 11px;
    color: var(--accent);
    background-color: var(--bg-elev);
    text-transform: uppercase;
}
.layer-mask-thumb {
    border-style: dashed;
}
.layer-mask-thumb.off { opacity: 0.4; }
.layer-tools-row {
    grid-column: 1 / -1;
    display: flex;
    gap: 3px;
    margin-top: 4px;
}
.layer-mini-btn {
    width: 22px; height: 18px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: transparent;
    color: var(--ink-dim);
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    padding: 0;
}
.layer-mini-btn:hover { color: var(--ink); background: var(--hover); }
.layer-mini-btn.locked { color: var(--accent); border-color: var(--accent); }
.layers-header-actions { display: flex; gap: 4px; }
.layers-header-actions .icon-btn { padding: 2px 6px; font-size: 12px; min-width: 24px; }

/* fx menu (add adjustment) */
.fx-menu {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.5);
    padding: 4px;
    z-index: 9000;
    min-width: 180px;
}
.fx-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: var(--ink);
    padding: 6px 10px;
    border-radius: 3px;
    cursor: pointer;
    font: inherit;
}
.fx-menu button:hover { background: var(--hover); }

/* Filter menu (drop-down list of filters) */
.filter-menu {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.5);
    padding: 4px;
    z-index: 9000;
    min-width: 200px;
    max-height: 70vh;
    overflow-y: auto;
}
.filter-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: var(--ink);
    padding: 6px 10px;
    border-radius: 3px;
    cursor: pointer;
    font: inherit;
}
.filter-menu button:hover { background: var(--hover); }

/* Filter dialog */
.filter-dialog { max-width: 760px; width: min(760px, 96vw); }
.filter-grid {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: 16px;
    align-items: start;
}
.filter-preview {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.filter-preview canvas { max-width: 100%; max-height: 480px; image-rendering: auto; }
.filter-controls { display: flex; flex-direction: column; gap: 10px; }
.filter-row { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.filter-row span { display: flex; justify-content: space-between; color: var(--ink-dim); }

@media (max-width: 720px) {
    .filter-grid { grid-template-columns: 1fr; }
}

/* Adjustment editor overlay */
.adj-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9100;
    display: flex; align-items: flex-start; justify-content: flex-end;
    padding: 80px 30px;
    pointer-events: auto;
}
.adj-card {
    background: var(--bg-panel);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 16px;
    min-width: 280px;
    color: var(--ink);
    box-shadow: 0 16px 40px rgba(0,0,0,0.5);
}
.adj-card h3 { margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.adj-rows { display: flex; flex-direction: column; gap: 10px; }
.adj-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    font-size: 12px;
}
.adj-row span { display: flex; justify-content: space-between; color: var(--ink-dim); }
.adj-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 14px; }
.layer-name {
    background: transparent;
    border: 0;
    color: var(--ink);
    font: inherit;
    width: 100%;
    padding: 2px 0;
    min-width: 0;
}
.layer-name:focus { outline: 1px solid var(--accent); border-radius: 2px; }
.layer-actions { display: flex; gap: 2px; flex-direction: column; }
.layer-actions button {
    width: 18px; height: 18px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    padding: 0;
    font-size: 10px;
    line-height: 1;
}
.layer-actions button:hover { background: var(--hover); }
.layer-opacity-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    margin-top: 4px;
    font-size: 10px;
    color: var(--ink-dim);
    align-items: center;
}
.layer-opacity-row select { padding: 1px 4px; font-size: 11px; }
.layer-opacity { width: 100%; }

/* ─── Statusbar ───────────────────────────────────────────────────────── */
.statusbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    font-size: 11px;
    color: var(--ink-dim);
    background: var(--bg-panel);
    border-top: 1px solid var(--line);
}
.statusbar-spacer { flex: 1; }
.statusbar-link { color: var(--ink-dim); text-decoration: none; }
.statusbar-link:hover { color: var(--accent); }
.statusbar-sep { color: var(--ink-dim); opacity: 0.4; }

/* ─── Dialogs ─────────────────────────────────────────────────────────── */
.dlg {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--bg-panel);
    color: var(--ink);
    padding: 0;
    max-width: 420px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
.dlg-wide { max-width: 560px; width: min(560px, 92vw); }
.dlg::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(2px); }
.dlg-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg h2 { margin: 0; color: var(--ink); font-size: 16px; font-weight: 600; }
.dlg-hint { margin: 0; color: var(--ink-dim); font-size: 12px; }
.dlg-row { display: flex; flex-direction: column; gap: 4px; }
.dlg-row-2 { flex-direction: row; gap: 10px; }
.dlg-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-dim); }
.dlg-row > label.cb { flex-direction: row; align-items: center; color: var(--ink); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dlg-panel { display: flex; flex-direction: column; gap: 14px; }
.muted { color: var(--ink-dim); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -8px 0 4px; }
.tab {
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    color: var(--ink-dim);
    padding: 8px 12px;
    cursor: pointer;
    font: inherit;
}
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tab:hover { color: var(--ink); }

/* ─── Tour overlay ────────────────────────────────────────────────────── */
.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 9500;
    background: rgba(0, 0, 0, 0.6);
}
.tour-spotlight {
    position: fixed;
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    transition: all 0.18s ease;
}
.tour-card {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 16px;
    max-width: 320px;
    color: var(--ink);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    z-index: 9510;
}
.tour-title { margin: 0 0 6px; font-size: 15px; }
.tour-body { margin: 0 0 12px; color: var(--ink-dim); }
.tour-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ─── Info-pages (imprint/privacy/about/shortcuts) ───────────────────── */
body.info-page {
    display: block;
    background: var(--bg);
    color: var(--ink);
}
.info-shell {
    max-width: 720px;
    margin: 0 auto;
    padding: 40px 24px 80px;
    line-height: 1.6;
}
.info-shell h1 { color: var(--ink); }
.info-shell h2 { color: var(--ink); margin-top: 2em; font-size: 16px; text-transform: uppercase; letter-spacing: 0.06em; }
.info-shell a { color: var(--accent); }
.info-back {
    display: inline-block;
    margin-bottom: 30px;
    text-decoration: none;
    color: var(--ink-dim);
}
.info-foot {
    margin-top: 4em;
    border-top: 1px solid var(--line);
    padding-top: 1em;
    color: var(--ink-dim);
}

table.shortcuts {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
table.shortcuts th, table.shortcuts td {
    border-bottom: 1px solid var(--line);
    padding: 6px 8px;
    text-align: left;
}
table.shortcuts thead th {
    background: var(--bg-elev);
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11px;
}
table.shortcuts td.group {
    background: var(--bg-panel);
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 11px;
}
kbd {
    background: var(--bg-elev);
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    padding: 1px 6px;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 11px;
    color: var(--ink);
}

/* ─── Crash modal ─────────────────────────────────────────────────────── */
.crash-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}
.crash-card {
    background: var(--bg-panel);
    border: 1px solid var(--danger, #ff6b5a);
    border-radius: 8px;
    padding: 22px;
    max-width: 520px;
    color: var(--ink);
}
.crash-card h2 { color: var(--danger, #ff6b5a); margin-top: 0; }
.crash-err {
    background: var(--bg);
    border-radius: 4px;
    padding: 10px;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 11px;
    max-height: 220px;
    overflow: auto;
    color: var(--ink-dim);
    white-space: pre-wrap;
}
.crash-actions { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.crash-actions button {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--line-strong);
    color: var(--ink);
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
}
.crash-actions button[data-act="save"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--navy);
    font-weight: 600;
}

/* ─── Selection marching ants ─────────────────────────────────────────── */
@keyframes marching-ants {
    0% { stroke-dashoffset: 0; }
    100% { stroke-dashoffset: 8; }
}

/* ─── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
    :root { --toolbar-w: 1fr; --layers-w: 1fr; }
    .stage {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    .toolbar {
        flex-direction: row;
        flex-wrap: wrap;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        max-height: 38vh;
        padding: 8px;
        gap: 8px;
    }
    .tool-group { flex: 1 1 140px; min-width: 140px; }
    .layers {
        border-left: 0;
        border-top: 1px solid var(--line);
        max-height: 28vh;
    }
    .topbar-actions .btn { padding: 5px 8px; font-size: 12px; }
    .topbar-actions #btn-new,
    .topbar-actions #btn-print { display: none; }
}

/* ─── Print ───────────────────────────────────────────────────────────── */
@media print {
    body { display: block; background: white; }
    .topbar, .toolbar, .layers, .statusbar, dialog, .tour-overlay { display: none; }
    .stage { display: block; }
    .canvas-area { background: white; overflow: visible; }
    .canvas-frame { padding: 0; }
    #view { box-shadow: none; max-width: 100%; height: auto; transform: none !important; }
}
