/* ═══════════════════════════════════════════════════════════
   Pasta Bridge — Layout & visual style
   ═══════════════════════════════════════════════════════════ */
:root {
    --col-bg:        #f4f6f9;
    --col-panel:     #ffffff;
    --col-border:    #d8dee6;
    --col-text:      #222;
    --col-muted:     #666;
    --col-primary:   #E8A13A;     /* pasta gold */
    --col-primary-dark: #C77F1A;
    --col-success:   #2E7D32;
    --col-success-bg:#E8F5E9;
    --col-danger:    #C62828;
    --col-danger-bg: #FFEBEE;
    --col-tension:   #D32F2F;     /* red = tension */
    --col-compress:  #1565C0;     /* blue = compression */
    --shadow:        0 1px 3px rgba(0,0,0,.1);
}
* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--col-text);
    background: var(--col-bg);
    height: 100%;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}
#app {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    grid-template-areas: "sidebar canvas score";
    height: 100vh;
    width: 100vw;
}
#sidebar     { grid-area: sidebar; background: var(--col-panel); border-right: 1px solid var(--col-border); overflow-y: auto; padding: 12px; }
#canvas-area { grid-area: canvas;  position: relative; background: #fbfaf7; overflow: hidden; touch-action: none; }
#score-panel { grid-area: score;   background: var(--col-panel); border-left: 1px solid var(--col-border); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }

#sidebar h1 { font-size: 19px; margin: 0 0 4px; color: var(--col-primary-dark); }
#sidebar .subtitle { font-size: 12px; color: var(--col-muted); margin: 0 0 12px; }

#logo-link { display: block; margin: 4px auto 12px; line-height: 0; text-align: center; }
#logo-img { display: block; width: 100%; max-width: 150px; height: auto; margin: 0 auto; border-radius: 6px; transition: opacity .15s; }
#logo-img:hover { opacity: .85; }

.logo-m { display: none; }   /* mobile-only logo, shown to the right of Show deformation */
#sound-footer { display: none; }   /* mobile-only sound controls, below the fold */

.panel { margin-bottom: 14px; }
fieldset { border: 1px solid var(--col-border); border-radius: 6px; padding: 8px 10px; margin: 0 0 10px; }
fieldset legend { font-size: 12px; color: var(--col-muted); padding: 0 4px; }
.radio-row { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.radio-row label { font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 5px; }
/* Desktop only: enlarge the selection radios a notch for easier clicking */
@media (min-width: 901px) {
    .radio-row input[type="radio"] { width: 18px; height: 18px; accent-color: var(--col-primary); cursor: pointer; }
}
.hint { font-size: 11px; color: var(--col-muted); margin: 4px 0 0; line-height: 1.4; }

label.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; margin: 6px 0; }
label.field input[type="number"] { width: 90px; padding: 4px 6px; border: 1px solid var(--col-border); border-radius: 4px; font: inherit; }
label.field input[type="range"] { flex: 1; accent-color: var(--col-primary); }

/* Sound + Volume on one row: short volume bar to the right of the Sound toggle */
.sound-row { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 6px 0; }
.sound-row .sound-toggle { display: flex; align-items: center; gap: 8px; }
.sound-row .vol-label { margin-left: 14px; }
.sound-row input[type="range"] { width: 80px; flex: 0 0 auto; accent-color: var(--col-primary); }

/* on/off toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 24px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
    position: absolute; inset: 0; background: #c4ccd6; border-radius: 24px;
    transition: background .15s; cursor: pointer;
}
.switch .track::before {
    content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked + .track { background: var(--col-primary); }
.switch input:checked + .track::before { transform: translateX(22px); }

button {
    padding: 8px 10px; border-radius: 6px; border: 1px solid var(--col-border);
    background: #f6f8fa; cursor: pointer; font: inherit; color: var(--col-text);
    transition: filter .1s; width: 100%; margin-top: 6px;
}
button:hover { filter: brightness(0.96); }
button:active { filter: brightness(0.9); }
button.btn-primary { background: var(--col-primary); border-color: var(--col-primary-dark); color: white; font-weight: bold; }
button.btn-big { font-size: 18px; padding: 14px; margin-top: 8px; }
.btn-row { display: flex; gap: 6px; }
.btn-row button { flex: 1; }

.material-box { font-size: 12px; color: #444; line-height: 1.6; background: #faf7f0; border: 1px solid var(--col-border); border-radius: 6px; padding: 8px 10px; }
.material-box b { color: var(--col-primary-dark); }

/* ── Canvas ── */
#game-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
#zoom-controls {
    position: absolute; top: 10px; right: 10px;
    display: flex; flex-direction: column; gap: 4px; z-index: 5;
}
#zoom-controls button {
    width: 40px; height: 40px; margin: 0; padding: 0;
    border-radius: 6px; border: 1px solid var(--col-border);
    background: rgba(255,255,255,0.92); box-shadow: var(--shadow);
    font-size: 18px; line-height: 1; cursor: pointer; user-select: none;
}
#zoom-controls button:hover { background: white; }
#legend {
    position: absolute; left: 10px; bottom: 10px; background: rgba(255,255,255,.9);
    border: 1px solid var(--col-border); border-radius: 6px; padding: 6px 10px;
    font-size: 11px; color: #444; box-shadow: var(--shadow); line-height: 1.6;
}
#legend .sw { display: inline-block; width: 14px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
#cbar {
    display: inline-block; width: 90px; height: 9px; border-radius: 2px;
    vertical-align: middle; border: 1px solid #aaa;
    background: linear-gradient(to right,
        rgb(0,26,255), rgb(0,210,255), rgb(140,255,115),
        rgb(255,185,0), rgb(255,0,0));
}

/* ── Score panel ── */
#status-card {
    border: 3px solid var(--col-border); border-radius: 10px; padding: 16px 12px;
    text-align: center; background: white; transition: .2s;
}
#status-card.state-pass { border-color: var(--col-success); background: var(--col-success-bg); }
#status-card.state-fail { border-color: var(--col-danger);  background: var(--col-danger-bg);  }
#status-card.state-warn { border-color: var(--col-primary); background: #FFF8E1; }
#status-banner { font-size: 14px; font-weight: bold; color: var(--col-muted); margin-bottom: 6px; }
#status-card.state-pass #status-banner { color: var(--col-success); }
#status-card.state-fail #status-banner { color: var(--col-danger); }
#score-number { font-size: 40px; font-weight: bold; line-height: 1.1; color: var(--col-muted); }
#score-unit { font-size: 13px; color: var(--col-muted); }
#score-formula { font-size: 21px; font-weight: bold; line-height: 1.2; color: var(--col-muted); }
#status-card.state-pass #score-formula { color: var(--col-success); }
#status-card.state-fail #score-formula { color: var(--col-danger); }
#score-sub { font-size: 12px; color: #444; margin-top: 6px; }
#time-card {
    border: 2px solid var(--col-border); border-radius: 8px; padding: 8px 12px;
    background: white; display: flex; align-items: baseline; justify-content: space-between;
}
#time-label { font-size: 12px; color: var(--col-muted); }
#time-value { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 22px; font-weight: bold; color: #444; }
#score-best { font-size: 13px; font-weight: bold; color: var(--col-muted); margin-top: 8px; }

#metrics { display: flex; flex-direction: column; gap: 12px; }
.metric-row { display: flex; gap: 12px; }
.metric-row > .metric-card { flex: 1; min-width: 0; }
.metric-row .metric-value { font-size: 15px; }

/* clickable load cards (switch the canvas view) */
#fracture-card, #buckle-card { cursor: pointer; transition: box-shadow .12s, border-color .12s; }
#fracture-card:hover, #buckle-card:hover { border-color: var(--col-primary-dark); }
#fracture-card.view-active, #buckle-card.view-active { box-shadow: 0 0 0 2px var(--col-primary-dark) inset; }
#buckle-card.disabled { opacity: 0.45; }
.metric-label .view-tag { float: right; font-size: 10px; color: var(--col-primary-dark); }

.metric-card { border: 2px solid var(--col-border); border-radius: 8px; padding: 8px 12px; background: white; text-align: center; }
.metric-card.state-ok   { border-color: var(--col-success); }
.metric-card.state-over { border-color: var(--col-danger); background: var(--col-danger-bg); }
.metric-label { font-size: 12px; color: var(--col-muted); }
.metric-value { font-size: 18px; font-weight: bold; color: #444; margin-top: 2px; }
.metric-card.state-over .metric-value { color: var(--col-danger); }
.bar { position: relative; width: 100%; height: 12px; border: 1px solid #aaa; border-radius: 3px; margin-top: 6px; overflow: hidden; background: #eee; }
.bar > .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--col-success); transition: width .2s, background .2s; }
.bar > .fill.over { background: var(--col-danger); }

/* ── Mobile: game fills one screen; sound controls live below the fold ── */
@media (max-width: 900px) {
    html, body { overflow: visible; height: auto; }   /* page grows past #app so scrolling reveals the sound footer */
    #sidebar .sound-sidebar { display: none; }   /* not in the always-visible control bar */
    #sound-footer {
        display: block; padding: 14px 16px; background: var(--col-panel);
        border-top: 1px solid var(--col-border);
    }
    #sound-footer .field { max-width: 360px; margin: 6px 0; }
    #sound-footer .footer-title { font-size: 18px; font-weight: bold; color: var(--col-primary-dark); margin-bottom: 12px; }
    #sound-footer .material-box { display: block; max-width: 360px; margin-bottom: 12px; }
    #sound-footer .sound-row { max-width: 360px; }
    #app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas: "score" "canvas" "sidebar";
        height: 100vh; height: 100dvh; width: 100vw;
    }

    /* top: compact score bar */
    #score-panel {
        border-left: none; border-bottom: 1px solid var(--col-border);
        flex-direction: row; flex-wrap: nowrap; align-items: stretch;
        gap: 6px; padding: 6px; overflow: hidden;
    }
    #status-card { flex: 1 1 auto; padding: 6px 8px; border-width: 2px; }
    #time-card { display: none; }   /* hidden on phones to save space */
    #status-banner { font-size: 11px; margin-bottom: 2px; }
    #score-formula { font-size: 15px; }
    #score-sub { display: none; }
    #score-best { font-size: 11px; margin-top: 2px; }
    #metrics { flex: 0 0 auto; gap: 6px; }
    .metric-row { flex: 0 0 auto; gap: 6px; }
    .metric-row > .metric-card { flex: 0 0 auto; min-width: 76px; }
    /* Self-weight spans the two load cards' width, on a single line */
    #selfweight-card { flex: 1 1 auto; display: flex; flex-direction: row;
        align-items: baseline; justify-content: space-between; gap: 6px; }
    .metric-card { padding: 4px 8px; }
    .metric-label { font-size: 10px; }
    .metric-row .metric-value { font-size: 13px; }

    /* middle: canvas fills the remaining height */
    #canvas-area { min-height: 0; }

    /* bottom: compact control bar */
    #sidebar {
        border-right: none; border-top: 1px solid var(--col-border);
        padding: 6px; overflow: hidden;
    }
    #sidebar h1, #sidebar .subtitle, #logo-link, #sidebar .material-box { display: none; }
    #sidebar .panel { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
    #sidebar fieldset { margin: 0; padding: 0; border: none; display: inline-flex; align-items: center; }
    #sidebar fieldset legend { display: none; }
    #sidebar .radio-row { gap: 2px 10px; }
    #sidebar .radio-row label { font-size: 12px; }
    #sidebar .field { margin: 0; gap: 6px; width: auto; }
    #sidebar #btn-solve { font-size: 14px; padding: 9px 16px; width: auto; margin: 0; flex: 1 1 140px; }
    #sidebar .btn-row { flex: 1 1 100%; margin: 0; gap: 6px; }
    #sidebar .btn-row button { margin: 0; padding: 8px; }
    #in-deform-scale { flex: 1 1 90px; min-width: 70px; }
    .logo-m { display: inline-block; line-height: 0; flex: 0 0 auto; margin-left: auto; }
    .logo-m img { height: 26px; width: auto; border-radius: 4px; display: block; }
}
