:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  color-scheme: light;
  --ink: #303c4a;
  --muted: #586d81;
  --line: #d5e3ef;
  --blue: #135d94;
  --tint: #eaf5fd;
  --seen: #8eddbb;
  --pressed: #ffc775;
  --mono: "IBM Plex Mono", Consolas, monospace;
  font-family: "Microsoft YaHei", "PingFang SC", Roboto, sans-serif;
  color: var(--ink);
  background: #eaf5fd;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(ellipse at 60% -20%, #91e6fd 0%, transparent 62%), linear-gradient(#bdeaff, #eaf5fd 60%); background-attachment: fixed; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button, a { touch-action: manipulation; }
button { min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 8px 15px; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
button:hover:enabled, .tool:hover { background-color: #f3faff; }
a { color: inherit; }
:focus-visible { outline: 3px solid #2378b1; outline-offset: 3px; }
[hidden] { display: none !important; }
.shell { container-type: inline-size; --gutter: clamp(16px, 5.5vw, 72px); width: min(100%, 1320px); margin: auto; padding: calc(18px + var(--safe-top)) max(var(--gutter), var(--safe-right)) calc(16px + var(--safe-bottom)) max(var(--gutter), var(--safe-left)); }
.pagehead { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); align-items: center; gap: 8px; }
.pagehead h1 { font-size: clamp(19px, 2.4vw, 33px); text-align: center; font-weight: 730; letter-spacing: .04em; }
.tool-title, .compact, .devicebar, .ctitle, .actions, .legend, .methods, .dialoghead, .loghead, .instrument-head, .instrument-foot { display: flex; align-items: center; }
.brand-mark, .back { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: #314b60; border: 1px solid #ffffffd9; background: #f7fcffcf; box-shadow: 0 4px 12px #31547212; }
.back { padding: 0; }
.primary { justify-self: end; border-color: transparent; border-radius: 24px; background: #ffffffa6; font-size: 14px; white-space: nowrap; }
.icon { width: 21px; height: 21px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#overview { display: flex; flex-direction: column; min-height: calc(100svh - 84px - var(--safe-top) - var(--safe-bottom)); }
.hero { display: grid; justify-items: center; gap: clamp(10px, 2vh, 20px); padding: clamp(24px, 4.5vh, 54px) 0 clamp(20px, 4vh, 42px); }
.devicebar { justify-content: center; flex-wrap: wrap; gap: 8px; font-size: 14px; text-align: center; }
#device { overflow-wrap: anywhere; font-weight: 550; }
.status, .badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #506477; padding: 4px 9px; border-radius: 18px; background: #eaf2f8; }
.status { background: #ffffffa1; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: #7d8f9f; }
.on { background: #def7eb; color: #166246; }
.on i { background: #18a56d; }
.piano-preview, .piano { display: block; position: relative; overflow: hidden; width: min(88cqw, 800px); height: clamp(46px, 9vw, 105px); border: 1px solid #a2afba; border-radius: 4px; background: #9ca8b3; box-shadow: 0 5px 12px #334f641c; }
.piano-preview span { position: absolute; top: 0; pointer-events: none; }
.preview-white { width: calc(100% / 52 - .7px); height: 100%; border-radius: 0 0 2px 2px; background: linear-gradient(#e8edf1, white 64%, #f6f9fb); }
.preview-black { width: calc(100% / 52 * .62); height: 62%; z-index: 1; background: linear-gradient(90deg, #20282f, #49525d 65%, #273039); border-radius: 0 0 2px 2px; }
.piano-preview .seen { background: var(--seen); }
.piano-preview .active { background: var(--pressed); }
#transport, footer { color: var(--muted); font-size: 13px; }
#transport { letter-spacing: .04em; }
.tools { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: clamp(8px, 1.2vw, 16px); }
.tool { background: #fff; text-decoration: none; border-radius: 18px; min-width: 0; color: #263341; }
.tool:active { background: #eaf6ff; }
.feature { display: flex; flex-direction: column; grid-row: span 2; padding: clamp(15px, 2.1vw, 29px); }
.tool-title { gap: 9px; font-weight: 700; font-size: clamp(17px, 1.7vw, 25px); padding-bottom: 14px; border-bottom: 1px solid #cfdfeb; }
.cover-count, .swatches { display: flex; align-items: center; gap: 5px; min-height: 34px; margin: auto 0 7px; padding-top: 12px; }
.cover-count b { font-size: clamp(22px, 2.2vw, 32px); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.cover-count small, .tool-sub, .compact small { font-size: 14px; font-weight: 400; color: var(--muted); }
.swatches i { height: 20px; width: 19%; max-width: 36px; border-radius: 5px; background: #ff788a; }
.swatches i:nth-child(2) { background: #64d7a4; }
.swatches i:nth-child(3) { background: #5eabff; }
.compact { padding: clamp(13px, 1.6vw, 24px); gap: 13px; min-height: 76px; }
.compact b, .compact small { display: block; }
.compact b { font-size: clamp(16px, 1.45vw, 21px); }
.compact small { margin-top: 3px; }
.tools .test-passed { color: #167044; font-weight: 650; }
#fw-unlock { max-width: 440px; margin: auto; }
#fw-unlock label { display: block; margin-bottom: 8px; font-weight: 600; }
#fw-unlock button { margin-top: 12px; }
#fw-password-error { color: #92362f; }
footer { margin-top: auto; padding-top: 24px; text-align: center; }
.detail { max-width: 920px; margin: clamp(22px, 4vh, 45px) auto; }
.instrument, .card, .panel, dialog { background: #fff; border: 0; border-radius: 18px; padding: clamp(16px, 2.5vw, 30px); }
.instrument { margin-bottom: 12px; }
.instrument-head, .instrument-foot, .dialoghead, .loghead { justify-content: space-between; gap: 10px; }
.instrument-head h2, .ctitle h3, dialog h2 { font-size: 19px; }
.range, .legend, .mono, .progress-heading, .hardware-data span, .fw-link, #fw-detail, dialog p { color: var(--muted); font-size: 14px; }
.range b { margin-right: 4px; color: var(--ink); }
.piano { margin: 14px auto 10px; user-select: none; }
.key { position: absolute; top: 0; min-height: 0; padding: 0; border: 0; overflow: hidden; display: flex; align-items: flex-end; justify-content: center; font: 11px var(--mono); }
.key.white-key { width: calc(100% / 52 - 1px); height: 100%; padding-bottom: 7px; border-radius: 1px 1px 3px 3px; background: linear-gradient(#dce2e6,#fff 68%,#f4f6f8); box-shadow: inset 0 -4px #cbd4dc; }
.key.black-key { width: calc(100% / 52 * .62); height: 62%; border-radius: 0 0 3px 3px; background: linear-gradient(90deg,#25292e,#444b53 66%,#22282e); z-index: 2; box-shadow: inset 0 -5px #1e252a,1px 2px 2px #0004; }
.key.seen { background: var(--seen); box-shadow: inset 0 -4px #59af8b; }
.key.active { background: var(--pressed); box-shadow: inset 0 -4px #da9d47; }
.legend { gap: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; }
.white { background: #fff; border: 1px solid #b3bdc5; }
.mint { background: var(--seen); }
.gold { background: var(--pressed); }
.mono { font-family: var(--mono); }
.ctitle { gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.ctitle .badge { margin-left: auto; }
.progress-heading, .fw-progress > div { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 6px; }
.progress-heading strong { color: var(--ink); font-size: 20px; }
progress { width: 100%; height: 7px; accent-color: #2c8b75; }
.actions, .methods, .fw-buttons { gap: 8px; flex-wrap: wrap; }
.actions, .methods { margin-top: 16px; }
.accent { background: var(--tint); border-color: #bddeef; color: var(--blue); }
.quiet { background: transparent; color: var(--muted); border-color: transparent; }
.light-ranges, #ports fieldset { min-width: 0; margin: 16px 0 8px; padding: 0; border: 0; }
.light-ranges legend, #ports legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.light-ranges > div { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
.light-ranges button { padding-inline: 4px; }
.light-ranges [aria-pressed=true] { background: var(--tint); color: var(--blue); border-color: #96cce9; }
.colors { display: flex; gap: 8px; margin-top: 16px; }
.colors button { display: flex; align-items: center; justify-content: center; gap: 6px; }
.colors i { display: inline-block; width: 12px; height: 16px; border-radius: 3px; }
.red { background: #ff788a; } .green { background: #64d7a4; } .blue { background: #5eabff; }
.colors .selected { outline: 2px solid var(--blue); }
.pedals, .hardware-data { display: grid; gap: 8px; margin-top: 18px; }
.pedals { grid-template-columns: repeat(3,minmax(0,1fr)); }
.pedals > div, .hardware-data > div { display: grid; justify-items: center; align-content: center; gap: 5px; padding: 12px 2px; background: #f3f7fa; border-radius: 10px; text-align: center; }
.pedals .detected { background: #dcf5e8; color: #176447; }
.pedals small { color: var(--muted); font-family: var(--mono); }
.pedal-symbol { height: 23px; width: 14px; transform: skew(-16deg); background: #c3cfd6; border-radius: 6px 6px 3px 3px; border-bottom: 3px solid #8899a6; }
.detected .pedal-symbol { background: #79cd9e; border-color: #439365; }
.hardware-data { grid-template-columns: repeat(3,minmax(0,1fr)); margin-bottom: 16px; }
.hardware-data b { overflow-wrap: anywhere; max-width: 100%; }
#read, .methods button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.fw-link, #fw-detail, dialog p { line-height: 1.6; margin-top: 10px; }
.fw-fields { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; min-width: 0; margin: 15px 0; padding: 0; border: none; }
.fw-fields label:first-child { grid-column: 1 / -1; }
.fw-fields label, #ports label { display: grid; min-width: 0; gap: 5px; font-size: 14px; font-weight: 550; }
input:not([type=range]), select { width: 100%; min-width: 0; min-height: 44px; padding: 8px 10px; background: #fcfdff; border: 1px solid var(--line); border-radius: 9px; }
input[type=file]::file-selector-button { border: 0; padding: 5px 10px; border-radius: 5px; background: var(--tint); color: var(--blue); }
.fw-package { display: flex; flex-wrap: wrap; gap: 12px 30px; margin: 12px 0; padding: 12px; border-radius: 10px; background: var(--tint); }
.fw-package dt { font-size: 13px; color: var(--muted); }
.fw-package dd { margin: 4px 0 0; font: 14px var(--mono); overflow-wrap: anywhere; }
.fw-buttons { display: flex; justify-content: flex-end; margin-top: 12px; }
.firmware[data-error=true] #fw-detail, #command-error { color: #92362f; }
.loghead { border-bottom: 1px solid var(--line); }
.loghead .ctitle { padding: 0; border: none; }
.logbody { max-height: clamp(130px, 38vh, 330px); overflow: auto; padding: 8px 0; }
.empty { padding: 20px 0; text-align: center; color: var(--muted); }
.logrow { display: grid; grid-template-columns: 7em 2.7em minmax(0,1fr); gap: 4px; padding: 6px 0; border-bottom: 1px solid #e9eff5; font: 12px var(--mono); overflow-wrap: anywhere; }
.logrow time { color: var(--muted); }
.logrow b { color: var(--blue); }
.command-form { border-top: 1px solid var(--line); padding-top: 12px; }
.command-row { display: flex; gap: 8px; margin-top: 6px; }
.command-row input { flex: 1; font-family: var(--mono); }
#command-error { margin-top: 5px; font-size: 14px; }
dialog { inset: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); margin: auto; width: min(430px, calc(100% - var(--safe-left) - var(--safe-right) - 24px)); max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 24px); overflow-y: auto; color: var(--ink); box-shadow: 0 18px 65px #19374a30; }
dialog::backdrop { background: #29415b66; }
.close { font-size: 22px; min-width: 44px; padding: 4px; border: 0; }
.methods button { flex: 1; }
#ports label, #ble-devices button { border: 1px solid var(--line); border-radius: 12px; background: #f6fbff; padding: 10px 12px; overflow-wrap: anywhere; min-height: 44px; }
#ports label { display: flex; align-items: center; gap: 9px; margin: 4px 0; }
#ports input[type=radio] { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--blue); flex-shrink: 0; }
.scan-heading { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
#ble-devices { display: grid; gap: 6px; max-height: 36vh; overflow: auto; }
#ble-devices button { display: grid; text-align: left; gap: 4px; }
#ble-devices small { font-weight: normal; color: var(--muted); }
#dialog-status:empty { display: none; }
#disconnect { margin-top: 12px; }
.toast { position: fixed; z-index: 6; bottom: calc(18px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); background: #35414e; color: white; border-radius: 10px; padding: 11px 17px; width: max-content; max-width: 90vw; font-size: 14px; }

@media (orientation: portrait), (max-width: 600px) {
  .tools { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .feature { grid-row: auto; min-height: clamp(124px, 17vh, 160px); }
  .compact { min-height: clamp(60px, 8vh, 82px); }
  .hero { padding-block: clamp(24px, 5vh, 56px); }
  .piano-preview, .piano { width: min(89cqw, 800px); }
}
@media (max-width: 620px) {
  .pagehead { grid-template-columns: auto minmax(0,1fr) auto; gap: 5px; }
  .pagehead h1 { font-size: clamp(16px, 4.8vw, 19px); letter-spacing: normal; }
  .brand-mark, .back { width: 42px; height: 42px; }
  .tool { border-radius: 14px; }
  .compact { gap: 9px; }
  .primary { padding-inline: 12px; }
  .fw-fields { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .fw-fields label:last-child { grid-column: 1 / -1; }
  .colors button { flex: 1; padding-inline: 6px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .shell { --gutter: clamp(16px,5vw,50px); padding-top: calc(8px + var(--safe-top)); padding-bottom: calc(8px + var(--safe-bottom)); }
  #overview { min-height: calc(100svh - 60px - var(--safe-top) - var(--safe-bottom)); }
  .hero { padding: 5px 0 10px; gap: 4px; }
  .piano-preview, .piano { width: min(78cqw, 720px); height: clamp(40px, 16vh, 65px); }
  .devicebar, #transport, footer { font-size: 12px; }
  .tools { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .feature { grid-row: span 2; min-height: 0; padding: 12px; }
  .compact { min-height: 52px; padding: 8px 12px; gap: 8px; }
  .tool-title { padding-bottom: 7px; }
  .cover-count, .swatches { padding-top: 6px; }
  footer { padding-top: 8px; }
  .detail { margin-block: 12px; }
}
@media (prefers-reduced-motion: no-preference) {
  .tool, button { transition: background-color .15s; }
}

#fw-advanced { grid-column: 1 / -1; }
#fw-advanced summary { cursor: pointer; }
#fw-advanced label:first-child { grid-column: auto; }
#fw-summary { white-space: pre-line; overflow-wrap: anywhere; }
#fw-confirm .fw-buttons { margin-top: 16px; }
