:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111318;
  color: #f4f7fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  height: 100vh;
  background:
    radial-gradient(circle at 40% 0%, rgba(52, 113, 97, 0.18), transparent 34%),
    linear-gradient(135deg, #101318 0%, #181b20 54%, #0d1315 100%);
}

.viewport {
  position: relative;
  min-width: 0;
}

#scene {
  display: block;
  width: 100%;
  height: 100vh;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#scene:active {
  cursor: grabbing;
}

.hud {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 20px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  pointer-events: none;
}

.hud > div {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: rgba(12, 16, 18, 0.72);
  padding: 12px 14px;
  backdrop-filter: blur(10px);
}

.label {
  display: block;
  color: #91a3a8;
  font-size: 11px;
  line-height: 1.3;
}

.hud strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
  line-height: 1.1;
}

.control-panel {
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 17, 22, 0.92);
  padding: 20px 18px;
  overflow: auto;
}

header p {
  margin: 0 0 6px;
  color: #62c8b6;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 20px;
  font-size: 22px;
  line-height: 1.18;
  font-weight: 760;
}

.score-card {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 18px;
  padding: 12px;
  border: 1px solid rgba(98, 200, 182, 0.34);
  border-radius: 6px;
  background: rgba(98, 200, 182, 0.1);
}

.score-card span {
  color: #91a3a8;
  font-size: 12px;
}

.score-card strong {
  overflow: hidden;
  color: #62c8b6;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  display: grid;
  grid-template-columns: max-content minmax(118px, 1fr) max-content;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}

.field label {
  color: #dfe7e8;
  font-size: 14px;
  font-weight: 650;
}

.field output {
  color: #9bb0b5;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  justify-self: end;
  min-width: 48px;
  text-align: right;
  white-space: nowrap;
}

.field input {
  width: 100%;
  height: 20px;
  accent-color: #62c8b6;
}

.rule-field {
  margin: 8px 0 12px;
}

.hidden {
  display: none;
}

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

.commands {
  grid-template-columns: repeat(3, 1fr);
}

.select-field {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin: 16px 0 8px;
  color: #dfe7e8;
  font-size: 14px;
  font-weight: 650;
}

.select-field select {
  min-width: 0;
  height: 34px;
  padding: 0 34px 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, #9bb0b5 50%) right 15px center / 7px 7px no-repeat,
    linear-gradient(135deg, #9bb0b5 50%, transparent 50%) right 10px center / 7px 7px no-repeat,
    #20252a;
  color: #f4f7fb;
  cursor: pointer;
}

.select-field select:focus-visible {
  outline: 2px solid rgba(98, 200, 182, 0.72);
  outline-offset: 2px;
}

.mode-hint {
  min-height: 34px;
  margin: 0 0 8px;
  color: #91a3a8;
  font-size: 12px;
  line-height: 1.45;
}

.state-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin: 0 0 12px;
  color: #b5c3c7;
  font-size: 12px;
  line-height: 1.2;
}

.state-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.state-legend i {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.turn-state {
  background: #ff596b;
  box-shadow: 0 0 10px rgba(255, 89, 107, 0.52);
}

.channel-state {
  background: #669fff;
  box-shadow: 0 0 10px rgba(102, 159, 255, 0.52);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 34px;
  margin: 2px 0 14px;
  padding: 0 2px;
  color: #dfe7e8;
  font-size: 14px;
  font-weight: 650;
}

.switch-row input {
  width: 44px;
  height: 24px;
  margin: 0;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: #20252a;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.switch-row input::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  margin: 2px;
  border-radius: 50%;
  background: #9bb0b5;
  transition: transform 160ms ease, background 160ms ease;
}

.switch-row input:checked {
  border-color: #62c8b6;
  background: #1d4d47;
}

.switch-row input:checked::before {
  transform: translateX(20px);
  background: #f4f7fb;
}

button {
  position: relative;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: #20252a;
  color: #f4f7fb;
  cursor: pointer;
}

button:hover {
  background: #2a3036;
}

button.active {
  border-color: #62c8b6;
  background: #1d4d47;
}

.readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 12px;
}

.readout div {
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
}

.readout dt {
  color: #91a3a8;
  font-size: 12px;
  line-height: 1.2;
}

.readout dd {
  margin: 4px 0 0;
  overflow: hidden;
  color: #f4f7fb;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  #scene {
    height: 62vh;
  }

  .control-panel {
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    left: 12px;
    right: 12px;
  }
}
