:root {
    --ink: #142e46;
    --muted: #5b7182;
    --blue: #155b89;
    --teal: #087e81;
    --line: #d6e4e8;
    --layer-app: #fbe6ce;
    --layer-pres: #f8efd2;
    --layer-sess: #e8edfa;
    --layer-tcp: #dfeaf6;
    --layer-ip: #e4f0e5;
    --layer-mac: #dcefed;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Noto Sans TC', sans-serif;
    color: var(--ink);
    background: #eef4f4;
    line-height: 1.65;
}
header {
    color: #fff;
    background: #102e43;
    background-image: radial-gradient(circle at 85% 20%, rgba(35, 162, 159, .24), transparent 31%), linear-gradient(120deg, #102e43, #174c60);
    position: relative;
    overflow: hidden;
}
header::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
    background-size: 36px 36px;
    pointer-events: none;
}
.header-inner { max-width: 1440px; margin: auto; padding: 42px 40px 48px; display: flex; align-items: center; justify-content: space-between; gap: 30px; position: relative; z-index: 1; }
.eyebrow { margin: 0 0 10px; color: #85d6ce; font-size: .75rem; font-weight: 700; letter-spacing: .16em; }
.eyebrow span { color: #6a999f; }
header h1 { margin: 0; font-size: clamp(2rem, 3vw, 2.9rem); letter-spacing: .04em; line-height: 1.25; }
header h1 span { color: #8de0d0; }
.header-subtitle { margin: 12px 0 0; color: #c2d8dd; }
.header-mark { display: flex; align-items: center; gap: 12px; color: #a5d9d3; font-family: monospace; font-size: .8rem; letter-spacing: .08em; }
.header-mark span { padding: 10px 12px; border: 1px solid #6eaaa8; border-radius: 6px; }
.header-mark b { color: #76d4c9; font-size: 1.2rem; }
.container { max-width: 1440px; margin: 0 auto; padding: 30px 40px 70px; }
.controls, .info-panel, .stage { background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 12px 35px rgba(20, 54, 65, .06); }
.controls { display: grid; grid-template-columns: minmax(220px, 1.5fr) minmax(150px, .75fr) minmax(150px, .75fr); gap: 18px 22px; padding: 24px 28px; }
.input-group, .mode-control, .speed-control { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.controls label { font-size: .82rem; font-weight: 700; color: #435e6b; }
input[type="text"], select { width: 100%; min-height: 44px; border: 1px solid #bfd1d6; border-radius: 8px; background: #f9fcfc; color: var(--ink); padding: 9px 12px; font: inherit; }
input[type="range"] { accent-color: var(--teal); width: 100%; margin: 12px 0; }
input:disabled { opacity: .5; }
.button-group { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; }
.btn { min-height: 43px; padding: 9px 20px; border: 1px solid transparent; border-radius: 8px; font: inherit; font-weight: 700; cursor: pointer; transition: background .2s, transform .2s, box-shadow .2s; }
.btn:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 5px 14px rgba(18, 71, 85, .15); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary span { margin-left: 10px; color: #8de0d0; }
.btn.next { background: var(--teal); color: #fff; }
.btn.warning, .btn.secondary { background: #f2f6f6; border-color: #d3e1e3; color: var(--ink); }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.mode-hint { grid-column: 1 / -1; margin: -8px 0 0; font-size: .82rem; color: var(--muted); }
.info-panel { margin-top: 18px; padding: 22px 28px; border-left: 4px solid var(--teal); }
.info-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .05em; }
.step-status { color: #116f70; background: #e1f2ef; border-radius: 999px; padding: 4px 12px; letter-spacing: 0; }
.explanation-box { margin-top: 10px; font-size: 1.08rem; font-weight: 500; }
.model-note { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid #e5eeee; color: #647985; font-size: .8rem; }
.stage-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin: 36px 0 14px; }
.stage-heading .eyebrow { margin-bottom: 2px; }
.eyebrow.dark { color: var(--teal); }
.stage-heading h2 { margin: 0; font-size: 1.4rem; }
.stage-heading > p { margin: 0; color: var(--muted); font-size: .85rem; }
.stage { display: flex; justify-content: center; align-items: flex-start; padding: 28px 18px 38px; position: relative; min-height: 510px; }
.layer-list { display: flex; flex-direction: column; gap: 7px; min-width: 103px; }
.layer-item { width: 100%; padding: 9px 12px; background: #f2f6f6; border: 1px solid #e1ebeb; border-radius: 8px; font: inherit; font-size: .82rem; font-weight: 500; color: #526b78; text-align: center; white-space: nowrap; cursor: pointer; transition: background .2s, color .2s, border-color .2s; }
.layer-item:hover { background: #e4f2ef; border-color: #a6cfca; }
.layer-item.active { background: var(--blue); color: #fff; border-color: var(--blue); box-shadow: 0 4px 10px rgba(21,91,137,.2); }
.layer-item:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, .back-to-home-btn:focus-visible { outline: 3px solid #52b9ad; outline-offset: 3px; }
.sender-layers { order: 1; }
.device.sender { order: 2; }
.network-path { order: 3; flex: 0 0 125px; min-width: 125px; display: flex; align-items: center; justify-content: center; position: relative; margin: 0 8px; }
.network-path::before { content: ''; position: absolute; top: 50%; left: -213px; width: calc(100% + 426px); height: 4px; transform: translateY(-50%); border-radius: 4px; background: #83bcb7; pointer-events: none; }
.device.receiver { order: 4; }
.receiver-layers { order: 5; }
.device { display: flex; flex-direction: column; align-items: center; width: 410px; min-width: 0; z-index: 2; }
.device-icon { font-size: 2.8rem; line-height: 1.15; margin-bottom: 8px; }
.device > .device-icon { position: relative; background: #fff; border-radius: 8px; }
.device-label { font-size: .9rem; font-weight: 700; margin-bottom: 16px; color: #284b5c; }
.stack-container { width: min(100%, 390px); min-height: 280px; display: flex; flex-direction: column-reverse; align-items: center; justify-content: flex-end; position: relative; }
.router { background: #fff; padding: 12px; border-radius: 50%; border: 2px solid #c6e2de; z-index: 5; text-align: center; }
.router .device-icon { font-size: 1.8rem; margin: 0; }
.router .device-label { font-size: .72rem; margin: 0; white-space: nowrap; }
.router.active { border-color: var(--teal); box-shadow: 0 0 0 5px #d9f0eb; animation: pulse .5s ease-in-out; }
.hop-details { position: absolute; top: calc(100% + 10px); left: 50%; transform: translateX(-50%); width: 220px; padding: 10px; border-radius: 8px; background: #e5f4f1; color: #235c5e; font-size: .72rem; text-align: center; overflow-wrap: anywhere; z-index: 20; }
.hop-details.hidden, .flying-packet.hidden, .final-message.hidden { display: none; }
.data-unit { width: 100%; padding: 8px; border-radius: 8px; text-align: center; font-weight: 700; transition: opacity .5s ease, transform .5s ease; position: relative; border: 1px solid rgba(34, 77, 87, .18); }
.layer-app { background: var(--layer-app); }
.layer-pres { background: var(--layer-pres); }
.layer-sess { background: var(--layer-sess); }
.layer-tcp { background: var(--layer-tcp); }
.layer-ip { background: var(--layer-ip); }
.layer-mac { background: var(--layer-mac); }
.layer-header-block { display: flex; align-items: center; gap: 8px; border-bottom: 1px dashed rgba(34,77,87,.2); padding-bottom: 4px; margin-bottom: 5px; min-width: 0; }
.header-title { font-size: .75rem; flex: 0 0 auto; white-space: nowrap; }
.header-details { font-family: monospace; font-size: .66rem; text-align: left; line-height: 1.3; flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.message-content { font-size: 1rem; overflow-wrap: anywhere; }
.flying-packet { position: absolute; width: 55px; height: 36px; background: #1c7778; color: white; border: 2px solid #a9e4d8; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-family: monospace; font-size: .75rem; font-weight: 700; z-index: 100; box-shadow: 0 3px 12px rgba(22, 113, 110, .3); transform: translate(-50%, -50%); }
.final-message { margin-top: 16px; padding: 12px 18px; background: #d9f3eb; color: #165c52; border-radius: 10px; font-weight: 700; overflow-wrap: anywhere; animation: popIn .4s ease; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
footer { text-align: center; color: #718993; font-size: .7rem; font-weight: 700; letter-spacing: .12em; padding: 15px 100px 35px; }
footer span { color: var(--teal); }
.back-to-home-btn { position: fixed; bottom: 20px; right: 20px; display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 9px; background: #163f50; color: #fff; font-size: .85rem; font-weight: 700; text-decoration: none; box-shadow: 0 6px 20px rgba(13, 48, 61, .25); z-index: 999; }
.back-to-home-btn:hover { background: #087e81; }
.back-to-home-btn svg { width: 17px; height: 17px; }
@media (max-width: 1300px) {
    .stage { flex-direction: column; align-items: stretch; gap: 18px; min-height: 0; }
    .layer-list { flex-direction: row; flex-wrap: wrap; justify-content: center; min-width: 0; }
    .layer-item { width: auto; }
    .device { width: 100%; max-width: 430px; margin: 0 auto; }
    .device.sender { position: relative; }
    .device.sender::after { content: ''; position: absolute; top: 24px; bottom: -18px; left: 50%; width: 4px; transform: translateX(-50%); background: #83bcb7; z-index: -1; pointer-events: none; }
    .device > .device-label { position: relative; background: #fff; }
    .network-path { flex: 0 0 170px; width: 100%; min-width: 0; margin: 0; }
    .network-path::before { top: -18px; left: 50%; width: 4px; height: calc(100% + 36px); transform: translateX(-50%); }
    .hop-details { top: 50%; left: calc(50% + 55px); transform: translateY(-50%); width: min(35%, 250px); }
}
@media (max-width: 800px) {
    .header-inner { padding: 32px 24px; }
    .header-mark { display: none; }
    .container { padding: 24px 20px 65px; }
    .controls { grid-template-columns: 1fr 1fr; }
    .input-group { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
