body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 20px;
    background: linear-gradient(180deg, #f5f7fb 0%, #e9eef7 100%);
    color: #232323;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background-color: #ffffff;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(32, 40, 56, 0.12);
}

.hero {
    text-align: center;
    margin-bottom: 24px;
}

.hero h1 {
    margin: 0;
    font-size: clamp(2rem, 2.8vw, 3rem);
    letter-spacing: -0.03em;
    color: #102a43;
}

.hero p {
    margin: 12px auto 0;
    max-width: 760px;
    color: #475569;
    line-height: 1.75;
}

.procedure {
    margin-bottom: 30px;
}

.procedure h2 {
    margin-bottom: 12px;
    color: #102a43;
}

.procedure ol {
    margin: 0;
    padding-left: 24px;
    line-height: 1.85;
    color: #334e68;
}

.procedure em {
    color: #627d98;
    font-style: normal;
}

.simulation {
    display: grid;
    gap: 24px;
    grid-template-columns: minmax(280px, 360px) 1fr;
}

.controls {
    display: grid;
    gap: 20px;
}

.panel {
    background-color: #ffffff;
    border: 1px solid #d9e2ec;
    border-radius: 18px;
    padding: 18px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.panel-title {
    margin: 0 0 14px;
    font-size: 1rem;
    font-weight: 700;
    color: #102a43;
}

.connections h3,
.switches h3 {
    margin-top: 0;
    margin-bottom: 14px;
    color: #102a43;
}

.connection-group {
    margin-bottom: 16px;
}

.connection-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.97rem;
    color: #334e68;
}

.connection-group input[type="radio"] {
    width: 18px;
    height: 18px;
}

#clearConnections {
    width: 100%;
    background-color: #0f62fe;
    color: white;
    border: none;
    padding: 12px 18px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

#clearConnections:hover {
    background-color: #0353e9;
    transform: translateY(-1px);
}

.switches {
    display: grid;
    gap: 18px;
}

.switch-visual {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #e1e8f0;
}

.switch-visual:last-child {
    border-bottom: none;
}

.switch-icon {
    width: 30px;
    height: auto;
}

.switch-state {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.9rem;
    color: #ffffff;
    background-color: #7a869a;
    white-space: nowrap;
}

.switch-state.on {
    background-color: #16ab39;
}

.switch-state.off {
    background-color: #9ba3ab;
}

.switch {
    position: relative;
    width: 58px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cad5e2;
    transition: 0.4s;
    border-radius: 999px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #0f62fe;
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.diagram {
    display: grid;
    gap: 24px;
    grid-template-columns: 280px 1fr;
    align-items: start;
}

.phase-rows {
    display: grid;
    gap: 16px;
}

.phase-row {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) 40px;
    align-items: center;
    gap: 10px;
}

.phase-number {
    font-weight: 700;
    color: #102a43;
    text-align: center;
}

.phase-track {
    position: relative;
    height: 18px;
    background-color: #e1e8f0;
    border-radius: 999px;
}

.phase-wire {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    opacity: 0.2;
    transform-origin: left center;
    background-color: #7c8ea3;
    transition: opacity 0.25s ease, background-color 0.25s ease, width 0.25s ease;
    width: 100%;
}

.phase-wire.active {
    opacity: 1;
}

.phase-wire.R {
    background-color: #dc2626;
}

.phase-wire.Y {
    background-color: #f59e0b;
}

.phase-wire.B {
    background-color: #2563eb;
}

.phase-end {
    font-weight: 700;
    color: #334e68;
    text-align: center;
}

.machine-diagram {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 260px;
}

.machine-image {
    width: 100%;
    max-width: 440px;
    display: block;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(16, 42, 67, 0.08);
}

.rotation-arrow {
    position: absolute;
    width: 90px;
    height: 90px;
    top: 16px;
    right: 16px;
    transform: none;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(16, 42, 67, 0.12);
}

.rotation-arrow svg {
    width: 100%;
    height: 100%;
    display: block;
    transform-origin: 50% 50%;
}

.arrow-ring {
    fill: none;
    stroke: #94a3b8;
    stroke-width: 5;
}

.rotation-arrow.on .arrow-ring {
    stroke: #16ab39;
}

.rotation-arrow.cw svg {
    animation: spin-clockwise 2s linear infinite;
}

.rotation-arrow.ccw svg {
    animation: spin-anticlockwise 2s linear infinite;
}

.rotation-arrow.off .arrow-ring {
    stroke: #94a3b8;
}

@keyframes spin-clockwise {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes spin-anticlockwise {
    from { transform: rotate(0deg); }
    to { transform: rotate(-360deg); }
}

.status-box {
    margin-top: 18px;
    padding: 16px;
    border-radius: 16px;
    background: #f1f5f9;
    color: #102a43;
    line-height: 1.7;
}

.status-box .phase-map {
    display: grid;
    gap: 10px;
}

.status-box .phase-map div {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #d9e2ec;
    color: #334e68;
}

#statusText {
    margin-bottom: 12px;
    font-weight: 600;
}

.phase-map {
    display: grid;
    gap: 8px;
}

.phase-map div {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    padding: 10px 12px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #d9e2ec;
}

.phase-map .label {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.78rem;
}

.phase-map .label.R { background: #dc2626; }
.phase-map .label.Y { background: #f59e0b; color: #1f2937; }
.phase-map .label.B { background: #2563eb; }

@media (max-width: 940px) {
    .simulation,
    .diagram {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    body { padding: 14px; }
    .container { padding: 18px; }
}
