:root {
  color-scheme: dark;
  --bg: #151617;
  --panel: #202224;
  --panel-line: #3b3e40;
  --text: #f4f1e8;
  --muted: #c9cccd;
  --subtle: #a9adaf;
  --accent: #f0b548;
  --red: #e44535;
  --blue: #3975cf;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { min-width: 0; background: var(--bg); }
.shell, .game-frame, canvas, .orders, .topbar, footer, .touch-controls, .how-to-guide {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.shell.with-touch .game-frame, .shell.with-touch canvas { touch-action: none; }
input, textarea, select { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
button { font: inherit; }
input, select { font: inherit; }
[hidden] { display: none !important; }
.mode-badge { display: inline-block; margin-top: 5px; color: var(--accent); font-size: 10px; font-weight: 750; }
.release-settings { margin-top: 12px; padding: 10px; background: #151718; border: 1px solid #505457; border-radius: 9px; }
.player-name-setting { display: grid; grid-template-columns: auto minmax(150px, 1fr); align-items: center; gap: 5px 10px; margin-bottom: 9px; }
.player-name-setting input { min-width: 0; padding: 7px 9px; border: 1px solid #707477; border-radius: 6px; background: #26292b; color: white; }
.player-name-setting small, .player-name-setting p { grid-column: 1 / -1; margin: 0; }
.player-name-setting p { min-height: 14px; color: #ffb14a; font-size: 11px; font-weight: 800; }
.difficulty-setting { display: flex; align-items: center; gap: 8px; }
.release-settings label { margin-right: 10px; font-size: 12px; font-weight: 800; }
.release-settings select, .ranking select { border: 1px solid #707477; border-radius: 5px; padding: 5px 8px; background: #26292b; color: white; }
.release-settings p { margin: 6px 0 3px; font-size: 12px; }
.release-settings small, .ranking-note { color: #c9cccd; font-size: 10px; }
.sound-toggle { position: absolute; left: 8px; bottom: 8px; z-index: 2; padding: 6px 9px; border: 1px solid #ffffff70; border-radius: 7px; background: #161819e8; color: white; cursor: pointer; }
.record-form { margin: 12px 0; padding: 12px; background: #151718; border: 1px solid #b18c41; border-radius: 8px; }
.record-form label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 800; }
.record-form > div { display: flex; gap: 6px; }
.record-form input { width: 100%; min-width: 0; padding: 8px; background: #303436; color: white; border: 1px solid #777; border-radius: 5px; }
.record-form button { flex-shrink: 0; padding: 8px 12px; border: 0; border-radius: 5px; background: var(--accent); color: #17191a; cursor: pointer; font-weight: 800; }
.record-form button:disabled { opacity: .55; cursor: default; }
.record-form p { margin: 6px 0 0; font-size: 11px; color: var(--accent); }
.ranking { margin-top: 13px; border-top: 1px solid #525658; padding-top: 10px; }
.ranking summary { cursor: pointer; font-size: 12px; font-weight: 800; }
.ranking-filters { display: flex; gap: 7px; margin-top: 9px; }
.ranking-list { padding-left: 22px; margin: 8px 0; font-size: 11px; }
.ranking-list li { margin: 7px 0; padding-left: 3px; }
.ranking-list li > * { margin-right: 8px; }
.record-player { display: inline-block; max-width: 130px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; white-space: nowrap; }
.ranking-list strong { color: var(--accent); }
.ranking-empty { list-style: none; margin-left: -20px !important; color: var(--muted); }
.record-form small { display: block; margin-top: 7px; color: var(--muted); font-size: 10px; }
.record-rank { display: inline-block; min-width: 19px; color: var(--accent); font-weight: 900; }
.result-award { display: flex; gap: 16px; align-items: center; margin-top: 15px; padding: 12px 18px; border: 1px solid #b59457; border-radius: 12px; background: linear-gradient(125deg,#4d3821,#26292b); }
.award-letter { color: #ffd568; font-size: 58px; line-height: 1; font-weight: 1000; }
.award-copy b { font-size: 20px; }
.award-copy p { margin: 5px 0 0; color: #ddd4c3; font-size: 11px; }
.result-award[data-rank="S"] { border-color: #ffd568; box-shadow: inset 0 0 30px #f0b54820; }
.shell.with-touch { grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
.touch-controls { display: flex; gap: 10px; justify-content: center; padding: 3px 4px max(3px, env(safe-area-inset-bottom)); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.touch-player { display: flex; position: relative; align-items: center; justify-content: space-between; gap: 12px; width: min(540px, 100%); padding: 4px 12px; border: 1px solid #e4453560; border-radius: 12px; background: #231e1e; }
.touch-player-2 { background: #1c222c; border-color: #3975cf80; }
.touch-player-label { position: absolute; top: 5px; left: 10px; font-size: 10px; color: #ff9388; }
.touch-player-2 .touch-player-label { color: #91baff; }
.touch-pad { display: grid; grid-template-columns: repeat(3,44px); grid-template-rows: repeat(2,40px); gap: 3px; }
.touch-controls button { touch-action: none; min-width: 44px; min-height: 40px; padding: 5px; border: 1px solid #ffffff40; border-radius: 9px; background: #3b3c3d; color: white; font-size: 13px; font-weight: 800; -webkit-tap-highlight-color: transparent; }
.touch-controls button.is-held { background: #b85332; border-color: #ffc75c; transform: scale(.95); }
.touch-controls button:disabled { opacity: .35; }
.touch-up { grid-column: 2; grid-row: 1; }
.touch-left { grid-column: 1; grid-row: 2; }
.touch-down { grid-column: 2; grid-row: 2; }
.touch-right { grid-column: 3; grid-row: 2; }
.touch-actions { display: grid; grid-template-columns: repeat(2, minmax(54px,1fr)); gap: 5px; }
.touch-actions .touch-action { grid-row: span 2; background: #ad372c; min-width: 62px; }
.touch-player-2 .touch-action { background: #2e61a9; }
.touch-actions .touch-dash { background: #856329; }
@media (max-width: 680px) {
  .touch-controls { gap: 4px; padding-inline: 0; }
  .touch-player { padding: 4px; gap: 4px; }
  .touch-controls.two-players .touch-pad { grid-template-columns: repeat(3,32px); grid-template-rows: repeat(2,42px); }
  .touch-controls.two-players button { min-width: 32px; font-size: 10px; }
  .touch-controls.two-players .touch-actions { grid-template-columns: 42px; gap: 3px; }
  .touch-controls.two-players .touch-action { grid-row: auto; min-width: 32px; }
  .touch-controls.two-players .touch-actions button { min-height: 30px; }
}

.shell {
  width: 100%;
  height: 100dvh;
  margin: 0;
  padding: clamp(5px, .8vw, 12px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 6px;
  overflow: hidden;
}

.topbar { min-height: 42px; display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.eyebrow { margin: 0 0 1px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: .13em; }
h1 { margin: 0; font-size: clamp(17px, 2vw, 25px); line-height: 1; letter-spacing: -.04em; }
.stats { display: flex; gap: 5px; }
.stats div { min-width: 72px; padding: 5px 9px; border: 1px solid var(--panel-line); border-radius: var(--radius-sm); background: var(--panel); }
.stats span { display: block; color: var(--muted); font-size: 9px; }
.stats strong { font-size: clamp(14px, 1.6vw, 18px); line-height: 1.05; }
.rating-stat strong { color: #4bb66a; }
.ranking-shortcut { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid #f0b54880; border-radius: var(--radius-sm); background: #372d1d; color: #ffd568; cursor: pointer; font-weight: 900; }
.ranking-shortcut span { color: inherit; font-size: 11px; }
.ranking-shortcut span:first-child { font-size: 16px; }
.ranking-shortcut:hover, .ranking-shortcut:focus-visible { border-color: var(--accent); background: #4a3820; outline: none; }
.ranking-dialog { width: min(520px, calc(100vw - 24px)); max-height: min(650px, calc(100dvh - 24px)); padding: 0; overflow: hidden; border: 1px solid #b18c41; border-radius: 12px; background: #202224; color: var(--text); box-shadow: 0 18px 70px #000c; }
.ranking-dialog::backdrop { background: #08090bd9; backdrop-filter: blur(3px); }
.ranking-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid #4d4536; background: #17191a; }
.ranking-dialog-head h2 { margin: 0; font-size: 22px; }
.ranking-dialog-head button { width: 36px; height: 36px; border: 1px solid #ffffff50; border-radius: 7px; background: #2c2f31; color: white; cursor: pointer; }
#ranking-dialog-body { max-height: calc(min(650px, 100dvh - 24px) - 67px); padding: 6px 16px 16px; overflow-y: auto; }
#ranking-dialog-body .ranking { margin-top: 0; border-top: 0; padding-top: 8px; }
#ranking-dialog-body .ranking summary { display: none; }
#ranking-dialog-body .ranking-list { font-size: 13px; }
#ranking-dialog-body .ranking-list li { margin: 10px 0; }

.orders {
  height: clamp(94px, 13vh, 116px);
  min-height: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 6px;
}
.queue-summary { width: auto; min-width: 0; display: grid; place-content: center; border: 3px solid #0c0c0c; border-radius: 6px; background: #ffd200; color: #0c0c0c; box-shadow: 3px 3px 0 #e44535; text-align: center; font-size: 10px; font-weight: 900; }
.queue-summary strong { font-size: 20px; color: #0c0c0c; }
.dot { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--accent); }
.order-cards { min-width: 0; display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 0 4px 4px 0; scrollbar-width: thin; scrollbar-color: #e44535 #252729; }
.order-card { --ticket-number-col: 68px; position: relative; flex: 0 0 clamp(238px, 24vw, 310px); min-width: 0; height: calc(100% - 4px); padding: 5px 7px 10px; display: grid; grid-template-columns: var(--ticket-number-col) minmax(0, 1fr); gap: 7px; overflow: hidden; border: 3px solid #0c0c0c; border-radius: 6px; background: #fff9df; color: #0c0c0c; box-shadow: 4px 4px 0 #e44535; }
.kds-copy { min-width: 0; }
.kds-head { display: flex; justify-content: space-between; align-items: center; gap: 5px; border-bottom: 2px solid #0c0c0c; padding-bottom: 3px; }
.kds-source { width: max-content; max-width: 100%; padding: 2px 5px; overflow: hidden; border: 2px solid #0c0c0c; border-radius: 3px; background: #ffd200; font-size: 8px; font-weight: 1000; white-space: nowrap; text-overflow: ellipsis; }
.kds-number { grid-row: 1 / 2; display: grid; place-items: center; align-self: stretch; min-width: 0; overflow: hidden; border-right: 2px solid #0c0c0c; color: #e6201f; font-size: 30px; font-variant-numeric: tabular-nums; letter-spacing: -.06em; line-height: .9; white-space: nowrap; }
.kds-head small { font-size: 9px; font-weight: 900; }
.kds-body { min-width: 0; padding-top: 3px; line-height: 1.05; }
.kds-body b, .kds-body strong, .kds-body small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kds-body b, .kds-body strong, .kds-body small { display: block; }
.kds-body b { font-size: clamp(11px, 1.1vw, 15px); }
.kds-body strong { color: #9f1f17; font-size: clamp(10px, 1vw, 14px); }
.kds-body small { margin-top: 2px; color: #5f574f; font-size: 9px; font-weight: 800; }
.kds-foot { position: absolute; right: 7px; bottom: 8px; left: calc(var(--ticket-number-col) + 14px); display: flex; justify-content: space-between; color: #5f574f; font-size: 8px; font-weight: 900; }
.order-card .bar { position: absolute; inset: auto 0 0; height: 6px; background: #d7d7d2; }
.order-card .fill { height: 100%; background: #4bb66a; }

.game-frame {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid var(--panel-line);
  border-radius: var(--radius-md);
  background: #090a0b;
  box-shadow: 0 10px 35px #0007;
}
canvas { display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; flex: 0 0 auto; }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 12px; background: #101213db; backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.panel { width: min(920px, 100%); max-height: 100%; padding: clamp(14px, 2.4vh, 24px); overflow: auto; border: 1px solid #595d5f; border-radius: var(--radius-lg); background: var(--panel); box-shadow: 0 24px 70px #0009; }
.panel h2 { margin: 0 0 6px; font-size: clamp(23px, 3.6vh, 31px); letter-spacing: -.04em; }
.panel > p:not(.eyebrow) { margin: 6px 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.recipes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0; }
.recipes span, .controls div { padding: 8px 10px; border-radius: var(--radius-sm); background: #2c2f31; font-size: 12px; }
.recipes b { display: block; color: var(--accent); }
.controls { display: grid; gap: 5px; color: #eef0f1; }
.how-to-guide { display: block; width: 100%; height: min(32vh, 300px); object-fit: contain; margin: 10px 0; border: 1px solid #4d5052; border-radius: 10px; background: #18181a; }
.how-to-guide[hidden] { display: none; }
.buttons { display: flex; gap: 8px; margin-top: 14px; }
.buttons button[hidden] { display: none; }
.buttons button, .restart { flex: 1; padding: 11px 14px; border: 0; border-radius: var(--radius-sm); background: var(--red); color: white; font-weight: 800; cursor: pointer; }
.buttons button:last-child { background: var(--blue); }
.restart { width: 100%; margin-top: 14px; }
.pause { position: absolute; right: 8px; bottom: 8px; padding: 6px 9px; border: 1px solid #ffffff70; border-radius: 7px; background: #161819e8; color: white; cursor: pointer; }

footer { min-width: 0; min-height: 18px; display: flex; justify-content: space-between; align-items: center; gap: 14px; overflow: hidden; color: var(--muted); font-size: 11px; }
footer p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message { flex: 0 1 auto; color: var(--accent); font-weight: 800; text-align: right; }

@media (max-width: 900px) {
  .shell { padding: 4px; gap: 4px; }
  .topbar { min-height: 36px; }
  .eyebrow { display: none; }
  h1 { font-size: 16px; }
  .stats { gap: 3px; }
  .stats div { min-width: 57px; padding: 4px 6px; }
  .stats span { font-size: 8px; }
  .stats strong { font-size: 14px; }
  .ranking-shortcut { padding: 4px 7px; }
  .orders { height: 94px; grid-template-columns: 68px minmax(0, 1fr); gap: 4px; }
  .queue-summary { font-size: 9px; }
  .queue-summary strong { font-size: 15px; }
  .order-cards { gap: 7px; }
  .order-card { --ticket-number-col: 58px; flex-basis: 238px; padding: 5px 6px 10px; }
  .kds-number { font-size: 25px; }
  .kds-body b { font-size: 11px; }
  .kds-body strong { font-size: 10px; }
  footer p:first-child { display: none; }
  footer { justify-content: flex-end; }
  .panel > p:not(.eyebrow) { font-size: 12px; }
}

@media (max-height: 820px) {
  .topbar { min-height: 34px; }
  .orders { height: 92px; }
  .panel { padding: 14px 18px; }
  .panel h2 { font-size: 22px; }
  .how-to-guide { height: min(20vh, 165px); margin: 6px 0; }
  .release-settings { margin-top: 6px; padding: 7px 10px; }
  .player-name-setting { margin-bottom: 5px; }
  .recipes { margin: 7px 0; }
  .recipes span, .controls div { padding: 6px 8px; }
  .buttons { margin-top: 8px; }
}

@media (max-width: 680px) {
  h1 { display: none; }
  .topbar { justify-content: flex-end; }
  .ranking-shortcut { width: 34px; justify-content: center; padding: 3px; }
  .ranking-shortcut-label { display: none !important; }
  .orders { grid-template-columns: 58px minmax(0, 1fr); }
  .how-to-guide { height: min(22vh, 170px); }
  .recipes { grid-template-columns: 1fr; }
  .recipes span:nth-child(n+3) { display: none; }
}

@media (max-width: 420px) {
  .stats div { min-width: 49px; padding: 4px; }
  .stats { gap: 3px; }
  .ranking-dialog { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); }
  #ranking-dialog-body { max-height: calc(100dvh - 79px); padding-inline: 12px; }
}
