:root {
    --bg: #14161d;
    --bg-surface: #1b1e28;
    --bg-raised: #262a38;
    --text: #e6e7ee;
    --text-dim: #8a8ea3;
    --accent: #e0812b;
    --border: #333748;
    --radius: 8px;
    --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--sans);
    background: #ffffff;
    color: #1d1f27;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- header: just space above the recipe ---------- */
#topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
    align-items: center;
    gap: 16px;
    padding: 12px 20px 4px;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    white-space: nowrap;
}

.brand-name {
    font-size: 16px;
    font-weight: 700;
}

.version {
    font-size: 11px;
    color: #8a8ea3;
    font-variant-numeric: tabular-nums;
}

.top-center {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 14px;
}

.top-side {
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-side--left {
    justify-content: flex-end;
}

#recipeTitle {
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    padding: 2px 8px;
    border-radius: 6px;
    outline: none;
    min-width: 6ch;
    max-width: 40vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#recipeTitle.is-editable {
    cursor: text;
}

#recipeTitle.is-editable:hover,
#recipeTitle:focus {
    background: #f1f2f6;
}

#recipeTitle:focus {
    text-overflow: clip;
}

.top-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
}

.row-height-ctl {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #6b6f85;
    white-space: nowrap;
}

.row-height-ctl[hidden],
#topbar button[hidden] {
    display: none;
}

.row-height-ctl input[type="range"] {
    width: 90px;
    accent-color: var(--accent);
}

.row-height-ctl output {
    min-width: 2ch;
    color: #1d1f27;
    font-variant-numeric: tabular-nums;
}

button,
.file-btn {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
}

button:hover,
.file-btn:hover {
    border-color: var(--accent);
}

#topbar button {
    background: #f1f2f6;
    border-color: #d9dbe5;
    color: #1d1f27;
    white-space: nowrap;
}

#topbar button:hover {
    border-color: var(--accent);
}

#appBody {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ---------- recipe folder ---------- */
#folderView {
    flex: 1;
    overflow: auto;
    padding: 20px 24px 32px;
}

#folderView[hidden],
#canvasWrap[hidden] {
    display: none;
}

#folderGrid {
    display: flex;
    flex-direction: column;
    gap: 36px;
}

.folder-new {
    align-self: flex-start;
    background: none;
    border: none;
    padding: 0;
    color: #6b6f85;
    font-size: 15px;
}

.folder-new:hover {
    color: var(--accent);
}

.recipe-entry {
    cursor: pointer;
}

.recipe-entry:focus-visible {
    outline: none;
}

.recipe-entry-head {
    display: flex;
    align-items: baseline;
    gap: 14px;
    margin-bottom: 4px;
}

.recipe-entry-title {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
}

.recipe-entry:hover .recipe-entry-title,
.recipe-entry:focus-visible .recipe-entry-title {
    color: var(--accent);
}

.recipe-entry-del {
    display: none;
    background: none;
    border: none;
    padding: 0;
    color: #c0392b;
    font-size: 12px;
}

.recipe-entry:hover .recipe-entry-del {
    display: inline;
}

.recipe-thumb svg {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

.check-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 140px;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px;
}

.check-item {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

#canvasWrap {
    flex: 1;
    overflow: auto;
    background: #ffffff;
    padding: 20px;
}

#diagram {
    display: block;
    width: 100%;
    height: auto;
}

.utensil-label {
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 400;
    cursor: grab;
}

.step-label {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 400;
    fill: #fff;
    cursor: grab;
}

.line-name {
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 400;
    fill: #fff;
}

.line-name[data-part="quantity"] {
    font-weight: 700;
}

.line-name--placeholder {
    fill-opacity: 0.55;
    font-weight: 400;
    font-style: italic;
}

.pill-label-bg {
    pointer-events: none;
}

.line-name-leader {
    stroke: rgba(0, 0, 0, 0.25);
    stroke-width: 1;
    stroke-dasharray: 2 2;
    pointer-events: none;
}

.line-name[data-line-kind="ingredient"] {
    cursor: grab;
}

.line-name[data-line-kind="merge"] {
    cursor: pointer;
}

.ingredient-line {
    cursor: grab;
    filter: drop-shadow(1px 2px 1.5px rgba(0, 0, 0, 0.35));
}

.ingredient-line.is-selected {
    filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 6px #fff) drop-shadow(1px 2px 1.5px rgba(0, 0, 0, 0.35));
}

.utensil-rect,
.process-rect {
    cursor: grab;
}

.utensil-rect.is-selected,
.process-rect.is-selected {
    stroke: #fff;
    stroke-width: 3px;
    stroke-dasharray: 6 3;
}

.utensil-edge {
    fill: transparent;
    cursor: ew-resize;
}

.process-edge {
    fill: transparent;
    cursor: ns-resize;
}

.section-header-label {
    font-family: var(--sans);
    font-size: 11px;
    font-weight: 600;
    fill: #555;
    pointer-events: none;
}

.layer-hover {
    pointer-events: none;
}

.row-dim {
    fill: #fff;
    fill-opacity: 0.5;
    pointer-events: none;
}

.step-number-bg.is-selected {
    stroke: var(--accent);
    stroke-width: 2;
}

/* ---------- in-context editing affordances ---------- */

.utensil-create-band {
    fill: rgba(0, 0, 0, 0.03);
    cursor: pointer;
}

.utensil-create-band:hover {
    fill: rgba(224, 129, 43, 0.12);
}

.ingredient-create-band {
    fill: transparent;
    cursor: pointer;
}

.ingredient-create-band:hover {
    fill: rgba(224, 129, 43, 0.08);
}

.ingredient-band-border {
    stroke: rgba(0, 0, 0, 0.2);
    stroke-width: 1;
    stroke-dasharray: 3 3;
    pointer-events: none;
}

.timestep-add,
.timestep-add-label {
    cursor: pointer;
}

.timestep-add {
    fill: #f5f5f5;
    stroke: #ccc;
    stroke-dasharray: 3 3;
    shape-rendering: crispEdges;
}

.timestep-add-label {
    font-family: var(--sans);
    font-size: 14px;
    fill: #999;
    pointer-events: none;
}

.row-separator {
    stroke: rgba(0, 0, 0, 0.07);
    stroke-width: 1;
    shape-rendering: crispEdges;
    pointer-events: none;
}

.step-number-bg {
    fill: #ececec;
    stroke: rgba(0, 0, 0, 0.18);
    stroke-width: 1;
    shape-rendering: crispEdges;
    cursor: grab;
}

.step-number-bg:hover {
    filter: brightness(0.92);
    stroke: var(--accent);
}

.step-number {
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 600;
    fill: #555;
    pointer-events: none;
}

.draw-preview {
    fill: rgba(224, 129, 43, 0.15);
    stroke: var(--accent);
    stroke-dasharray: 4 3;
    pointer-events: none;
}

.inline-popover {
    position: fixed;
    z-index: 1000;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    min-width: 180px;
}

.drag-ghost {
    position: fixed;
    z-index: 1100;
    transform: translate(12px, -50%);
    pointer-events: none;
    background: var(--bg-raised);
    border: 2px solid #888;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    display: none;
    white-space: nowrap;
}

.popover-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 11px;
    color: var(--text-dim);
}

.inline-edit-wrap {
    position: fixed;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 4px;
}

.inline-edit-input {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--accent);
    color: #1a1a1a;
    padding: 0 3px;
    border-radius: 3px;
    font-size: 12px;
    font-family: var(--sans);
    line-height: 1.3;
    outline: none;
    box-shadow: none;
}

.inline-edit-input--pill {
    border: none;
    border-radius: 999px;
    padding: 2px 7px;
    font-weight: 600;
}

.inline-edit-input--transparent {
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 0;
}

.inline-edit-delete {
    background: #c0392b;
    color: #fff;
    border: none;
    border-radius: 999px;
    width: 18px;
    height: 18px;
    line-height: 1;
    font-size: 12px;
    cursor: pointer;
    padding: 0;
    flex: none;
}

.color-swatch {
    position: fixed;
    transform: translate(-50%, -50%);
    z-index: 950;
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 2px solid var(--bg-raised);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
    cursor: pointer;
}

.color-swatch:hover {
    filter: brightness(1.15);
}

.thickness-adjuster {
    position: fixed;
    transform: translate(-50%, -50%);
    z-index: 950;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
    user-select: none;
}

.thickness-adjuster:hover {
    color: var(--text);
    border-color: var(--accent);
}

.popover-field input {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.popover-field input[type="color"] {
    padding: 0;
    height: 26px;
}

.popover-add-btn {
    align-self: flex-start;
    border-color: var(--accent);
    color: var(--accent);
}

.hover-action-btn {
    position: fixed;
    transform: translate(-50%, -50%);
    z-index: 950;
    background: var(--accent);
    color: #1a1208;
    border: none;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.hover-action-btn:hover {
    filter: brightness(1.1);
}

.hover-action-btn.cut-btn {
    background: #c0392b;
    color: #fff;
    width: 20px;
    height: 20px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.hover-action-btn.delete-btn {
    background: #c0392b;
    color: #fff;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.row-current {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    pointer-events: none;
}

/* Timer field on a step label */
.step-timer {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
}

.step-timer.is-ringing {
    animation: timer-blink 0.7s steps(2, jump-none) infinite;
}

@keyframes timer-blink {
    50% {
        opacity: 0.25;
    }
}

.hover-action-btn.timer-btn {
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--accent);
    font-size: 11px;
}

/* ---------- cook mode ---------- */
svg.cooking {
    pointer-events: none;
}

.cook-toggle {
    border-color: var(--accent);
    color: var(--accent);
}

#cookBar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 24px;
    padding: 10px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
}

#cookBar[hidden] {
    display: none;
}

.cook-nav,
.cook-mic {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-dim);
}

#cookStatus {
    min-width: 8ch;
    text-align: center;
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
}

.cook-primary {
    background: var(--accent);
    color: #1a1208;
    border-color: var(--accent);
    font-weight: 700;
    padding: 9px 22px;
}

#cookBar button:disabled {
    opacity: 0.4;
    cursor: default;
}

#cookMic.is-on {
    border-color: #3fb950;
    color: #3fb950;
}

.cook-meter {
    position: relative;
    width: 110px;
    height: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    overflow: hidden;
}

.cook-meter::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    border-left: 1px dashed var(--text-dim);
}

#cookMeterBar {
    height: 100%;
    width: 0;
    background: #3fb950;
}

.cook-meter.snap {
    border-color: var(--accent);
}

.cook-meter.snap #cookMeterBar {
    background: var(--accent);
}

#cookTimers {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: auto;
}

.cook-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px 4px 10px;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
}

.cook-chip-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 14px;
}

.cook-chip-name {
    color: var(--text-dim);
    max-width: 18ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cook-chip button {
    padding: 0 7px;
    border-radius: 999px;
    line-height: 18px;
}

.cook-chip.is-ringing {
    border-color: #c0392b;
    animation: chip-flash 0.7s steps(2, jump-none) infinite;
}

@keyframes chip-flash {
    50% {
        background: #5a2420;
    }
}
@media (max-width: 900px) {
    #topbar {
        grid-template-columns: 1fr;
        justify-items: center;
        gap: 8px;
    }

    .top-center {
        grid-template-columns: auto;
        justify-items: center;
    }

    .top-side--left,
    .top-side--right {
        justify-content: center;
        flex-wrap: wrap;
    }

    #recipeTitle {
        max-width: 90vw;
    }
}
