* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #1b1e24; color: #e6e8ec; font: 14px/1.35 system-ui, "Segoe UI", sans-serif; overflow: hidden; }
#app { display: grid; height: 100%; grid-template-columns: 76px 230px 1fr 270px; grid-template-rows: 44px 1fr 26px;
  grid-template-areas: "top top top top" "tools palette stage right" "status status status status"; }
#top { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: #14161b; border-bottom: 1px solid #2c313a; }
.brand { font-weight: 700; font-size: 16px; margin-right: 6px; }
.spacer { flex: 1; }
.badge { padding: 2px 10px; border-radius: 99px; background: #2c313a; font-size: 12px; }
.badge.net { background: #1f5f3a; }
.badge.bad { background: #7a2630; }
#players { display: flex; gap: 6px; }
#players span { padding: 1px 8px; border-radius: 99px; font-size: 12px; color: #111; font-weight: 600; }
button { background: #2c313a; color: #e6e8ec; border: 1px solid #3a404b; border-radius: 6px; padding: 5px 10px; cursor: pointer; font: inherit; }
button:hover { background: #38404c; }
button.on { background: #2f6fb5; border-color: #4a8fd8; }
button.danger { background: #6b2a31; border-color: #8a3a42; }
button.sm { padding: 2px 7px; font-size: 12px; }
#tools { grid-area: tools; display: flex; flex-direction: column; gap: 4px; padding: 6px; background: #181b21; border-right: 1px solid #2c313a; }
#tools button { display: flex; flex-direction: column; align-items: center; padding: 6px 2px; font-size: 11px; }
#tools button span { font-size: 22px; line-height: 1.1; }
#palette { grid-area: palette; background: #1d2027; border-right: 1px solid #2c313a; padding: 10px; overflow-y: auto; }
#palette h3, #right h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #8b93a1; }
#palette .grp { margin: 10px 0 4px; font-size: 11px; text-transform: uppercase; color: #8b93a1; }
#palette button.item { display: block; width: 100%; text-align: left; margin-bottom: 4px; }
#palette .row { display: flex; gap: 6px; margin: 8px 0; }
#palette .row button { flex: 1; }
#palette label { display: block; font-size: 12px; color: #aab1bd; margin-top: 8px; }
#palette input[type=range], #palette select { width: 100%; }
#palette .note { font-size: 12px; color: #98a0ad; margin-top: 8px; }
#stage { grid-area: stage; position: relative; background: #23272e; min-width: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#hint { position: absolute; left: 10px; bottom: 8px; background: rgba(0,0,0,.55); padding: 3px 10px; border-radius: 6px; font-size: 12px; pointer-events: none; }
#toasts { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: rgba(20,22,27,.92); border: 1px solid #3a404b; padding: 6px 14px; border-radius: 8px; animation: fade 5s forwards; }
.toast.bad { border-color: #c0392b; background: rgba(90,24,24,.95); }
@keyframes fade { 0%, 85% { opacity: 1; } 100% { opacity: 0; } }
#right { grid-area: right; background: #1d2027; border-left: 1px solid #2c313a; padding: 10px; overflow-y: auto; }
.train { position: relative; padding-bottom: 20px !important; background: #262a33; border: 1px solid #343a45; border-radius: 8px; padding: 8px; margin-bottom: 8px; }
.train.sel { border-color: #4dd2ff; }
.train.der { border-color: #c0392b; }
.train .name { font-weight: 600; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.train .spd { font-variant-numeric: tabular-nums; color: #9fd1ff; }
.train input[type=range] { width: 100%; margin: 6px 0; }
.train .btns { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.train .msg { font-size: 12px; margin-top: 4px; color: #ffb4b4; }
.train .msg.warn { color: #ffd479; }
.train label { font-size: 12px; color: #aab1bd; margin-left: auto; }
#status { grid-area: status; background: #14161b; border-top: 1px solid #2c313a; padding: 3px 12px; font-size: 12px; color: #98a0ad; white-space: nowrap; overflow: hidden; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal[hidden] { display: none; }
.modal .card { background: #1d2027; border: 1px solid #3a404b; border-radius: 10px; padding: 18px 24px; max-width: 640px; }
.modal ul { padding-left: 18px; }
.modal li { margin-bottom: 6px; }
kbd { background: #2c313a; border: 1px solid #444; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; }
@media (max-width: 900px) { #app { grid-template-columns: 64px 160px 1fr 200px; } }
.train .delTrain { position: absolute; right: 4px; bottom: 2px; background: none; border: none; color: #5d6470; font-size: 15px; line-height: 1; padding: 0 4px; }
.train .delTrain:hover { color: #ff6b6b; background: none; }
#netBanner { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 5; max-width: 80%; text-align: center;
  background: #8a1f2b; color: #fff; border: 2px solid #ff6b6b; border-radius: 10px; padding: 12px 22px; font-size: 16px; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
#netBanner[hidden] { display: none; }
#netBanner small { display: block; margin-top: 4px; font-size: 12px; opacity: .85; }
body.offline #view { filter: grayscale(.85) brightness(.55); }
.suggest { margin-top: 6px; padding: 8px; background: #232831; border: 1px solid #3a404b; border-radius: 8px; }
.suggest ol, .suggest ul { margin: 2px 0 6px; padding-left: 20px; font-size: 12px; color: #c4cad4; }
.suggest li { margin-bottom: 2px; }
#stage.cabmode::after { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 3; box-shadow: inset 0 0 170px 50px rgba(0,0,0,.55); }
#cab { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
#cab[hidden] { display: none; }
.cabTop { position: absolute; top: 10px; left: 10px; display: flex; gap: 12px; align-items: center; pointer-events: auto; background: rgba(15,18,22,.88); padding: 6px 12px; border-radius: 8px; border: 1px solid #3a404b; }
.cabDash { position: absolute; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 210px 1fr 360px; gap: 12px; padding: 40px 14px 12px; background: linear-gradient(transparent, rgba(8,10,13,.88) 40%); }
.cabDash > div { pointer-events: auto; background: rgba(24,27,33,.92); border: 1px solid #3a404b; border-radius: 10px; padding: 10px 12px; }
.cabLabel { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8b93a1; margin-bottom: 4px; }
#cabSpeed { font-size: 42px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 10px; background: #2c313a; border-radius: 6px; margin: 8px 0 6px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: #3b82f6; border-radius: 6px; width: 0; }
.bar i.hot { background: #f59e0b; }
.bar b { position: absolute; top: -3px; bottom: -3px; width: 3px; background: #ff5050; }
.cabNote { font-size: 12px; color: #98a0ad; min-height: 16px; }
.cabNote.bad { color: #ff9a9a; }
.cabNote.warn { color: #ffd479; }
.cabCtl input[type=range] { width: 100%; margin: 4px 0 8px; }
.cabBtns { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.cabChk { font-size: 12px; color: #aab1bd; }
.cabAhead small { text-transform: none; letter-spacing: 0; }
#cabList { display: flex; flex-direction: column; gap: 5px; max-height: 150px; overflow: auto; }
.cabRow { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 6px; background: #1d2027; border-radius: 6px; }
.cabRow .dist { margin-left: auto; color: #9fd1ff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cabRow .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.cabRow.bad { border-left: 3px solid #ff5050; }
.cabEmpty { font-size: 12px; color: #8b93a1; }
.train .nameGroup { display: flex; align-items: center; gap: 7px; min-width: 0; }
.train .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.train .pen { background: none; border: none; padding: 0 2px; font-size: 13px; opacity: .55; cursor: pointer; line-height: 1; }
.train .pen:hover { opacity: 1; background: none; }
.train .colDot { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; padding: 0; border: 2px solid #e6e8ec; border-radius: 50%; background: none; cursor: pointer; flex: none; overflow: hidden; }
.train .colDot::-webkit-color-swatch-wrapper { padding: 0; }
.train .colDot::-webkit-color-swatch { border: none; border-radius: 50%; }
.train .colDot::-moz-color-swatch { border: none; border-radius: 50%; }
body.cabonly #app { grid-template-columns: 1fr; grid-template-areas: "top" "stage" "status"; }
body.cabonly #tools, body.cabonly #palette, body.cabonly #right { display: none; }
body.cabonly #btnNew, body.cabonly #btnSave, body.cabonly #btnLoad { display: none; }
