:root {
  --bg-top: #030712;
  --bg-bottom: #05030f;
  --panel: #101322;
  --line-cyan: #2cf7ff;
  --line-hot: #ff5d2f;
  --line-gold: #ffd76a;
  --text-main: #f5f6fb;
  --text-sub: #9ea5bf;
  --seg-off: #3b1915;
  --seg-on: #ff5c2f;
  --seg-glow: #ffad44;
  --button-bg: #141b2d;
  --button-border: #355a90;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: 'Trebuchet MS', 'Arial Narrow', sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 20% 10%, rgba(43, 74, 147, 0.28), transparent 35%),
    radial-gradient(circle at 80% 12%, rgba(217, 84, 35, 0.25), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

body {
  display: grid;
  place-items: center;
  padding: 10px;
  height: 100dvh;
  overflow: hidden;
}

#pinballApp {
  width: min(98vw, 1360px);
  height: calc(100dvh - 20px);
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 12px;
  align-items: stretch;
}

#sidePanel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

#tableArea {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#hud {
  background: linear-gradient(180deg, rgba(18, 24, 42, 0.95), rgba(10, 12, 24, 0.95));
  border: 1px solid rgba(83, 114, 188, 0.6);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.display-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.display-row.compact {
  grid-template-columns: 1.25fr 0.8fr 0.8fr;
}

.display-card {
  background: rgba(8, 10, 22, 0.9);
  border: 1px solid rgba(73, 92, 161, 0.7);
  border-radius: 8px;
  padding: 6px 6px 8px;
}

.display-label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--text-sub);
  margin-bottom: 4px;
}

.seg-display {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
  min-height: 40px;
}

.seg-digit {
  width: 18px;
  height: 34px;
  border-radius: 3px;
  position: relative;
  background: rgba(18, 6, 6, 0.75);
  border: 1px solid rgba(88, 24, 17, 0.9);
}

.seg {
  position: absolute;
  background: var(--seg-off);
  opacity: 0.35;
  border-radius: 3px;
  transition: opacity 80ms linear, background-color 80ms linear, box-shadow 80ms linear;
}

.seg.on {
  background: var(--seg-on);
  opacity: 1;
  box-shadow: 0 0 6px var(--seg-on), 0 0 12px var(--seg-glow);
}

.seg-a {
  top: 2px;
  left: 4px;
  width: 10px;
  height: 3px;
}

.seg-b {
  top: 4px;
  right: 2px;
  width: 3px;
  height: 11px;
}

.seg-c {
  bottom: 4px;
  right: 2px;
  width: 3px;
  height: 11px;
}

.seg-d {
  bottom: 2px;
  left: 4px;
  width: 10px;
  height: 3px;
}

.seg-e {
  bottom: 4px;
  left: 2px;
  width: 3px;
  height: 11px;
}

.seg-f {
  top: 4px;
  left: 2px;
  width: 3px;
  height: 11px;
}

.seg-g {
  top: 15px;
  left: 4px;
  width: 10px;
  height: 3px;
}

#hudButtons {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

button,
select,
input[type='range'] {
  font: inherit;
}

button {
  border: 1px solid var(--button-border);
  color: var(--text-main);
  background: linear-gradient(180deg, var(--button-bg), #0f1322);
  border-radius: 7px;
  padding: 7px 6px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

button:active {
  transform: translateY(1px);
}

#statusLine {
  margin-top: 8px;
  min-height: 1.2em;
  color: var(--line-gold);
  letter-spacing: 0.06em;
  font-size: 0.86rem;
}

#nudgeMeter {
  margin-top: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

#nudgeMeterFill {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #22f0e4, #ffa42f);
  transition: width 80ms linear;
}

#nudgeMeterFill.warn {
  background: linear-gradient(90deg, #ff9f44, #ff3b3b);
}

#tableWrap {
  position: relative;
  width: min(100%, calc((100dvh - 20px) * 4 / 7));
  aspect-ratio: 4 / 7;
  border: 1px solid rgba(74, 103, 176, 0.75);
  border-radius: 14px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(76, 120, 204, 0.24), transparent 45%),
    linear-gradient(180deg, #08101f, #070d19 42%, #0c0e1c 100%);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  max-height: 100%;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
}

.center-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--line-gold);
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
  letter-spacing: 0.08em;
  text-shadow: 0 0 8px rgba(255, 178, 79, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms linear;
}

.center-message.show {
  opacity: 1;
}

.center-message.tilt {
  color: #ff3f3f;
  text-shadow: 0 0 10px rgba(255, 63, 63, 0.85);
}

.debug-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.68rem;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid rgba(255, 166, 68, 0.8);
  color: #ffaf43;
  background: rgba(26, 18, 10, 0.8);
  opacity: 0;
  transition: opacity 120ms linear;
}

.debug-badge.show {
  opacity: 1;
}

.panel {
  background: rgba(12, 15, 29, 0.97);
  border: 1px solid rgba(88, 114, 190, 0.74);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel.hidden {
  display: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 0.86rem;
}

.help-grid p {
  margin: 0;
  line-height: 1.35;
}

.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms linear;
}

.touch-controls.show {
  opacity: 1;
}

.touch-controls button,
.touch-controls input {
  pointer-events: auto;
}

.touch-flippers {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 14px;
  display: flex;
  justify-content: space-between;
}

.touch-flippers button {
  width: 31%;
  height: 68px;
  font-size: 1.15rem;
  border-radius: 14px;
  background: rgba(15, 22, 42, 0.66);
  border: 1px solid rgba(122, 166, 255, 0.7);
}

.touch-plunger {
  position: absolute;
  right: 8px;
  top: 34%;
  width: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  font-size: 0.65rem;
}

.touch-plunger input[type='range'] {
  writing-mode: bt-lr;
  -webkit-appearance: slider-vertical;
  width: 24px;
  height: 170px;
}

.touch-nudges {
  position: absolute;
  left: 8px;
  top: 42%;
  display: grid;
  gap: 6px;
}

.touch-nudges button {
  width: 62px;
  padding: 7px 6px;
  font-size: 0.72rem;
  background: rgba(18, 20, 34, 0.75);
}

@media (pointer: coarse) {
  #pinballApp {
    width: min(99vw, 980px);
  }

  #hudButtons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  body {
    padding: 8px;
    overflow: auto;
  }

  #pinballApp {
    width: min(100%, 760px);
    height: auto;
    min-height: calc(100dvh - 16px);
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #sidePanel {
    overflow: visible;
    padding-right: 0;
  }

  #tableArea {
    justify-content: flex-start;
  }

  #tableWrap {
    width: 100%;
  }
}

@media (max-width: 560px) {
  #pinballApp {
    width: 100%;
  }

  #hud {
    padding: 8px;
  }

  .seg-digit {
    width: 16px;
    height: 30px;
  }

  .help-grid {
    grid-template-columns: 1fr;
  }
}
