:root {
  color-scheme: dark;
  --bg: #101e30;
  --ink: #effaff;
  --muted: #a5b8cc;
  --aqua: #82f6db;
  --edge: #3b566e;
  --deep: #172a40;
  --cell: min(29px, calc((100dvh - 148px) / 20));
  --cols: 10;
  font-family: ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior: none;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  background: radial-gradient(ellipse at 52% 5%, #2a4c67 0, #14253a 35%, #0d192a 79%);
  -webkit-tap-highlight-color: transparent;
}
button {
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  border: 1px solid var(--edge);
  border-radius: 8px;
  background: #253e55;
  padding: .55rem .8rem;
  touch-action: manipulation;
}
button:hover { background: #345670; }
button:focus-visible { outline: 2px solid var(--aqua); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: default; }
.primary { color: #142f38; background: var(--aqua); border-color: #b7ffed; font-weight: 800; }
.primary:hover { background: #b1ffed; }
.shell { height: 100%; width: min(1120px, 100%); margin: auto; padding-inline: clamp(10px, 4vw, 35px); }
.masthead {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #67829b54;
}
.masthead h1 { margin: 0; font-size: 1.2rem; }
.masthead nav { display: flex; gap: 5px; }
main {
  display: grid;
  grid-template-columns: minmax(180px, 245px) auto minmax(115px, 145px);
  grid-template-rows: 41px auto;
  grid-template-areas: "brief meters rail" "brief machine rail";
  align-content: center;
  align-items: start;
  justify-content: center;
  gap: 9px 22px;
  height: calc(100% - 64px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.brief {
  grid-area: brief;
  align-self: stretch;
  padding-top: 13px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.kicker { color: var(--aqua); font-size: .67rem; font-weight: 750; letter-spacing: .13em; margin: 0; text-transform: uppercase; }
.brief h2 { font-size: clamp(1.5rem, 3.1vw, 2.65rem); line-height: 1.04; letter-spacing: -.045em; margin: .45rem 0 0; }
#game-summary { max-width: 220px; color: var(--muted); line-height: 1.5; font-size: .88rem; margin: .65rem 0 1.1rem; }
.keyhint { margin-top: auto; display: grid; gap: 8px; color: var(--muted); font-size: .75rem; }
.keyhint div { display: flex; align-items: center; gap: 4px; }
.keyhint span { margin-left: 4px; }
kbd { background: #283d52; border-radius: 4px; color: var(--ink); border: 1px solid #557188; width: 23px; text-align: center; font-size: .86rem; line-height: 21px; }
.meters { grid-area: meters; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 4px; padding-inline: 2px; }
.meters div { display: grid; gap: 2px; align-content: center; min-width: 0; }
.meters div + div { border-inline-start: 1px solid #536f89a0; padding-inline-start: 10px; }
.meters span, .record span { color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-size: .64rem; white-space: nowrap; }
.meters strong,.record strong { font-variant-numeric: tabular-nums; font-size: clamp(.91rem, 2vw, 1.22rem); }
.machine {
  grid-area: machine;
  justify-self: center;
  padding: 6px;
  background: linear-gradient(145deg,#70899b,#303f54 12%,#394f63 80%,#6d8396);
  border-radius: 8px;
  border: 1px solid #94b2c6;
  box-shadow: 0 12px 35px #050b1590;
  touch-action: none;
}
.glass { width: calc(var(--cell) * var(--cols)); height: calc(var(--cell) * 20); position: relative; overflow: hidden; border-radius: 3px; background: #101a30; }
#board { display: block; width: 100%; height: 100%; }
#flash { position: absolute; top: 43%; left: 0; right: 0; text-align: center; font-size: clamp(.9rem, 3vw, 1.45rem); color: #caffe9; font-weight: 900; text-shadow: 0 2px 6px #003528, 0 0 14px #143c51; pointer-events: none; }
.curtain { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: #0f2132b5; padding: 8px; }
.curtain > div { display: grid; gap: 10px; max-width: 225px; justify-items: center; }
.curtain h2 { font-size: clamp(1.2rem, 4vw, 2rem); letter-spacing: -.035em; margin: 0; line-height: 1.02; text-wrap: balance; }
#splash-detail { margin: 0; color: #c4d6e6; font-size: .78rem; line-height: 1.45; }
.rail { grid-area: rail; min-width: 0; padding-top: 14px; }
#queue { display: grid; gap: 8px; margin-top: 10px; }
#queue canvas { display: block; width: 100%; height: auto; aspect-ratio: 1.65; background: #0e1d30b0; border-radius: 5px; border: 1px solid #3e5971b0; }
#queue canvas:first-child { border-color: #87cecb; }
.record { margin-top: 18px; border-top: 1px solid #49647d; padding-top: 11px; display: grid; gap: 5px; }
#run-note { color: var(--muted); font-size: .72rem; display: block; margin-top: 10px; overflow-wrap: anywhere; }
.touch { display: none; }
dialog { padding: 0; width: min(670px,calc(100% - 18px)); max-height: calc(100dvh - 24px); border: 1px solid #607b93; border-radius: 12px; background: #172a40; color: var(--ink); overscroll-behavior: contain; touch-action: pan-y; }
dialog::backdrop { background: #060f1ad5; }
.panel-head { position: sticky; z-index: 1; top: 0; background: #172a40; border-bottom: 1px solid #3c5670; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h2 { margin: 0; font-size: 1.16rem; }
.close { padding: .1rem .58rem; font-size: 1.45rem; }
#mode-panel,#help-panel { padding: 14px 16px 18px; }
#help-panel p,#help-panel li { line-height: 1.55; color: #d3e3ef; }
#help-panel ul { padding-inline-start: 1.25rem; }
#help-panel li + li { margin-top: .4rem; }
#mode-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
.mode-card { text-align: left; display: grid; align-content: start; gap: 4px; min-height: 75px; }
.mode-card b { font-size: .86rem; }
.mode-card small { color: #b5c9dc; font-size: .7rem; line-height: 1.3; }
button[aria-pressed="true"] { border-color: var(--aqua); }
.settings { margin-top: 12px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
#speeds,#puzzles,.panel-actions { display: flex; flex-wrap: wrap; gap: 5px; }
#puzzles button { padding-inline: .55rem; min-width: 2.4rem; }
#puzzles [data-solved] { color: var(--aqua); }
.panel-actions { margin-top: 14px; }
.rotate-message { position: fixed; inset: 0; z-index: 15; background: #101e30; display: grid; place-content: center; justify-items: center; }
.rotate-message span { font-size: 3rem; color: var(--aqua); }
@media (pointer: coarse) {
  :root { --cell: min(28px, calc((100dvh - 224px - env(safe-area-inset-bottom, 0px)) / 20)); }
  main { grid-template-rows: 39px auto 59px; grid-template-areas: "brief meters rail" "brief machine rail" ". touch ."; }
  .keyhint { display: none; }
  main { touch-action: none; }
  .touch { grid-area: touch; display: flex; justify-content: space-between; gap: 6px; touch-action: none; }
  .touch div { display: flex; gap: 5px; }
  .touch button { touch-action: none; padding: 0; width: clamp(35px, 10vw, 49px); height: 49px; font-size: 1.32rem; font-weight: 800; box-shadow: inset 0 -3px #101e30; }
  .touch button[data-held] { background: #416c83; border-color: var(--aqua); box-shadow: inset 0 1px #101e30; }
}
@media (max-width: 660px) {
  :root { --cell: min(29px, calc((100dvh - 217px - env(safe-area-inset-bottom, 0px)) / 20), calc((100vw - 98px) / var(--cols))); }
  .shell { padding-inline: max(8px, env(safe-area-inset-left), env(safe-area-inset-right)); }
  .masthead { height: 50px; }
  main {
    grid-template-columns: auto clamp(49px, 16vw, 75px);
    grid-template-rows: 32px 36px auto 51px;
    grid-template-areas: "brief brief" "meters rail" "machine rail" "touch touch";
    height: calc(100% - 50px - env(safe-area-inset-bottom,0px));
    gap: 6px 7px;
  }
  .brief { padding: 0; flex-direction: row; align-items: center; justify-content: space-between; gap: 6px; }
  .brief h2 { font-size: .96rem; margin: 0; letter-spacing: -.015em; }
  .brief .kicker,#game-summary,.keyhint { display: none; }
  .brief button { padding: .29rem .6rem; font-size: .76rem; }
  .rail { padding: 5px 0 0; }
  .rail .kicker { font-size: .57rem; letter-spacing: .06em; }
  #queue { gap: 5px; margin-top: 5px; }
  .record { margin-top: 8px; padding-top: 5px; }
  .record strong { font-size: .86rem; }
  #run-note { margin-top: 6px; font-size: .62rem; }
  #mode-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .touch button { height: 46px; }
  .machine { padding: 4px; }
}
@media (max-height: 500px) and (pointer: fine) and (min-width: 661px) {
  :root { --cell: calc((100dvh - 112px) / 20); }
  .masthead { height: 47px; }
  main { height: calc(100% - 47px); grid-template-rows: 30px auto; gap: 4px 16px; }
  #queue canvas { max-width: 76px; }
}
