/* Michi Binder Builder — styles. Tokens match the main woahpoke app. */

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

:root, [data-theme="dark"] {
    --bg-primary: #0e0e10;
    --bg-secondary: #18181b;
    --bg-tertiary: #232327;
    --bg-hover: #2f2f35;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.14);
    --text-primary: #f5f5f3;
    --text-secondary: #a3a29e;
    --text-muted: #6f6e69;
    --accent: #9d5cff;
    --accent-hover: #b07fff;
    --accent-subtle: rgba(157, 92, 255, 0.13);
    --accent-glow: rgba(157, 92, 255, 0.28);
    --success: #69db7c;
    --danger: #ff6b6b;
    --warning: #ffd43b;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
    --card-shadow: 0 10px 20px -12px rgba(0, 0, 0, 0.75), 0 2px 6px -2px rgba(0, 0, 0, 0.5);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --font-body: 'Instrument Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-display: 'Bricolage Grotesque', var(--font-body);
    --panel-w: 290px;
    color-scheme: dark;
}

[data-theme="light"] {
    --bg-primary: #f6f5f2;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eeede9;
    --bg-hover: #e5e3de;
    --border-color: rgba(30, 28, 25, 0.1);
    --border-light: rgba(30, 28, 25, 0.18);
    --text-primary: #1e1c19;
    --text-secondary: #605d57;
    --text-muted: #97948c;
    --accent: #6d33d6;
    --accent-hover: #5b28b8;
    --accent-subtle: rgba(109, 51, 214, 0.09);
    --accent-glow: rgba(109, 51, 214, 0.22);
    --success: #1f9d4d;
    --danger: #dc3b30;
    --warning: #b7791f;
    --shadow: 0 4px 20px rgba(25, 23, 20, 0.1);
    --shadow-lg: 0 12px 40px rgba(25, 23, 20, 0.18);
    --card-shadow: 0 10px 20px -12px rgba(25, 23, 20, 0.45), 0 2px 6px -2px rgba(25, 23, 20, 0.2);
    color-scheme: light;
}

html, body { height: 100%; }

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; font-weight: 700; }
h2 { font-size: 15px; }
h3 { font-size: 18px; }
.panel h3 { font-size: 15px; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- header */

.topbar {
    height: 56px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 20;
}
.page-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.brand { display: flex; align-items: center; color: var(--text-primary); }
.brand-logo {
    display: block;
    width: 112px;
    height: 24px;
    background: currentColor;
    -webkit-mask: url(../assets/woahpoke-logo.svg) no-repeat left center / contain;
    mask: url(../assets/woahpoke-logo.svg) no-repeat left center / contain;
}
.brand-divider { width: 1px; height: 22px; background: var(--border-light); }
.binder-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 16px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    min-width: 0;
    width: 180px;
    flex-shrink: 0;
}
.binder-name:hover { border-color: var(--border-color); }
.binder-name:focus { outline: none; border-color: var(--accent); background: var(--bg-tertiary); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.save-status { font-size: 12px; color: var(--text-muted); margin-right: 8px; white-space: nowrap; }
.icon-btn {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius);
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
}
.icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.mobile-only { display: none; }

/* ---------------------------------------------------------------- 3-column layout */

.app {
    display: grid;
    grid-template-columns: var(--panel-w) minmax(0, 1fr) var(--panel-w);
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
}

.panel {
    background: var(--bg-secondary);
    overflow-y: auto;
    padding: 8px 18px 24px;
    scrollbar-width: thin;
}
.panel-left { border-right: 1px solid var(--border-color); }
.panel-right { border-left: 1px solid var(--border-color); }

.panel-section { padding: 16px 0; border-bottom: 1px solid var(--border-color); display: flex; flex-direction: column; gap: 10px; }
.panel-section:last-of-type { border-bottom: none; }
.section-head { display: flex; align-items: center; justify-content: space-between; }

.disclosure { gap: 0; }
.disclosure > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::after { content: ''; width: 8px; height: 8px; border-right: 2px solid var(--text-muted); border-bottom: 2px solid var(--text-muted); transform: rotate(45deg); transition: transform var(--transition); margin-right: 4px; }
.disclosure[open] > summary::after { transform: rotate(-135deg); }
.disclosure[open] > summary { margin-bottom: 10px; }
.disclosure > *:not(summary) + * { margin-top: 10px; }

.hint { font-size: 12px; color: var(--text-secondary); line-height: 1.45; }
.hint.small { font-size: 11px; color: var(--text-muted); }

.preset-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.preset {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 10px 4px 8px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    background: var(--bg-tertiary);
    transition: all var(--transition);
}
.preset b { font-size: 11px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.preset .mini {
    display: grid;
    grid-template-columns: repeat(var(--c), 7px);
    grid-template-rows: repeat(var(--r), 10px);
    gap: 2px;
    height: 34px;
    align-content: center;
}
.preset .mini i { background: var(--text-muted); border-radius: 1.5px; opacity: 0.55; }
.preset:hover { border-color: var(--accent); }
.preset.active { border-color: var(--accent); background: var(--accent-subtle); box-shadow: inset 0 0 0 1px var(--accent); }
.preset.active b { color: var(--text-primary); }
.preset.active .mini i { background: var(--accent); opacity: 1; }

.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatches > * {
    position: relative;
    display: block;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--sw);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
}
.swatches > *:hover { transform: scale(1.1); }
/* Selected: white ring drawn inside the swatch, so it never touches its neighbours. */
.swatches > .active::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}
.swatch-custom { background: none; }
.swatch-custom::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: conic-gradient(from 0deg, #ff6b6b, #ffd43b, #69db7c, #4dabf7, #9d5cff, #ff6b6b);
    pointer-events: none;
}
/* the real colour input stays clickable but invisible */
.swatch-custom input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    border: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    clip-path: circle(50%);
}

.planner-box { background: var(--accent-subtle); border-radius: var(--radius-lg); padding: 14px; border: none; margin-top: 8px; gap: 6px; }
.planner-box b { color: var(--text-primary); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.field input, .field select {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 7px 10px;
    min-height: 36px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.color-field input { padding: 3px; height: 36px; cursor: pointer; }

.paper-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--text-muted); gap: 8px; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 12px; padding: 2px 0; }
.link-btn:hover { text-decoration: underline; }

.check-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; font-weight: 500; cursor: pointer; }

/* toggle switch */
.switch { position: relative; display: inline-flex; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { width: 38px; height: 22px; border-radius: 999px; background: var(--bg-hover); border: 1px solid var(--border-light); position: relative; transition: background var(--transition); }
.switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text-secondary); transition: transform var(--transition), background var(--transition); }
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 14px;
    min-height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 13px;
    transition: all var(--transition);
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); }
.btn-small { min-height: 30px; padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); }
.btn-block { width: 100%; min-height: 44px; font-size: 14px; }
.btn-stack { display: grid; gap: 6px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 4px; }
.stats div { background: var(--bg-tertiary); border-radius: var(--radius); padding: 8px 4px; text-align: center; display: flex; flex-direction: column; }
.stats b { font-family: var(--font-display); font-size: 17px; line-height: 1.1; }
.stats span { font-size: 10px; color: var(--text-muted); line-height: 1.2; margin-top: 2px; }

/* Michi panel */
.michi-section { position: relative; }
.michi-help { display: flex; flex-direction: column; gap: 8px; padding: 12px; border-radius: var(--radius-lg); background: var(--accent-subtle); border: 1px solid transparent; transition: border-color var(--transition); }
.michi-on .michi-help { border-color: var(--accent); }
.michi-help ol { padding-left: 18px; font-size: 12.5px; display: grid; gap: 4px; }
.size-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.size-grid button { padding: 6px 0; border-radius: var(--radius-sm); background: var(--bg-tertiary); border: 1px solid var(--border-light); font-weight: 600; font-size: 12px; }
.size-grid button:hover { border-color: var(--accent); }
.size-grid button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.print-summary { font-size: 12.5px; color: var(--text-secondary); background: var(--bg-tertiary); border-radius: var(--radius); padding: 10px 12px; }
.print-summary b { color: var(--text-primary); }
.print-summary .warn { color: var(--danger); }
.michi-help a { color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- guide (below the tool) */

.guide { border-top: 1px solid var(--border-color); background: var(--bg-primary); }
.guide-inner { max-width: 720px; margin: 0 auto; padding: 56px 20px 40px; display: grid; gap: 44px; }
.guide h2 { font-size: 26px; line-height: 1.2; margin-bottom: 14px; }
.guide p, .guide li { font-size: 16px; line-height: 1.65; color: var(--text-secondary); }
.guide p + p { margin-top: 12px; }
.guide b { color: var(--text-primary); font-weight: 600; }
.guide em { font-style: normal; color: var(--text-primary); }
.guide ul, .guide ol { padding-left: 22px; display: grid; gap: 10px; }
.guide li::marker { color: var(--accent); font-weight: 700; }
.faq details { border-bottom: 1px solid var(--border-color); padding: 14px 0; }
.faq summary { font-weight: 600; font-size: 16px; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 16px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: '+'; color: var(--accent); font-size: 20px; line-height: 1; }
.faq details[open] summary::after { content: '−'; }
.faq details p { margin-top: 8px; }
.more-card { display: block; padding: 16px 18px; border: 1px solid var(--border-light); border-radius: var(--radius-lg); text-decoration: none; color: inherit; transition: border-color var(--transition); }
.more-card:hover { border-color: var(--accent); }
.more-card b { display: block; color: var(--text-primary); font-family: var(--font-display); font-size: 17px; }
.more-card span { color: var(--text-secondary); font-size: 14px; }

.site-footer { border-top: 1px solid var(--border-color); padding: 28px 20px 40px; text-align: center; }
.site-footer p { max-width: 760px; margin: 0 auto; font-size: 12.5px; line-height: 1.6; color: var(--text-secondary); }
.site-footer p + p { margin-top: 8px; }
.site-footer a { color: var(--text-primary); font-weight: 600; }

/* ---------------------------------------------------------------- center */

.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.center-head { display: flex; align-items: center; gap: 8px; padding: 0 0 0 10px; min-width: 0; flex-shrink: 0; }
.page-tabs {
    display: flex; align-items: center; gap: 6px;
    padding: 12px 16px 12px 0;
    min-width: 0;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
}
.page-tabs::-webkit-scrollbar { display: none; }
.page-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    border: 1px solid transparent;
    transition: all var(--transition);
}
.page-tab em { font-style: normal; font-size: 11px; background: var(--bg-hover); color: var(--text-secondary); padding: 0 6px; border-radius: 999px; }
.page-tab:hover { color: var(--text-primary); background: var(--bg-tertiary); }
.page-tab.active { background: var(--text-primary); color: var(--bg-primary); }
.page-tab.active em { background: rgba(127, 127, 127, 0.25); color: inherit; }
.page-tab.drop-hover { border-color: var(--accent); background: var(--accent-subtle); color: var(--text-primary); }
.tab-del { margin-left: 2px; width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-size: 15px; line-height: 1; opacity: 0.6; }
.tab-del:hover { opacity: 1; background: rgba(127, 127, 127, 0.3); }
.add-tab svg { width: 15px; height: 15px; }

.stage {
    flex: 1;
    min-height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 16px;
}

/* the binder page */
.binder {
    --cell-w: 120px; --cell-h: 168px; --pad: 16px; --gap: 8px;
    display: grid;
    grid-template-columns: repeat(var(--cols, 3), var(--cell-w));
    grid-template-rows: repeat(var(--rows, 3), var(--cell-h));
    gap: var(--gap);
    padding: var(--pad);
    padding-left: calc(var(--pad) + var(--spine, 0px));
    background:
        linear-gradient(rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0.32)),
        var(--binder-color, #6d33d6);
    border-radius: 6px 16px 16px 6px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: var(--shadow-lg);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}
.binder::before {
    /* ring holes along the spine, like a real binder page */
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: var(--spine, 0px);
    background:
        radial-gradient(circle at 50% 22%, var(--bg-primary) 0 5px, rgba(255,255,255,0.18) 5.5px 6.5px, transparent 7px),
        radial-gradient(circle at 50% 50%, var(--bg-primary) 0 5px, rgba(255,255,255,0.18) 5.5px 6.5px, transparent 7px),
        radial-gradient(circle at 50% 78%, var(--bg-primary) 0 5px, rgba(255,255,255,0.18) 5.5px 6.5px, transparent 7px);
    border-right: 1px solid rgba(0, 0, 0, 0.25);
    pointer-events: none;
}
.binder.michi { box-shadow: 0 0 0 2px var(--accent), var(--shadow-lg); }

.pocket {
    position: relative;
    border-radius: calc(var(--cell-w) * 0.05);
    background: rgba(0, 0, 0, 0.28);
    border: 1.5px dashed rgba(255, 255, 255, 0.2);
    overflow: hidden;
    transition: border-color var(--transition), background var(--transition), transform var(--transition);
}
.pocket.empty { cursor: pointer; }
.pocket.empty:hover { border-color: rgba(255, 255, 255, 0.5); }
.pocket.selected { border: 2px solid var(--accent); background: var(--accent-subtle); }
.pocket.selected::after { content: 'Tap a card below'; position: absolute; inset: auto 0 8px; text-align: center; font-size: 11px; font-weight: 600; color: var(--accent); }
.compact .pocket.selected::after { display: none; }
.pocket.filled { border: none; background: transparent; cursor: grab; box-shadow: var(--card-shadow); }
.pocket.filled img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.pocket.filled::after, .michi-tile[style*="background-image"]::after {
    /* soft sleeve glare */
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(125deg, rgba(255,255,255,0.16) 0%, rgba(255,255,255,0.04) 28%, transparent 42%, transparent 70%, rgba(255,255,255,0.06) 100%);
    pointer-events: none;
    border-radius: inherit;
}
.pocket.img-error { background: var(--bg-tertiary); }
.pocket.img-error img { opacity: 0; }
.pocket.img-error::before { content: attr(title); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px; font-size: 11px; color: var(--text-secondary); }
.pocket-remove {
    position: absolute; top: 5px; right: 5px;
    width: 24px; height: 24px; border-radius: 50%;
    background: rgba(0, 0, 0, 0.72); color: #fff;
    font-size: 16px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity var(--transition);
}
.pocket.filled:hover .pocket-remove, .pocket-remove:focus-visible { opacity: 1; }
@media (hover: none) { .pocket-remove { opacity: 0.85; } }
.pocket.just-added { animation: pop 320ms ease-out; }
@keyframes pop { 0% { transform: scale(0.88); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }

.michi .pocket.empty { border-color: var(--accent-glow); cursor: crosshair; }
.michi .pocket.empty:hover { border-color: var(--accent); background: var(--accent-subtle); }
.michi .pocket.filled { opacity: 0.45; cursor: not-allowed; }
.pocket-plus { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 22px; opacity: 0.5; }

/* Michi blocks */
.michi-block {
    position: relative;
    border-radius: calc(var(--cell-w) * 0.05);
    cursor: grab;
}
.michi-tiles {
    display: grid;
    grid-template-columns: repeat(var(--bw), 1fr);
    grid-template-rows: repeat(var(--bh), 1fr);
    gap: var(--gap);
    width: 100%; height: 100%;
}
.michi-tile {
    position: relative;
    border-radius: calc(var(--cell-w) * 0.05);
    background-color: var(--accent-subtle);
    border: 1.5px solid var(--accent);
    background-repeat: no-repeat;
    box-shadow: var(--card-shadow);
}
.michi-tile[style*="background-image"] { border: none; }
.michi-block.file-over .michi-tile { outline: 3px solid var(--accent); }
.michi-empty {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    color: var(--accent); font-weight: 700; font-size: 13px;
}
.michi-empty svg { width: 28px; height: 28px; }
.michi-empty small { font-weight: 500; font-size: 11px; color: var(--text-secondary); }
.michi-empty:hover { background: var(--accent-subtle); border-radius: inherit; }
.michi-actions {
    position: absolute; top: 6px; right: 6px;
    display: flex; gap: 4px;
    opacity: 0; transition: opacity var(--transition);
}
.michi-block:hover .michi-actions, .michi-actions:focus-within { opacity: 1; }
@media (hover: none) { .michi-actions { opacity: 1; } }
.michi-actions button {
    height: 26px; min-width: 26px; padding: 0 9px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.75); color: #fff;
    font-size: 12px; font-weight: 600;
}
.michi-actions button:hover { background: var(--accent); }
.michi-actions button[data-act="remove"] { font-size: 16px; padding: 0; }
.michi-badge {
    position: absolute; left: 6px; bottom: 6px;
    background: var(--accent); color: #fff;
    font-size: 11px; font-weight: 700;
    padding: 1px 7px; border-radius: 999px;
    pointer-events: none;
}

/* drag-select + drop previews */
.select-rect, .drop-rect {
    pointer-events: none;
    border-radius: calc(var(--cell-w) * 0.05);
    z-index: 5;
}
.select-rect { background: var(--accent-glow); border: 2px solid var(--accent); position: relative; }
.select-rect::after { content: attr(data-label); position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--accent); color: #fff; font-weight: 700; padding: 2px 10px; border-radius: 999px; font-size: 13px; }
.select-rect.bad, .drop-rect.bad { background: rgba(255, 107, 107, 0.18); border-color: var(--danger); }
.select-rect.bad::after { background: var(--danger); content: 'Not empty'; }
.drop-rect { border: 2px solid var(--accent); background: var(--accent-subtle); }
.drop-rect.swap { border-style: dashed; }

.planner-note {
    margin-top: 12px;
    display: flex; align-items: center; gap: 8px;
    padding: 6px 6px 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 999px;
    font-size: 12px; color: var(--text-secondary);
    box-shadow: var(--shadow);
    white-space: nowrap;
    max-width: calc(100% - 24px);
    z-index: 4;
}
.planner-note span { overflow: hidden; text-overflow: ellipsis; }
.planner-note svg { width: 15px; height: 15px; color: var(--accent); }
.note-close { width: 22px; height: 22px; border-radius: 50%; font-size: 15px; line-height: 1; color: var(--text-muted); flex-shrink: 0; }
.note-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.stage-banner {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
    background: var(--accent); color: #fff;
    padding: 6px 8px 6px 14px; border-radius: 999px;
    font-size: 12.5px; font-weight: 600;
    display: flex; align-items: center; gap: 10px;
    box-shadow: var(--shadow);
    white-space: nowrap;
    z-index: 6;
}
.stage-banner .dot { width: 7px; height: 7px; background: #fff; border-radius: 50%; animation: blink 1.4s infinite; }
.stage-banner .link-btn { color: #fff; background: rgba(255, 255, 255, 0.2); padding: 2px 10px; border-radius: 999px; }
@keyframes blink { 50% { opacity: 0.3; } }

/* drag ghost */
.drag-ghost {
    position: fixed; left: 0; top: 0;
    z-index: 1000;
    pointer-events: none;
    background-size: cover; background-position: center;
    border-radius: 6px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
    opacity: 0.95;
}
.drag-ghost.ghost-block { background-size: cover; }
.is-dragging, .is-dragging * { cursor: grabbing !important; }
.drag-source { opacity: 0.35; }

/* ---------------------------------------------------------------- search panel */

.search-panel {
    flex-shrink: 0;
    height: clamp(220px, 34vh, 340px);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    transition: background var(--transition);
}
.search-panel.remove-hover { background: rgba(255, 107, 107, 0.12); }
.search-panel.remove-hover .search-meta::before { content: 'Drop here to remove from binder · '; color: var(--danger); font-weight: 600; }
.search-bar { display: flex; gap: 8px; padding: 12px 16px 6px; align-items: center; }
.search-input {
    flex: 1; min-width: 0;
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 0 12px;
    height: 40px;
    color: var(--text-muted);
}
.search-input:focus-within { border-color: var(--accent); }
.search-input input { flex: 1; min-width: 0; border: none; background: none; outline: none; height: 100%; color: var(--text-primary); font-size: 14px; }
.set-picker { position: relative; width: 210px; flex-shrink: 0; }
.set-picker input {
    width: 100%; height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 0 30px 0 12px;
}
.set-picker input:focus { outline: none; border-color: var(--accent); }
.clear-set { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; border-radius: 50%; font-size: 17px; color: var(--text-secondary); }
.clear-set:hover { background: var(--bg-hover); }
.search-meta { padding: 0 16px 8px; font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results { flex: 1; overflow-y: auto; padding: 0 16px 16px; scrollbar-width: thin; }
.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px; }
.result {
    cursor: grab;
    border-radius: var(--radius);
    padding: 4px;
    transition: background var(--transition), transform var(--transition);
    touch-action: pan-y;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
}
.result:hover { background: var(--bg-tertiary); }
.result:hover .result-img { transform: translateY(-2px); }
.result-img { aspect-ratio: 63.5 / 88.9; border-radius: 5px; overflow: hidden; background: var(--bg-tertiary); box-shadow: var(--card-shadow); transition: transform var(--transition); }
.result-img img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.result.img-error .result-img::after { content: 'No image'; display: flex; height: 100%; align-items: center; justify-content: center; font-size: 11px; color: var(--text-muted); }
.result.img-error img { display: none; }
.result-name { font-size: 12px; font-weight: 600; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-set { font-size: 10.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result.skeleton { aspect-ratio: 63.5 / 88.9; background: var(--bg-tertiary); animation: shimmer 1.2s infinite ease-in-out; cursor: default; }
@keyframes shimmer { 50% { opacity: 0.5; } }
.results-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; color: var(--text-secondary); padding: 12px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border-light); background: var(--bg-tertiary); font-size: 12.5px; font-weight: 600; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.load-more { display: flex; margin: 16px auto 0; }

/* ---------------------------------------------------------------- modals */

.modal {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: min(760px, 100%);
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    display: flex; flex-direction: column;
    padding: 20px;
    gap: 14px;
}
.modal-small { width: min(420px, 100%); }
.modal-small p { color: var(--text-secondary); }
.modal-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.modal-sub { font-size: 12.5px; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.crop-wrap { height: min(60vh, 520px); background: #000; border-radius: var(--radius); overflow: hidden; }
.crop-wrap img { display: block; max-width: 100%; }
.crop-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); margin-left: auto; cursor: pointer; }
.crop-pockets { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--w), 1fr); grid-template-rows: repeat(var(--h), 1fr); pointer-events: none; }
.crop-pockets span { border: 1px dashed rgba(255, 255, 255, 0.7); }
.cropper-view-box { outline-color: var(--accent); }
.cropper-point, .cropper-line { background-color: var(--accent); }
.modal-open { overflow: hidden; }

/* ---------------------------------------------------------------- toasts */

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 200; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
    pointer-events: auto;
    background: var(--text-primary); color: var(--bg-primary);
    padding: 10px 16px; border-radius: 999px;
    font-size: 13px; font-weight: 600;
    box-shadow: var(--shadow-lg);
    display: flex; align-items: center; gap: 12px;
    opacity: 0; transform: translateY(8px);
    transition: opacity 200ms, transform 200ms;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--danger); color: #fff; }
.toast-warn { background: var(--warning); color: #1e1c19; }
.toast-success::before { content: '✓'; color: var(--success); }
.toast-action { color: var(--accent); font-weight: 700; text-decoration: underline; }
[data-theme="light"] .toast-action { color: #c9a7ff; }
.toast-error .toast-action, .toast-warn .toast-action { color: inherit; }

.scrim { position: fixed; inset: 56px 0 0; background: rgba(0, 0, 0, 0.5); z-index: 29; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1180px) {
    :root { --panel-w: 250px; }
    .set-picker { width: 170px; }
}

@media (max-width: 900px) {
    .mobile-only { display: inline-flex; }
    .save-status { display: none; }
    .app { grid-template-columns: minmax(0, 1fr); }
    .panel {
        position: fixed; top: 56px; bottom: 0;
        width: min(340px, 88vw);
        z-index: 30;
        transition: transform 220ms ease;
        box-shadow: var(--shadow-lg);
    }
    .panel-left { left: 0; transform: translateX(-102%); }
    .panel-right { right: 0; transform: translateX(102%); }
    .drawer-left .panel-left, .drawer-right .panel-right { transform: none; }
    .stage { padding: 8px; }
    .search-panel { height: clamp(210px, 38vh, 320px); }
    .search-bar { flex-wrap: wrap; padding: 10px 12px 6px; }
    .search-input { flex-basis: 100%; }
    .set-picker { flex: 1; width: auto; }
    .results { padding: 0 12px 12px; }
    .results-grid { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
    .page-tabs { padding: 8px 12px; }
    .binder-name { width: 120px; }
    .page-title { font-size: 13px; }
    .guide-inner { padding: 40px 16px 32px; gap: 36px; }
    .guide h2 { font-size: 22px; }
    .brand-logo { width: 88px; }
    .stage-banner { font-size: 11.5px; top: 4px; }
}

@media (max-width: 480px) {
    .brand-divider { display: none; }
    .brand-logo { width: 74px; }
    .binder-name { font-size: 14px; width: 104px; }
    .page-title { font-size: 12px; }
    .icon-btn { width: 32px; height: 32px; }
}

/* ---------------------------------------------------------------- eBay links */

.result { position: relative; }
.result-ebay {
    display: inline-flex; align-items: center; gap: 3px;
    margin-top: 3px;
    font-size: 11px; font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition);
}
.result-ebay svg { width: 10px; height: 10px; stroke-width: 2.5; }
.result-ebay:hover, .result:hover .result-ebay { color: var(--accent); }
.result-ebay:hover { text-decoration: underline; }

.pocket-ebay {
    position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 3px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.78); color: #fff;
    font-size: 11px; font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    opacity: 0; transition: opacity var(--transition), background var(--transition);
    z-index: 2;
}
.pocket-ebay svg { width: 10px; height: 10px; stroke-width: 2.5; }
.pocket.filled:hover .pocket-ebay, .pocket-ebay:focus-visible { opacity: 1; }
.pocket-ebay:hover { background: var(--accent); }
.compact .pocket-ebay { display: none; }
@media (hover: none) { .pocket-ebay { display: none; } }

/* in / mm toggle */
.unit-toggle { display: inline-flex; background: var(--bg-tertiary); border: 1px solid var(--border-light); border-radius: 999px; padding: 2px; }
.unit-toggle button { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.unit-toggle button[aria-pressed="true"] { background: var(--text-primary); color: var(--bg-primary); }
