:root {
    --paper: #f3efe6;
    --paper-deep: #e7e1d6;
    --card: #fffdf8;
    --ink: #241f1a;
    --muted: #6d655c;
    --faint: #8a8176;
    --line: #e3dbd0;
    --blue: #2f62d6;
    --blue-deep: #1f4cb3;
    --orange: #e06a2f;
    --orange-deep: #c4551d;
    --green: #2f8a58;
    --brown: #8a6232;
    --danger: #b42318;
    --warn: #9a6700;
    --ok: #1f7a45;
    --bed: #e7eef6;
    --shadow: 0 14px 30px -22px rgba(48, 36, 20, 0.45);
    --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    color-scheme: light;
    font-family: var(--sans);
    color: var(--ink);
    background-color: var(--paper);
    background-image: repeating-linear-gradient(
        180deg,
        transparent 0 10px,
        rgba(36, 31, 26, 0.028) 10px 11px
    );
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

button, input { font-family: inherit; }

.pair-stripe {
    flex: none;
    display: grid;
    grid-template-columns: 1.15fr 10px 0.72fr 10px 0.55fr 10px 0.42fr 1.4fr;
    height: 8px;
    background: var(--paper-deep);
}

.pair-blue { background: var(--blue); }
.pair-orange { background: var(--orange); }
.pair-green { background: var(--green); }
.pair-brown { background: var(--brown); }
.pair-gap { background: var(--paper); }
.pair-layers {
    background: repeating-linear-gradient(
        90deg,
        #d9d0c3 0 7px,
        transparent 7px 14px
    );
}

.app-header {
    flex: none;
    background: rgba(255, 253, 248, 0.92);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.8rem 1.25rem 0.9rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.logo-icon {
    color: var(--blue);
    background:
        linear-gradient(var(--orange), var(--orange)) left bottom / 14px 3px no-repeat,
        var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    flex: none;
    box-shadow: inset 0 -8px 0 rgba(47, 98, 214, 0.08);
}

.kicker {
    margin: 0;
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--orange-deep);
}

h1 {
    margin: 0.05rem 0 0;
    font-size: 1.28rem;
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.subtitle {
    margin: 0.12rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    flex: none;
}

.workspace {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(320px, 430px) 1fr;
}

.panel {
    min-height: 0;
    overflow: auto;
    padding: 1.05rem 1.15rem 1.4rem;
    border-right: 1px solid var(--line);
    background: rgba(255, 253, 248, 0.55);
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 16px;
    margin: 0 0 0.8rem;
    padding: 0.85rem 0.9rem 1rem;
    background: var(--card);
    box-shadow: var(--shadow);
}

legend {
    padding: 0 0.35rem;
    color: var(--ink);
    font-size: 0.74rem;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

legend::before {
    content: "";
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    margin-right: 0.4rem;
    border-radius: 99px;
    vertical-align: 0.05em;
    background: var(--blue);
    box-shadow: 0 0 0 3px rgba(47, 98, 214, 0.15);
}

legend[data-pair="orange"]::before {
    background: var(--orange);
    box-shadow: 0 0 0 3px rgba(224, 106, 47, 0.16);
}

legend[data-pair="green"]::before {
    background: var(--green);
    box-shadow: 0 0 0 3px rgba(47, 138, 88, 0.16);
}

.field-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 0.7rem;
}

.field { display: flex; flex-direction: column; gap: 0.28rem; min-width: 0; }
.field-wide { grid-column: 1 / -1; }

.field span {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink);
}

.field em {
    font-family: var(--mono);
    font-style: normal;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    color: var(--faint);
    font-weight: 500;
}

.field small {
    color: var(--faint);
    font-size: 0.7rem;
    line-height: 1.35;
}

input[type="number"] {
    width: 100%;
    background: #fff;
    color: var(--ink);
    border: 1px solid #ddd4c8;
    border-radius: 10px;
    padding: 0.48rem 0.65rem;
    font-family: var(--mono);
    font-size: 0.92rem;
    outline: none;
}

input[type="number"]:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(47, 98, 214, 0.16);
}

.stats {
    display: grid;
    grid-template-columns: 1.45fr 0.8fr 0.85fr;
    gap: 0.55rem;
    margin: 0;
}

.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-left-width: 3px;
    border-radius: 12px;
    padding: 0.6rem 0.7rem;
    box-shadow: var(--shadow);
}

.stat-blue { border-left-color: var(--blue); }
.stat-orange { border-left-color: var(--orange); }
.stat-green { border-left-color: var(--green); }

.stats dt {
    margin: 0;
    color: var(--faint);
    font-family: var(--mono);
    font-size: 0.64rem;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.stats dd {
    margin: 0.22rem 0 0;
    font-family: var(--mono);
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: -0.03em;
    line-height: 1.35;
}

.notice {
    border-radius: 12px;
    padding: 0.7rem 0.8rem;
    font-size: 0.82rem;
    line-height: 1.4;
}

.notice p { margin: 0; }
.notice p + p { margin-top: 0.35rem; }

.notice-warn {
    background: #fff7e8;
    border: 1px solid #f0d7a2;
    color: #7a5200;
}

.notice-error {
    background: #fff1f0;
    border: 1px solid #f3c1bc;
    color: var(--danger);
}

.panel-actions { display: flex; flex-direction: column; gap: 0.7rem; }

.print-note {
    margin: 0;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.45;
    padding-left: 0.7rem;
    border-left: 3px solid var(--orange);
}

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.55rem 0.9rem;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    color: white;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
    background: var(--blue);
    border-color: var(--blue-deep);
}
.btn-primary:hover:not(:disabled) { background: var(--blue-deep); }

.btn-secondary {
    background: var(--card);
    color: var(--orange-deep);
    border-color: #f0c2ae;
}
.btn-secondary:hover:not(:disabled) { background: #fff4ee; }

.btn-ghost {
    background: var(--card);
    color: var(--muted);
    border-color: var(--line);
}
.btn-ghost:hover:not(:disabled) {
    color: var(--ink);
    border-color: #cfc6ba;
    background: #fff;
}

.btn-small { padding: 0.35rem 0.65rem; font-size: 0.78rem; }

.stage {
    position: relative;
    min-width: 0;
    min-height: 0;
    background:
        radial-gradient(720px 420px at 50% 42%, rgba(255, 255, 255, 0.72), transparent 68%),
        var(--bed);
}

.stage::after {
    content: "";
    position: absolute;
    inset: 16px;
    border: 1px dashed rgba(47, 98, 214, 0.22);
    border-radius: 18px;
    pointer-events: none;
    z-index: 1;
}

.stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.stage-toolbar {
    position: absolute;
    top: 0.85rem;
    left: 0.85rem;
    right: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    z-index: 2;
    flex-wrap: wrap;
}

.stage-tools {
    display: flex;
    gap: 0.4rem;
    pointer-events: auto;
}

.stage-toolbar .btn { pointer-events: auto; }

.btn-ghost.is-on {
    color: var(--blue-deep);
    border-color: #b9c9f2;
    background: #eef3ff;
}

.status-pill {
    pointer-events: none;
    background: rgba(255, 253, 248, 0.92);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--muted);
    box-shadow: var(--shadow);
}

.status-pill.ok { color: var(--ok); }
.status-pill.busy { color: var(--blue); }
.status-pill.warn { color: var(--warn); }
.status-pill.bad { color: var(--danger); }

.stage-hint {
    position: absolute;
    left: 0.9rem;
    bottom: 0.8rem;
    margin: 0;
    color: var(--muted);
    font-size: 0.75rem;
    background: rgba(255, 253, 248, 0.92);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.28rem 0.7rem;
    z-index: 2;
    box-shadow: var(--shadow);
}

.stage.is-busy::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    height: 3px;
    width: 35%;
    background: linear-gradient(90deg, transparent, var(--orange), var(--blue), transparent);
    animation: slide 0.9s ease-in-out infinite;
    z-index: 3;
}

@keyframes slide {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}

@media (max-width: 860px) {
    body { height: auto; overflow: auto; }
    .header-inner { align-items: flex-start; flex-wrap: wrap; }
    .workspace { display: flex; flex-direction: column; }
    .stage { order: -1; height: 68vh; flex: none; }
    .panel { overflow: visible; border-right: 0; border-top: 1px solid var(--line); }
    .stats { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .field-grid { grid-template-columns: 1fr; }
    .header-actions { width: 100%; }
    .header-actions .btn { flex: 1; }
}
