* { box-sizing: border-box; }

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

body {
    background: #000;
    color: #fff;
    font-family: Arial, sans-serif;
    overflow-x: auto;
}

button, select { font: inherit; }

.hidden { display: none !important; }

.layout {
    min-width: 1240px;
    min-height: 100vh;
    padding: 12px;
}

.left-panel,
.right-panel {
    position: fixed;
    top: 12px;
    width: 220px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #2f3b46;
    border: 2px solid #1f2a33;
    border-radius: 18px;
    box-shadow: 0 10px 25px rgba(0,0,0,.42);
    z-index: 100;
}

.left-panel { left: 12px; }
.right-panel { right: 12px; }

.center-panel {
    margin-left: 250px;
    margin-right: 250px;
    min-height: calc(100vh - 24px);
    padding: 18px;
    background: #111;
    border: 2px solid #333;
    border-radius: 16px;
}

.pretty-btn,
.back-btn,
.timer-buttons button,
.practice-intro button {
    width: 100%;
    min-height: 42px;
    padding: 10px 11px;
    border: 2px solid #1f2f3a;
    border-radius: 12px;
    background: linear-gradient(180deg,#5f7fa0 0%,#4a6a82 100%);
    color: #e9f3ff;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,.4), inset 0 1px 3px rgba(255,255,255,.28);
    transition: .2s ease;
}

.pretty-btn:hover,
.back-btn:hover,
.timer-buttons button:hover,
.practice-intro button:hover {
    background: linear-gradient(180deg,#6f8fb3 0%,#557a94 100%);
    transform: translateY(-2px);
}

.back-btn {
    background: #064523;
    color: #0f0;
    border-color: #0f0;
    box-shadow: 0 0 8px #0f0;
}

.back-btn:hover {
    background: #0a6a36;
    box-shadow: 0 0 12px #0f0;
}

.reset-btn {
    background: linear-gradient(180deg,#8a4c4c,#693737);
}

.contest-note {
    padding: 8px 10px;
    border: 1px solid #52697d;
    border-radius: 10px;
    background: #202a33;
    color: #b8c7d6;
    font-size: 11px;
    line-height: 1.4;
    text-align: center;
}

.panel-separator {
    width: 100%;
    height: 2px;
    margin: 5px 0;
    background: #738291;
    box-shadow: 0 2px 6px rgba(0,0,0,.6);
}

.panel-caption,
.field-label {
    color: #c7d6e5;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.panel-select,
.builder-select {
    width: 100%;
    min-height: 42px;
    padding: 8px 9px;
    border: 2px solid #1f2f3a;
    border-radius: 10px;
    background: #1c242d;
    color: #fff;
}

#timerDisplay {
    width: 100%;
    padding: 10px 6px;
    background: #1c242d;
    border: 2px solid #0a0f14;
    border-radius: 10px;
    color: #c9f508;
    font-family: Consolas, monospace;
    font-size: 28px;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 0 10px rgba(80,120,160,.7);
    box-shadow: inset 0 0 10px rgba(0,0,0,.6);
}

.timer-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.timer-buttons button {
    min-width: 0;
    padding: 8px 5px;
}

.trainer-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    padding: 18px 20px;
    background: #202a33;
    border: 1px solid #3c4d5c;
    border-radius: 14px;
}

.eyebrow {
    margin-bottom: 5px;
    color: #ffaa44;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.trainer-head h1 {
    margin: 0 0 8px;
    font-size: 27px;
    color: #f4f8fb;
}

.trainer-head p {
    max-width: 780px;
    margin: 0;
    color: #bdcbd8;
    font-size: 14px;
    line-height: 1.5;
}

.scan-box {
    min-width: 135px;
    padding: 10px;
    background: #10181e;
    border: 1px solid #395164;
    border-radius: 10px;
    text-align: center;
}

.scan-box span,
.scan-box small {
    display: block;
    color: #8fa7bb;
    font-size: 10px;
    text-transform: uppercase;
}

.scan-box strong {
    display: block;
    margin: 4px 0;
    color: #36f27a;
    font-size: 22px;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 12px;
}

.section-title-row h2 {
    margin: 0 0 5px;
    font-size: 21px;
}

.section-title-row p {
    margin: 0;
    color: #aebfcd;
    font-size: 13px;
}

.status-pill {
    white-space: nowrap;
    padding: 7px 10px;
    border-radius: 999px;
    background: #183328;
    border: 1px solid #2f7b51;
    color: #74f3a4;
    font-size: 11px;
}

.plc-rack {
    margin-bottom: 14px;
    padding: 14px;
    background: linear-gradient(180deg,#28343e,#1c242b);
    border: 3px solid #4c5a65;
    border-radius: 14px;
    box-shadow: inset 0 0 20px rgba(0,0,0,.35), 0 10px 20px rgba(0,0,0,.35);
}

.plc-brand {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    padding: 8px 10px;
    background: #111820;
    border-radius: 8px;
}

.plc-brand strong {
    color: #f4f4f4;
    letter-spacing: .08em;
}

.plc-brand span {
    color: #8ca0b1;
    font-size: 11px;
}

.io-columns {
    display: grid;
    grid-template-columns: 1fr 120px 1fr;
    gap: 12px;
    align-items: stretch;
}

.io-block,
.cpu-block {
    background: #151d23;
    border: 2px solid #3e4d59;
    border-radius: 10px;
    padding: 10px;
}

.io-title {
    margin-bottom: 8px;
    color: #ffaa44;
    font-size: 11px;
    font-weight: 800;
    text-align: center;
}

.io-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: 7px;
}

.io-btn,
.output-lamp {
    min-height: 55px;
    padding: 6px;
    border: 2px solid #455866;
    border-radius: 9px;
    background: #222d35;
    color: #cbd7e0;
    font-family: Consolas, monospace;
    font-weight: 800;
    text-align: center;
}

.io-btn {
    cursor: pointer;
}

.io-btn:hover {
    background: #2d3e4a;
}

.io-led {
    width: 12px;
    height: 12px;
    margin: 0 auto 4px;
    border-radius: 50%;
    background: #374151;
    box-shadow: inset 0 0 4px #000;
}

.io-btn.on .io-led,
.output-lamp.on .io-led {
    background: #28f06f;
    box-shadow: 0 0 10px #28f06f;
}

.io-btn.on,
.output-lamp.on {
    border-color: #3cb66a;
    color: #7bffa9;
}

.cpu-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.cpu-led {
    width: 16px;
    height: 16px;
    margin-bottom: 6px;
    border-radius: 50%;
}

.cpu-led.run {
    background: #24e768;
    box-shadow: 0 0 10px #24e768;
}

.cpu-block span {
    margin-top: 4px;
    color: #53f18a;
    font-size: 12px;
    font-weight: 800;
}

.cpu-block small {
    margin-top: 4px;
    color: #869baa;
    font-size: 9px;
}

.ladder-card,
.practice-ladder-card {
    overflow: hidden;
    margin-bottom: 14px;
    border: 2px solid #3a4b58;
    border-radius: 12px;
    background: #0e1419;
}

.ladder-card-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    background: #202e38;
    color: #a9c6dc;
    font-size: 11px;
}

.ladder-card-head strong {
    color: #ffaa44;
}

.ladder-view {
    min-height: 150px;
    padding: 18px;
    overflow-x: auto;
    font-family: Consolas, monospace;
}

.rung {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 690px;
    min-height: 54px;
    padding: 5px 18px;
    border-left: 4px solid #8ba1b3;
    border-right: 4px solid #8ba1b3;
}

.rung::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 3px;
    background: #52616e;
    z-index: 0;
}

.lad-node {
    position: relative;
    z-index: 1;
    min-width: 92px;
    margin-right: 28px;
    padding: 7px 10px;
    background: #0e1419;
    border: 2px solid #667887;
    border-radius: 6px;
    color: #d8e3eb;
    text-align: center;
}

.lad-node.coil {
    margin-left: auto;
    margin-right: 0;
    border-radius: 999px;
}

.lad-node.active {
    border-color: #2fea73;
    color: #78ffa8;
    box-shadow: 0 0 10px rgba(47,234,115,.35);
}

.lad-node.timer,
.lad-node.counter {
    min-width: 120px;
}

.branch-note {
    position: relative;
    z-index: 1;
    margin-right: 28px;
    padding: 7px 10px;
    background: #193044;
    border: 1px dashed #5c8ab0;
    border-radius: 6px;
    color: #a8d7fb;
    text-align: center;
}

.device-grid {
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 10px;
}

.device-card {
    padding: 10px;
    background: #202a33;
    border: 1px solid #3f5362;
    border-radius: 10px;
    text-align: center;
}

.device-card span {
    color: #ffaa44;
    font-family: Consolas, monospace;
    font-weight: 900;
}

.device-card strong {
    display: block;
    margin: 5px 0;
    color: #c9f508;
    font-size: 19px;
}

.device-card small {
    color: #8399aa;
    font-size: 9px;
}

.task-score {
    display: grid;
    grid-template-columns: repeat(3,1fr);
    gap: 9px;
    margin-bottom: 14px;
}

.task-score > div {
    padding: 10px;
    background: #202a33;
    border: 1px solid #3e5261;
    border-radius: 10px;
    text-align: center;
}

.task-score span {
    display: block;
    color: #8ea5b7;
    font-size: 10px;
    text-transform: uppercase;
}

.task-score strong {
    display: block;
    margin-top: 4px;
    color: #c9f508;
    font-size: 22px;
}

.plc-task-grid {
    display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 12px;
}

.plc-task {
    padding: 14px;
    background: #27343e;
    border: 2px solid #3e5363;
    border-radius: 14px;
}

.plc-task.correct { border-color: #2ecc71; }
.plc-task.wrong { border-color: #e74c3c; }

.plc-task h3 {
    margin: 0 0 8px;
    color: #f2f6f8;
    font-size: 16px;
}

.task-expression {
    margin-bottom: 8px;
    padding: 9px;
    background: #111820;
    border-radius: 8px;
    color: #ffaa44;
    font-family: Consolas, monospace;
    text-align: center;
}

.task-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-bottom: 8px;
}

.task-chip {
    padding: 5px 8px;
    background: #141e25;
    border-radius: 7px;
    color: #d7e2eb;
    font-family: Consolas, monospace;
}

.task-answer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.task-answer-btn {
    min-height: 40px;
    border: 2px solid #4a6173;
    border-radius: 9px;
    background: #263a49;
    color: #fff;
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
}

.task-answer-btn.selected {
    border-color: #ffaa44;
    background: #6a512c;
}

.task-check-btn {
    width: 100%;
    min-height: 36px;
    margin-top: 8px;
    border: 0;
    border-radius: 8px;
    background: #50718a;
    color: #fff;
    font-weight: 800;
    cursor: pointer;
}

.task-check-btn:disabled {
    background: #34424c;
    color: #8799a7;
}

.task-result {
    min-height: 28px;
    margin-top: 7px;
    padding: 6px;
    background: #172027;
    border-radius: 7px;
    color: #94a7b6;
    font-size: 12px;
    text-align: center;
}

.practice-intro {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    margin-bottom: 14px;
    padding: 14px;
    background: #202a33;
    border: 1px solid #3e5261;
    border-radius: 12px;
}

.practice-intro h2 {
    margin: 0 0 5px;
    font-size: 20px;
}

.practice-intro p {
    max-width: 760px;
    margin: 0;
    color: #aebfcd;
    font-size: 13px;
    line-height: 1.45;
}

.practice-intro button {
    width: auto;
    min-width: 140px;
}

.practice-workspace {
    display: grid;
    grid-template-columns: 290px 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.builder-panel {
    padding: 12px;
    background: #202a33;
    border: 1px solid #3e5261;
    border-radius: 12px;
}

.builder-row {
    margin-bottom: 10px;
}

.builder-row:last-child { margin-bottom: 0; }

.builder-row label {
    display: block;
    margin-bottom: 4px;
    color: #9db2c2;
    font-size: 11px;
    font-weight: 700;
}

.practice-ladder-card {
    margin-bottom: 0;
}

.practice-io-wrap {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 12px;
}

.practice-io-wrap > div {
    padding: 12px;
    background: #202a33;
    border: 1px solid #3e5261;
    border-radius: 12px;
}

.practice-io-wrap h3 {
    margin: 0 0 9px;
    font-size: 15px;
}

.practice-result-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: center;
}

.practice-result-box span {
    color: #8fa7b8;
    font-size: 11px;
    text-transform: uppercase;
}

.practice-result-box strong {
    margin: 7px 0;
    color: #c9f508;
    font-size: 34px;
}

.practice-result-box small {
    color: #ffaa44;
    font-family: Consolas, monospace;
}

.mini-reference {
    display: grid;
    gap: 7px;
    padding: 9px;
    background: #202a33;
    border-radius: 10px;
}

.mini-reference div {
    display: grid;
    gap: 2px;
}

.mini-reference code {
    color: #c9f508;
    font-size: 12px;
}

.mini-reference span {
    color: #92a7b8;
    font-size: 10px;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0,0,0,.76);
}

.modal.show { display: flex; }

.modal-content {
    position: relative;
    width: min(820px,96vw);
    max-height: 88vh;
    overflow-y: auto;
    padding: 25px 28px;
    background: #141c23;
    border: 2px solid #0f0;
    border-radius: 16px;
    box-shadow: 0 0 25px rgba(0,255,0,.42);
}

.modal-content h2 {
    margin: 0 38px 18px 0;
    color: #c9f508;
}

.modal-content h3 { color: #ffaa44; }

.modal-content p,
.modal-content li {
    color: #d5e0e9;
    line-height: 1.55;
}

.modal-close {
    position: absolute;
    right: 14px;
    top: 10px;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
}

.ref-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    background: #0d141a;
}

.ref-table th,
.ref-table td {
    padding: 7px 8px;
    border: 1px solid #3c4d5c;
    text-align: left;
}

.ref-table th {
    background: #263746;
    color: #ffaa44;
}

.code-box {
    padding: 10px;
    background: #0a0f13;
    border-left: 3px solid #00eaff;
    color: #00eaff;
    font-family: Consolas, monospace;
    white-space: pre-wrap;
}

@media (max-width: 1500px) {
    .plc-task-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
    .layout {
        min-width: 0;
        padding: 8px;
    }

    .left-panel,
    .right-panel {
        position: static;
        width: auto;
        max-height: none;
        margin-bottom: 8px;
    }

    .center-panel {
        margin: 0 0 8px;
    }

    .io-columns {
        grid-template-columns: 1fr;
    }

    .cpu-block {
        min-height: 90px;
    }

    .trainer-head,
    .section-title-row,
    .practice-intro {
        flex-direction: column;
        align-items: stretch;
    }

    .practice-workspace {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .device-grid { grid-template-columns: repeat(2,1fr); }
    .io-grid { grid-template-columns: repeat(2,1fr); }
    .task-score { grid-template-columns: repeat(3,1fr); }
    .practice-io-wrap { grid-template-columns: 1fr; }
    .trainer-head h1 { font-size: 21px; }
}
