:root {
  --chassis: #eaeaea;
  --chassis-border: #d1d1d1;
  --panel: #f5f5f5;
  --screen: #0f0f0f;
  --screen-deep: #050505;
  --ui-dark: #111111;
  --ui-muted: #7f7f7f;
  --accent: #f05a28;
  --accent-strong: #e03c31;
  --line: rgba(0, 0, 0, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-device: 0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
  --shadow-inset: inset 0 4px 12px rgba(0, 0, 0, 0.6);
  --text: #101010;
  --playfield-height: clamp(480px, 60vh, 620px);
  --console-max-width: 1040px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 8px;
  font-family: 'Noto Sans', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: #f2f2f2;
  background-image: radial-gradient(#d4d4d4 1px, transparent 1px);
  background-size: 24px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.console {
  width: 100%;
  max-width: var(--console-max-width);
  height: auto;
  max-height: calc(100vh - 12px);
  background: var(--chassis);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 24px;
  box-shadow: var(--shadow-device);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.console__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--chassis-border);
  background: var(--chassis);
  z-index: 2;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__mark {
  width: 18px;
  height: 18px;
  background: var(--accent-strong);
  border-radius: 999px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5);
}

.brand__text {
  display: flex;
  flex-direction: column;
  font-family: 'Space Grotesk', 'Noto Sans', sans-serif;
  letter-spacing: 0.04em;
}

.brand__title {
  font-weight: 700;
  text-transform: uppercase;
}

.brand__subtitle {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--ui-muted);
  letter-spacing: 0.28em;
}

.header__status {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ui-muted);
  font-size: 12px;
  letter-spacing: 0.06em;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #e0e0e0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.pill__dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.pill__text {
  font-size: 10px;
  font-weight: 700;
  color: var(--ui-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.console__body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) 300px;
  gap: 12px;
  padding: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0.4));
  align-items: start;
}

.display {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

.display__frame {
  position: relative;
  width: min(100%, calc(var(--playfield-height) * 0.5));
  height: var(--playfield-height);
  aspect-ratio: 10 / 20;
  max-width: 100%;
  background: var(--screen);
  border-radius: 14px;
  border: 4px solid var(--screen-deep);
  box-shadow: var(--shadow-inset), 0 10px 30px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

#game-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 10px;
  background: var(--screen);
}

.display__glare {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 55%);
  pointer-events: none;
}

.warning {
  position: absolute;
  left: 14px;
  bottom: 12px;
  padding: 10px 12px;
  background: rgba(240, 90, 40, 0.9);
  color: #fff;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3);
  display: none;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 6px 2px 6px 4px;
  max-height: var(--playfield-height);
}

.module {
  background: var(--panel);
  border: 1px solid var(--chassis-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  padding: 14px 14px 12px;
}

.module__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ui-muted);
  margin-bottom: 10px;
  font-weight: 700;
}

.preview-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.preview-card {
  background: #ffffff;
  border: 1px solid var(--chassis-border);
  border-radius: var(--radius-md);
  padding: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.preview-card__label {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ui-muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.preview-card__screen {
  background: var(--screen);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: var(--shadow-inset);
  padding: 6px;
}

.preview-card__screen canvas {
  width: 100%;
  height: auto;
  display: block;
  background: transparent;
}

.metrics {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.metric {
  background: #ffffff;
  border: 1px solid var(--chassis-border);
  border-radius: var(--radius-md);
  padding: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.metric--primary {
  padding: 12px;
}

.metric__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ui-muted);
  margin-bottom: 6px;
}

.metric__value {
  font-family: 'Space Grotesk', 'Noto Sans', sans-serif;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ui-dark);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.meter {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meter__label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ui-muted);
}

.meter__track {
  position: relative;
  width: 100%;
  height: 12px;
  background: #e6e6e6;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.03);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
}

.meter__track span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #ff8b57);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04);
  transition: width 120ms ease;
}

.meter:last-of-type .meter__track span {
  background: linear-gradient(90deg, var(--accent-strong), #ff7b6d);
}

.story-log {
  min-height: 140px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  background: var(--screen);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: var(--shadow-inset);
  color: #e9e9e9;
  font-size: 13px;
}

.story-log .entry {
  margin-bottom: 10px;
  color: #d1d1d1;
  letter-spacing: 0.01em;
}

.story-log .entry strong {
  color: #ffffff;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.module--controls .controls-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-list li {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ui-dark);
  letter-spacing: 0.02em;
}

.console__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--chassis-border);
  background: var(--chassis);
  font-size: 11px;
  color: var(--ui-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-line__dot {
  width: 8px;
  height: 8px;
  background: #19c25d;
  border-radius: 999px;
  box-shadow: 0 0 0 2px rgba(25, 194, 93, 0.2);
}

.status-line__text {
  font-weight: 700;
}

.status-line__serial {
  letter-spacing: 0.2em;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 10;
  padding: 18px;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.overlay .panel {
  background: var(--panel);
  border: 1px solid var(--chassis-border);
  border-radius: 18px;
  padding: 24px;
  width: min(540px, 92vw);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  text-align: center;
}

.overlay .panel.small {
  width: min(420px, 88vw);
}

.serve-warning {
  background: #fff7f3;
  color: #c2410c;
  border: 1px solid #f3d3c0;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 12px;
}

.panel__badge {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--chassis-border);
  color: var(--ui-muted);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.overlay h1,
.overlay h2 {
  margin: 4px 0 8px;
  font-family: 'Space Grotesk', 'Noto Sans', sans-serif;
  letter-spacing: 0.04em;
}

.overlay p {
  color: var(--ui-muted);
  margin: 0 0 12px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 12px;
}

.menu-buttons button {
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 12px;
  border: 1px solid var(--chassis-border);
  background: linear-gradient(180deg, #fafafa, #f0f0f0);
  color: var(--ui-dark);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: transform 120ms ease, box-shadow 120ms ease, border 120ms ease;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.menu-buttons button:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.12);
}

.settings {
  display: flex;
  justify-content: center;
  gap: 16px;
  color: var(--ui-muted);
  font-size: 13px;
  letter-spacing: 0.02em;
}

.dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 20px;
  pointer-events: none;
  z-index: 9;
}

.dialog .bubble {
  max-width: 520px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--chassis-border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transform: translateY(20px);
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
}

.dialog.show {
  pointer-events: auto;
}

.dialog.show .bubble {
  opacity: 1;
  transform: translateY(0);
}

#dialog-text {
  color: var(--ui-dark);
  margin-bottom: 10px;
}

#dialog-close {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--chassis-border);
  background: #ffffff;
  color: var(--ui-dark);
  cursor: pointer;
  font-weight: 600;
}

.tiny-warning {
  position: fixed;
  bottom: 14px;
  right: 14px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  z-index: 8;
}

.tiny-warning.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.9); opacity: 0.7; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 1100px) {
  .console {
    height: auto;
  }
  .console__body {
    grid-template-columns: 1fr;
    height: auto;
  }
  .side-panel {
    padding-right: 4px;
  }
}

@media (max-width: 1280px) {
  .console__body {
    grid-template-columns: minmax(0, 1fr) 280px;
    padding: 10px;
  }
  .console__header {
    padding: 14px 16px;
  }
  .console {
    max-width: 1024px;
  }
}

@media (max-width: 1050px) {
  .console__body {
    grid-template-columns: 1fr;
    max-height: none;
  }
  .display {
    order: -1;
  }
  .side-panel {
    max-height: none;
  }
}

@media (max-height: 820px) {
  :root {
    --playfield-height: clamp(440px, 58vh, 560px);
  }
  .console {
    height: auto;
  }
  .side-panel {
    max-height: var(--playfield-height);
  }
}

@media (max-width: 780px) {
  body {
    padding: 10px;
  }
  .console__header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .console__body {
    padding: 12px;
  }
  .display__frame {
    max-height: unset;
  }
}
