:root {
    --bg: #0f1115;
    --panel: #181b22;
    --panel-2: #20242d;
    --border: #2b313c;
    --text: #e6e9ef;
    --muted: #8b93a3;
    --accent: #5b8cff;
    --accent-2: #3f6fe0;
    --success: #2faa6a;
    --danger: #e05656;
    --rail-w: 84px;
    --panel-w: 290px;
    --header-h: 60px;
    --footer-h: 132px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over component display rules below. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
}
main { height: 100vh; }

/* ---- Fixed app shell -------------------------------------------------- */
.app {
    height: 100vh;
    display: grid;
    grid-template-rows: var(--header-h) 1fr var(--footer-h);
}

.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
    display: inline-grid; place-items: center;
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--accent); color: #fff; font-size: 14px;
}
.app-header h1 { margin: 0; font-size: 18px; font-weight: 600; }
.wordmark {
    font-family: "M PLUS Rounded 1c", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: clamp(22px, 2.5vw, 32px) !important;
    line-height: 1;
    color: var(--text);
    display: inline-block;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    text-rendering: geometricPrecision;
}
.header-actions { display: flex; align-items: center; gap: 10px; }

/* ---- Workspace: rail | panel | stage ---------------------------------- */
.workspace {
    display: grid;
    grid-template-columns: var(--rail-w) var(--panel-w) 1fr;
    min-height: 0;
}

/* Left tool rail */
.rail {
    display: flex; flex-direction: column; gap: 4px;
    padding: 12px 8px;
    background: var(--panel);
    border-right: 1px solid var(--border);
}
.rail-btn {
    appearance: none; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    padding: 12px 4px;
    background: transparent; color: var(--muted);
    border: 1px solid transparent; border-radius: 12px;
    font-size: 12px; transition: background .12s, color .12s;
}
.rail-btn:hover { background: var(--panel-2); color: var(--text); }
.rail-btn.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.rail-btn.active .rail-icon { color: var(--accent); }
.rail-icon { font-size: 22px; line-height: 1; }
.rail-label { font-weight: 500; }

/* Tool panel */
.tool-panel {
    padding: 16px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}
.tool { display: block; }
.tool-head { display: flex; align-items: center; justify-content: space-between; }
.tool h2 { margin: 0 0 4px; font-size: 17px; }
.muted { color: var(--muted); font-size: 13px; margin: 8px 0 14px; line-height: 1.5; }
kbd {
    background: var(--panel-2); border: 1px solid var(--border); border-bottom-width: 2px;
    border-radius: 4px; padding: 1px 5px; font-size: 11px; font-family: inherit; color: var(--text);
}
.readout { font-variant-numeric: tabular-nums; font-size: 14px; margin: 12px 0; color: var(--text); }
.muted-readout { color: var(--muted); }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }

.speed-control { display: flex; align-items: center; justify-content: space-between; margin: 10px 0; }
.speed-value { font-size: 26px; font-variant-numeric: tabular-nums; }

.slice-actions { display: flex; gap: 8px; margin: 12px 0; }
.slice-actions .btn { flex: 1; }

/* Per-tool Apply button, separated from the controls above it. */
.panel-apply {
    display: block;
    width: 100%;
    margin-top: 18px;
    padding-top: 11px; padding-bottom: 11px;
}
.tool .panel-apply { border-top: 0; }

/* ---- Center stage ----------------------------------------------------- */
.stage-wrap {
    display: flex; flex-direction: column;
    min-width: 0; min-height: 0;
    padding: 16px;
}
.stage {
    position: relative; flex: 1; min-height: 0;
    display: flex; justify-content: center; align-items: center;
    background: #000; border-radius: 10px; overflow: hidden;
}
.stage video { max-width: 100%; max-height: 100%; display: block; }
.stage-meta { height: 22px; display: flex; align-items: center; justify-content: center; }
.dims { color: var(--muted); font-size: 12px; }

/* Drop zone is an overlay so the layout never shifts */
.dropzone {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    background: var(--panel);
    border: 2px dashed var(--border); border-radius: 10px;
    text-align: center; cursor: pointer;
    transition: border-color .15s, background .15s;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.drag { border-color: var(--accent); background: #1b2330; }
.dz-icon { font-size: 40px; opacity: .7; }
.dz-inner p { margin: 8px 0; }
.dz-hint { color: var(--muted); font-size: 13px; }

/* Crop overlay */
.crop-layer { position: absolute; overflow: hidden; z-index: 2; }
.crop-box {
    position: absolute;
    border: 1px solid #fff;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
    cursor: move;
}
.crop-box::after {
    content: ""; position: absolute; inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,.35) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.35) 1px, transparent 1px);
    background-size: 33.33% 33.33%;
    pointer-events: none;
}
.handle {
    position: absolute; width: 12px; height: 12px;
    background: #fff; border: 1px solid var(--accent-2);
    border-radius: 2px;
}
.handle.nw { left: -6px;  top: -6px;  cursor: nwse-resize; }
.handle.n  { left: 50%;   top: -6px;  margin-left: -6px; cursor: ns-resize; }
.handle.ne { right: -6px; top: -6px;  cursor: nesw-resize; }
.handle.e  { right: -6px; top: 50%;   margin-top: -6px; cursor: ew-resize; }
.handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle.s  { left: 50%;   bottom: -6px; margin-left: -6px; cursor: ns-resize; }
.handle.sw { left: -6px;  bottom: -6px; cursor: nesw-resize; }
.handle.w  { left: -6px;  top: 50%;   margin-top: -6px; cursor: ew-resize; }

/* ---- Bottom transport + timeline -------------------------------------- */
.timeline-bar {
    border-top: 1px solid var(--border);
    background: var(--panel);
    padding: 12px 18px;
    display: flex; flex-direction: column; gap: 12px;
}
.transport { display: flex; align-items: center; gap: 14px; }
.time-readout { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.timeline {
    position: relative;
    height: 46px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    touch-action: none;
}
.trim-range {
    position: absolute; top: 0; bottom: 0;
    background: rgba(91,140,255,.22);
    border-left: 2px solid var(--accent);
    border-right: 2px solid var(--accent);
    pointer-events: none;
}
.playhead {
    position: absolute; top: 0; bottom: 0; width: 2px;
    background: #fff; pointer-events: none;
    box-shadow: 0 0 6px rgba(0,0,0,.6);
}
.marker {
    position: absolute; top: 0; bottom: 0; width: 2px;
    background: var(--danger);
    transform: translateX(-1px);
}
.marker-flag {
    position: absolute; top: -2px; left: 50%; transform: translateX(-50%);
    color: var(--danger); font-size: 14px; line-height: 1;
}

/* ---- Context menu ----------------------------------------------------- */
.ctx-menu {
    position: fixed; z-index: 50;
    background: var(--panel-2);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 6px; min-width: 180px;
    box-shadow: 0 10px 30px rgba(0,0,0,.5);
    display: flex; flex-direction: column; gap: 2px;
}
.ctx-menu button {
    appearance: none; cursor: pointer; text-align: left;
    background: transparent; color: var(--text);
    border: none; border-radius: 6px; padding: 9px 11px; font-size: 13px;
}
.ctx-menu button:hover { background: var(--accent); color: #fff; }

/* ---- Status + buttons ------------------------------------------------- */
.status { font-size: 13px; color: var(--muted); }
.status.err { color: var(--danger); }
.status.ok { color: var(--success); }

.btn {
    appearance: none; border: 1px solid var(--border); background: var(--panel-2);
    color: var(--text); border-radius: 10px; padding: 9px 14px; font-size: 14px;
    cursor: pointer; text-align: center; text-decoration: none; transition: filter .12s, background .12s;
}
.btn:hover { filter: brightness(1.12); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 11px; font-size: 13px; }
.btn.round { width: 44px; height: 44px; border-radius: 50%; font-size: 22px; line-height: 1; padding: 0; }
.btn.round.small-round { width: 38px; height: 38px; font-size: 16px; }

/* App is disabled until a video is loaded */
.app.no-video .rail-btn,
.app.no-video .tool-panel,
.app.no-video .timeline { opacity: .4; pointer-events: none; }
