:root {
  color-scheme: dark;
  --bg: #0a0d13;
  --panel: rgba(16, 20, 29, 0.76);
  --panel-strong: rgba(22, 27, 37, 0.94);
  --line: rgba(181, 196, 211, 0.18);
  --text: #f4f7fb;
  --muted: #aeb7c4;
  --accent: #c0c030;
  --accent-strong: #f0d45a;
  --danger: #ff5d51;
  --good: #7ee26f;
  --blue: #32a8ff;
  --metal: #69717c;
  --metal-bright: #c8ced3;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
}

button {
  font: inherit;
}

.game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 74% 24%, rgba(41, 102, 159, 0.22), transparent 33%),
    radial-gradient(circle at 16% 82%, rgba(192, 192, 48, 0.13), transparent 30%),
    #080b11;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.topbar {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(132px, 188px) minmax(260px, 520px) auto;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.brand,
.readouts,
.top-actions,
.order-panel,
.toolbelt,
.state-panel {
  pointer-events: auto;
}

.brand,
.readouts,
.top-actions,
.order-panel,
.toolbelt {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(37, 43, 55, 0.72), rgba(9, 12, 18, 0.68)),
    rgba(9, 12, 18, 0.72);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(5px);
}

.brand {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background:
    linear-gradient(90deg, transparent 0 38%, #18222f 38% 62%, transparent 62%),
    linear-gradient(0deg, transparent 0 38%, #18222f 38% 62%, transparent 62%),
    linear-gradient(135deg, var(--accent), #32a8ff);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08), 0 0 24px rgba(192, 192, 48, 0.25);
}

.readouts {
  display: grid;
  grid-template-columns: repeat(4, minmax(78px, 1fr));
  gap: 1px;
  min-height: 46px;
  margin: 0;
  padding: 3px;
  border-radius: 8px;
}

.readouts div {
  display: grid;
  align-content: center;
  min-width: 0;
  padding: 6px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
}

.readouts dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.readouts dd {
  margin: 1px 0 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 950;
  line-height: 1;
}

.top-actions {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 6px;
  padding: 5px;
  border-radius: 8px;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible,
.tool-button:hover,
.tool-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: rgba(255, 255, 255, 0.42);
  outline: none;
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mute-slash {
  opacity: 0;
}

.is-muted .sound-wave {
  opacity: 0;
}

.is-muted .mute-slash {
  opacity: 1;
}

.order-panel {
  position: absolute;
  top: 66px;
  right: 12px;
  z-index: 4;
  display: grid;
  width: min(188px, calc(100vw - 24px));
  gap: 8px;
  padding: 9px;
  border-radius: 8px;
}

.order-panel .panel-section:first-child,
.order-panel .panel-metrics {
  display: none;
}

.panel-section {
  display: grid;
  gap: 5px;
}

.panel-kicker,
.panel-section span,
.order-card small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-section strong {
  font-size: 15px;
  line-height: 1.15;
}

.order-list {
  display: grid;
  gap: 5px;
  min-height: 58px;
  max-height: 188px;
  overflow: hidden;
}

.order-card {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 7px;
  align-items: center;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.order-dot {
  width: 16px;
  height: 16px;
  border-radius: 6px;
  box-shadow: 0 0 18px currentColor;
}

.order-card strong {
  display: block;
  font-size: 12px;
}

.order-card small {
  display: none;
}

.order-timer {
  position: relative;
  height: 4px;
  margin-top: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.order-timer span {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--order-time, 100%);
  background: currentColor;
}

.empty-orders {
  display: grid;
  min-height: 54px;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.panel-metrics {
  grid-template-columns: 1fr 1fr;
}

.panel-metrics div {
  padding: 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.panel-metrics strong {
  display: block;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

.toolbelt {
  position: absolute;
  left: 50%;
  bottom: 10px;
  z-index: 5;
  display: flex;
  max-width: calc(100% - 28px);
  gap: 7px;
  padding: 7px;
  overflow-x: auto;
  border-radius: 8px;
  transform: translateX(-50%);
  scrollbar-width: none;
}

.toolbelt::-webkit-scrollbar {
  display: none;
}

.tool-button {
  position: relative;
  display: grid;
  width: 52px;
  height: 52px;
  min-width: 52px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  cursor: pointer;
}

.tool-button span {
  font-size: 15px;
  font-weight: 950;
  line-height: 1;
}

.tool-button small {
  position: absolute;
  right: 5px;
  bottom: 4px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
}

.tool-button.is-active {
  border-color: rgba(240, 212, 90, 0.75);
  background: linear-gradient(180deg, rgba(192, 192, 48, 0.25), rgba(255, 255, 255, 0.065));
  color: #fff8c5;
}

.danger-tool.is-active {
  border-color: rgba(255, 93, 81, 0.75);
  background: linear-gradient(180deg, rgba(255, 93, 81, 0.28), rgba(255, 255, 255, 0.06));
}

.state-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center start;
  padding: 22px clamp(18px, 5vw, 58px);
  background:
    linear-gradient(90deg, rgba(5, 7, 11, 0.86), rgba(5, 7, 11, 0.55) 36%, rgba(5, 7, 11, 0.08) 72%, transparent),
    rgba(5, 7, 11, 0.16);
  backdrop-filter: none;
  pointer-events: auto;
}

.state-overlay[hidden] {
  display: none;
}

.state-panel {
  width: min(420px, 94vw);
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(32, 38, 50, 0.94), rgba(11, 15, 23, 0.93)),
    var(--panel-strong);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.56), inset 0 1px 0 rgba(255,255,255,0.08);
}

.state-kicker {
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.state-panel h1 {
  margin: 8px 0 10px;
  font-size: 42px;
  line-height: 0.95;
  letter-spacing: 0;
}

.state-panel p {
  max-width: 52ch;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.state-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0 18px;
}

.state-stats div {
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.state-stats span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.state-stats strong {
  display: block;
  margin-top: 3px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.state-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, #f0d45a, #c0c030);
  color: #11140b;
}

.secondary-button {
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.level-select {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 18px;
}

.level-select.is-open {
  display: grid;
}

.level-choice {
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.level-choice[disabled] {
  cursor: not-allowed;
  opacity: 0.45;
}

.level-choice strong,
.level-choice span {
  display: block;
}

.level-choice span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .brand {
    display: none;
  }

  .readouts {
    grid-column: 1;
  }

  .order-panel {
    width: 188px;
  }
}

@media (max-width: 720px) {
  .topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .readouts {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 52px;
  }

  .readouts div {
    padding: 7px 6px;
  }

  .readouts dt {
    font-size: 8px;
  }

  .readouts dd {
    font-size: 15px;
  }

  .top-actions {
    position: fixed;
    right: 8px;
    bottom: 86px;
    min-height: 0;
    padding: 6px;
    flex-direction: column;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .order-panel {
    display: none;
  }

  .toolbelt {
    left: 8px;
    right: 8px;
    bottom: 8px;
    transform: none;
    max-width: none;
  }

  .tool-button {
    width: 51px;
    height: 51px;
    min-width: 51px;
  }

  .state-stats {
    grid-template-columns: 1fr;
  }

  .state-overlay {
    place-items: center;
    background: rgba(5, 7, 11, 0.72);
  }

  .state-panel h1 {
    font-size: 34px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
