:root {
  color-scheme: dark;
  --bg: #10110f;
  --panel: #1b1e1a;
  --panel-strong: #242820;
  --ink: #f5f4ec;
  --muted: #aeb5a7;
  --line: #3b4236;
  --acid: #c9ff4a;
  --cyan: #4ad7ff;
  --pink: #ff6fae;
  --gold: #ffd166;
  --bad: #ff7b64;
  --good: #72e38a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: linear-gradient(160deg, #10110f 0%, #171b18 48%, #0e1214 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.game {
  width: min(100%, 430px);
  max-width: 100vw;
  height: 100vh;
  height: 100svh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) clamp(8px, 3.2vw, 14px) max(10px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(96px, 1fr);
  gap: 10px;
  overflow: hidden;
}

.topbar,
.target-panel,
.controls,
.hint-panel,
.history-panel {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(27, 30, 26, 0.94);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  padding: 10px clamp(10px, 3vw, 12px);
}

.topbar > div {
  min-width: 0;
}

.eyebrow,
.label {
  margin: 0;
  color: var(--acid);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  margin-top: 2px;
  font-size: clamp(1.25rem, 7vw, 1.55rem);
  line-height: 1.05;
}

h2 {
  font-size: 1rem;
}

.icon-button,
.stepper,
.test-button,
.reveal-button,
#clearButton {
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  background: var(--panel-strong);
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 900;
}

.target-panel {
  position: relative;
  padding: 12px;
  padding-right: clamp(96px, 30vw, 126px);
}

.target-value {
  margin-top: 4px;
  color: var(--gold);
  font-size: clamp(2.65rem, 17vw, 3.5rem);
  font-weight: 900;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.status {
  min-height: 2.45rem;
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.25;
}

.reveal-button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: clamp(82px, 27vw, 108px);
  min-height: 34px;
  margin: 0;
  background: #151916;
  color: var(--cyan);
  font-size: 0.82rem;
  font-weight: 850;
}

.box-reveal {
  margin: 8px 0 0;
  padding: 8px 10px;
  border: 1px solid rgba(74, 215, 255, 0.38);
  border-radius: 8px;
  background: rgba(74, 215, 255, 0.08);
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.25;
}

.box-reveal[hidden] {
  display: none;
}

.machine {
  width: 100%;
  min-width: 0;
  min-height: 96px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(72px, 23vw, 96px) minmax(0, 1fr);
  align-items: center;
  gap: clamp(6px, 2vw, 8px);
}

.slot {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121410;
  padding: 10px 8px;
  text-align: center;
}

.slot span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.slot strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  font-size: clamp(1.15rem, 6vw, 1.55rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.box {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  height: clamp(74px, 24vw, 88px);
  border: 2px solid #050605;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 42%),
    #030403;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08), 0 12px 24px rgba(0, 0, 0, 0.28);
}

.box-light {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--cyan);
  box-shadow: 0 0 16px var(--cyan);
}

.box-label {
  color: var(--acid);
  font-size: 2.25rem;
  font-weight: 900;
}

.controls {
  padding: 12px;
}

.controls label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.input-row {
  display: grid;
  grid-template-columns: clamp(40px, 13vw, 46px) minmax(0, 1fr) clamp(40px, 13vw, 46px);
  gap: clamp(6px, 2vw, 8px);
}

.stepper {
  min-height: 48px;
  background: var(--panel-strong);
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 900;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #0d0f0c;
  color: var(--ink);
  text-align: center;
  font-size: 1.45rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(74, 215, 255, 0.14);
}

.test-button {
  width: 100%;
  min-height: 46px;
  margin-top: 8px;
  background: var(--acid);
  color: #15170f;
  font-weight: 900;
}

.hint-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: var(--line);
}

.hint-panel > div {
  min-width: 0;
  padding: 10px 8px;
  background: var(--panel);
}

.hint-panel strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.98rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-panel {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

#clearButton {
  min-height: 32px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.history-list {
  min-height: 0;
  margin: 0;
  padding: 6px;
  overflow: auto;
  list-style: none;
}

.history-list:empty::before {
  content: "No experiments yet.";
  display: block;
  padding: 16px 6px;
  color: var(--muted);
  text-align: center;
}

.history-list li {
  display: grid;
  grid-template-columns: clamp(2.35rem, 13vw, 3.2rem) minmax(0, 1fr) minmax(3.8rem, auto);
  align-items: center;
  gap: 8px;
  min-height: 40px;
  margin-bottom: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121410;
}

.history-list .numbers {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-list .distance {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 2.7rem;
  height: 26px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
}

.match {
  border-color: rgba(114, 227, 138, 0.85) !important;
}

.match .badge {
  background: var(--good);
  color: #071008;
}

@media (max-height: 720px) {
  .game {
    grid-template-rows: auto auto auto auto auto minmax(76px, 1fr);
    gap: 7px;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .topbar,
  .target-panel,
  .controls {
    padding: 9px 10px;
  }

  .target-panel {
    padding-right: clamp(90px, 29vw, 114px);
  }

  .topbar {
    min-height: 54px;
  }

  .eyebrow,
  .label {
    font-size: 0.66rem;
  }

  .target-value {
    font-size: 2.55rem;
  }

  .status {
    min-height: 2rem;
    font-size: 0.9rem;
  }

  .reveal-button {
    top: 8px;
    right: 8px;
    width: clamp(78px, 26vw, 100px);
    min-height: 30px;
    font-size: 0.76rem;
  }

  .box-reveal {
    margin-top: 6px;
    padding: 7px 8px;
    font-size: 0.82rem;
  }

  .machine {
    min-height: 82px;
    grid-template-columns: minmax(0, 1fr) clamp(64px, 21vw, 78px) minmax(0, 1fr);
  }

  .box {
    height: 74px;
  }

  .slot {
    padding: 8px 6px;
  }

  .slot strong {
    font-size: 1.3rem;
  }

  .controls label {
    margin-bottom: 6px;
    font-size: 0.86rem;
  }

  .input-row {
    grid-template-columns: clamp(38px, 12vw, 42px) minmax(0, 1fr) clamp(38px, 12vw, 42px);
    gap: 6px;
  }

  .stepper,
  input {
    min-height: 42px;
  }

  .test-button {
    min-height: 42px;
    margin-top: 6px;
  }

  .hint-panel > div {
    padding: 8px 6px;
  }

  .hint-panel strong {
    font-size: 0.86rem;
  }

  .history-head {
    padding: 8px 10px;
  }

  .history-list li {
    min-height: 36px;
    padding: 6px;
    margin-bottom: 5px;
  }
}

@media (max-height: 600px) {
  .game {
    grid-template-rows: auto auto auto auto minmax(70px, 1fr);
  }

  .hint-panel {
    display: none;
  }

  .target-value {
    font-size: 2.2rem;
  }

  .status {
    min-height: 1.15rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .reveal-button {
    width: 76px;
    min-height: 28px;
  }

  .box-reveal {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .machine {
    min-height: 72px;
    grid-template-columns: minmax(0, 1fr) clamp(58px, 19vw, 68px) minmax(0, 1fr);
  }

  .box {
    height: 64px;
  }

  .box-label {
    font-size: 1.8rem;
  }

  .history-list:empty::before {
    padding: 10px 6px;
  }
}

@media (max-width: 360px) {
  .game {
    gap: 7px;
    padding-inline: 7px;
  }

  .topbar,
  .target-panel,
  .controls {
    padding-inline: 9px;
  }

  .target-panel {
    padding-right: 88px;
  }

  .machine {
    grid-template-columns: minmax(0, 1fr) 62px minmax(0, 1fr);
    gap: 5px;
  }

  .slot {
    padding-inline: 5px;
  }

  .slot span {
    font-size: 0.62rem;
  }

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

  .hint-panel > div:first-child {
    grid-column: 1 / -1;
  }

  .history-list li {
    grid-template-columns: 2.35rem minmax(0, 1fr);
  }

  .history-list .distance {
    grid-column: 2;
    text-align: left;
  }
}
