:root {
  color-scheme: light;
  --worktop: #dce5e9;
  --worktop-line: #b7c5cc;
  --surface: #f5f7f8;
  --surface-muted: #e6ecef;
  --ink: #171d21;
  --ink-soft: #53616a;
  --machine: #171d21;
  --machine-raised: #252d33;
  --machine-line: #47525a;
  --green: #16885b;
  --red: #c9443e;
  --yellow: #d5a91f;
  --blue: #326db5;
  --focus: #ffd15a;
  --error: #b73434;
  --success: #13764f;
  --z-dropdown: 20;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

html {
  min-width: 320px;
  background: var(--worktop);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  background: var(--worktop);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
}

button,
select {
  color: inherit;
  font: inherit;
}

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

button,
summary,
a,
select {
  outline: none;
}

button:focus-visible,
summary:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 50%;
  z-index: calc(var(--z-dropdown) + 1);
  min-height: 44px;
  padding: 11px 18px;
  transform: translate(-50%, -180%);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.skip-link:focus {
  transform: translate(-50%, 0);
}

.app-shell {
  position: relative;
  display: flex;
  min-height: 100vh;
  min-height: 100svh;
  flex-direction: column;
  padding: 0 24px 24px;
}

.topbar {
  position: relative;
  display: grid;
  width: min(100%, 1120px);
  min-height: 72px;
  margin: 0 auto;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.back-link {
  display: inline-flex;
  width: max-content;
  min-height: 44px;
  align-items: center;
  padding: 9px 14px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
  transition:
    background-color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.back-link::before {
  content: "←";
  margin-right: 8px;
  font-size: 1.15em;
}

.back-link:hover {
  background: var(--ink);
  color: #fff;
  transform: translateY(-1px);
}

.mini-signal {
  display: grid;
  width: 54px;
  height: 54px;
  padding: 8px;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  border-radius: 50%;
  background: var(--machine);
  box-shadow: 0 4px 0 #0c1114;
}

.mini-signal span {
  display: block;
  border-radius: 50%;
}

.mini-green {
  background: var(--green);
}

.mini-red {
  background: var(--red);
}

.mini-yellow {
  background: var(--yellow);
}

.mini-blue {
  background: var(--blue);
}

.settings {
  position: relative;
  justify-self: end;
}

.settings > summary {
  display: inline-flex;
  min-width: 92px;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: transparent;
  font-weight: 750;
  user-select: none;
}

.settings > summary::-webkit-details-marker {
  display: none;
}

.settings[open] > summary {
  background: var(--ink);
  color: #fff;
}

.settings-panel {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + 10px);
  right: 0;
  width: min(260px, calc(100vw - 28px));
  padding: 16px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 6px 0 var(--ink);
}

.settings-panel label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 750;
}

.settings-panel select {
  width: 100%;
  min-height: 44px;
  padding: 8px 36px 8px 10px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: #fff;
  font-size: 16px;
}

.settings-panel p {
  display: flex;
  margin-top: 14px;
  justify-content: space-between;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.settings-panel strong {
  color: var(--ink);
}

.instrument {
  position: relative;
  display: grid;
  width: min(100%, 1080px);
  height: min(620px, calc(100svh - 116px));
  min-height: 404px;
  margin: 6px auto 10px;
  overflow: hidden;
  flex: 1;
  grid-template-columns: minmax(310px, 0.88fr) minmax(420px, 1.12fr);
  border-radius: 16px;
  background: var(--machine);
  box-shadow: 0 8px 0 #0c1114;
}

.control-deck {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: clamp(24px, 4vh, 42px);
  border-radius: 12px 0 0 12px;
  background: var(--surface);
}

.control-deck::after {
  position: absolute;
  top: 18px;
  right: 0;
  bottom: 18px;
  width: 2px;
  background: var(--machine-line);
  content: "";
}

.console-label {
  width: max-content;
  max-width: 100%;
  margin-bottom: 8px;
  padding: 5px 9px;
  border-radius: 5px;
  background: var(--machine);
  color: #fff;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

h1 {
  max-width: 14ch;
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  font-size: clamp(2rem, 4vw, 3.55rem);
  line-height: 0.98;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.app-subtitle {
  max-width: 34ch;
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  text-wrap: pretty;
}

.readouts {
  display: grid;
  margin-top: clamp(18px, 3vh, 28px);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.readout {
  display: flex;
  min-height: 68px;
  padding: 10px 14px;
  align-items: center;
  justify-content: space-between;
  border-radius: 8px;
  background: var(--machine);
  color: #fff;
}

.readout span {
  color: #c5d0d6;
  font-size: 0.78rem;
  font-weight: 750;
}

.readout strong {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 1.8rem;
  line-height: 1;
}

.readout-value {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.readout-value small {
  color: #c5d0d6;
  font-size: 0.64rem;
  font-weight: 800;
}

.status-deck {
  margin-top: clamp(16px, 3vh, 24px);
  padding: 12px 0 13px;
  border-top: 2px solid var(--worktop-line);
  border-bottom: 2px solid var(--worktop-line);
}

.status-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 0.73rem;
  font-weight: 800;
}

.status-lamp {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #77838b;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}

.status-deck[data-phase="listen"] .status-lamp {
  background: var(--yellow);
}

.status-deck[data-phase="input"] .status-lamp,
.status-deck[data-phase="correct"] .status-lamp {
  background: var(--green);
}

.status-deck[data-phase="gameover"] .status-lamp {
  background: var(--red);
}

#message {
  min-height: 1.55em;
  margin-top: 5px;
  font-size: clamp(1rem, 2vw, 1.22rem);
  font-weight: 850;
  text-wrap: balance;
}

.status-deck[data-phase="gameover"] #message {
  color: var(--error);
}

.status-deck[data-phase="correct"] #message {
  color: var(--success);
}

.progress-panel {
  margin-top: 14px;
}

.progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-soft);
  font-size: 0.76rem;
  font-weight: 750;
}

.progress-heading strong {
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.progress-track {
  display: flex;
  min-height: 14px;
  margin-top: 8px;
  align-items: stretch;
  gap: 4px;
}

.progress-tick {
  min-width: 5px;
  height: 12px;
  flex: 1 1 12px;
  border-radius: 2px;
  background: #c3cdd2;
  transition:
    background-color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.progress-tick.is-complete {
  background: var(--green);
  transform: translateY(-2px);
}

.progress-overflow {
  display: inline-flex;
  min-width: 30px;
  height: 18px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--ink-soft);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 800;
}

.start-button {
  display: inline-flex;
  width: 100%;
  min-height: 54px;
  margin-top: auto;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 9px;
  background: var(--focus);
  box-shadow: 0 5px 0 #b98e18;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 900;
  transition:
    transform 160ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 160ms cubic-bezier(0.16, 1, 0.3, 1),
    background-color 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.start-button:hover:not(:disabled) {
  background: #ffdb78;
  transform: translateY(-1px);
}

.start-button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #b98e18;
}

.start-button:disabled {
  cursor: not-allowed;
  box-shadow: 0 3px 0 #707a80;
  background: #c4cdd1;
  color: #505a60;
}

.start-icon {
  font-size: 0.82rem;
}

.keyboard-hint {
  margin-top: 12px;
  color: var(--ink-soft);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  text-align: center;
}

.board-bay {
  display: flex;
  min-width: 0;
  min-height: 0;
  padding: clamp(18px, 3vh, 30px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.board-heading {
  width: min(100%, 500px);
  margin-bottom: 14px;
  text-align: center;
}

.board-heading h2 {
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.board-heading p {
  margin-top: 3px;
  color: #aebbc2;
  font-size: 0.76rem;
}

.simon-console {
  position: relative;
  width: min(100%, 450px);
  aspect-ratio: 1;
  padding: 18px;
  border-radius: 50%;
  background: #0c1014;
  box-shadow: 0 8px 0 #080b0d;
}

.console-rim {
  position: absolute;
  inset: 8px;
  pointer-events: none;
  border: 2px solid var(--machine-line);
  border-radius: 50%;
  transition: border-color 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.console-rim::before {
  position: absolute;
  inset: 9px;
  border: 1px solid #2c3439;
  border-radius: inherit;
  content: "";
}

.simon-console[data-phase="correct"] .console-rim {
  border-color: #45bb84;
}

.simon-console[data-phase="gameover"] .console-rim {
  border-color: #e06a65;
}

.simon-board {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  padding: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.signal-pad {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  border: 0;
  color: #fff;
  box-shadow:
    inset 0 -7px 0 rgba(0, 0, 0, 0.24),
    inset 0 3px 0 rgba(255, 255, 255, 0.2);
  isolation: isolate;
  transition:
    filter 160ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 160ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.signal-pad:disabled {
  cursor: default;
}

.signal-pad:not(:disabled):hover {
  filter: brightness(1.08);
}

.signal-pad:not(:disabled):active,
.signal-pad.is-active {
  z-index: 1;
  filter: brightness(1.32) saturate(1.08);
  transform: translateY(4px) scale(0.985);
  box-shadow:
    inset 0 -2px 0 rgba(0, 0, 0, 0.2),
    inset 0 3px 0 rgba(255, 255, 255, 0.35);
}

.signal-pad.is-active {
  outline: 4px solid #fff;
  outline-offset: -7px;
}

.signal-green {
  border-radius: 100% 15px 15px;
  background: var(--green);
}

.signal-red {
  border-radius: 15px 100% 15px 15px;
  background: var(--red);
}

.signal-yellow {
  border-radius: 15px 15px 15px 100%;
  background: var(--yellow);
  color: #191b14;
}

.signal-blue {
  border-radius: 15px 15px 100%;
  background: var(--blue);
}

.pad-lens {
  position: absolute;
  z-index: -1;
  width: 54%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  transition:
    transform 160ms cubic-bezier(0.16, 1, 0.3, 1),
    background-color 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.signal-pad.is-active .pad-lens,
.signal-pad:active .pad-lens {
  transform: scale(0.78);
  background: rgba(255, 255, 255, 0.24);
}

.pad-index {
  position: absolute;
  top: 15%;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.62rem, 1.4vw, 0.78rem);
  font-weight: 900;
}

.pad-name {
  margin-top: 10%;
  font-size: clamp(0.78rem, 1.8vw, 1rem);
  font-weight: 850;
}

.echo-dial {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  display: flex;
  width: 35%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border: 8px solid var(--machine-raised);
  border-radius: 50%;
  background: #080b0e;
  color: #fff;
  box-shadow: 0 3px 0 #000;
  text-align: center;
  transition:
    border-color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.dial-caption {
  color: #87969e;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.48rem, 1vw, 0.64rem);
  font-weight: 800;
  letter-spacing: 0.12em;
}

#dial-level {
  margin: 1px 0;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: clamp(1.35rem, 4vw, 2.6rem);
  line-height: 1;
}

#dial-phase {
  max-width: 80%;
  color: #c9d3d8;
  font-size: clamp(0.52rem, 1.2vw, 0.72rem);
  font-weight: 800;
  line-height: 1.1;
}

.simon-console[data-phase="listen"] .echo-dial {
  border-color: var(--yellow);
}

.simon-console[data-phase="input"] .echo-dial,
.simon-console[data-phase="correct"] .echo-dial {
  border-color: var(--green);
}

.simon-console[data-phase="gameover"] .echo-dial {
  border-color: var(--red);
}

.simon-console.is-mistake {
  animation: mistakeShake 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.simon-console.is-success .echo-dial {
  animation: successPress 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

.version-stamp {
  width: min(100%, 1080px);
  margin: 4px auto 0;
  color: #53616a;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.66rem;
  text-align: right;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes mistakeShake {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-7px);
  }
  65% {
    transform: translateX(7px);
  }
}

@keyframes successPress {
  0%,
  100% {
    transform: translate(-50%, -50%);
  }
  50% {
    transform: translate(-50%, -50%) scale(0.94);
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 0 14px 22px;
  }

  .instrument {
    height: auto;
    min-height: 0;
    flex: 0 0 auto;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .control-deck {
    padding: 24px;
    border-radius: 12px 12px 0 0;
  }

  .control-deck::after {
    top: auto;
    right: 18px;
    bottom: 0;
    left: 18px;
    width: auto;
    height: 2px;
  }

  h1 {
    max-width: none;
    font-size: 2.35rem;
  }

  .start-button {
    margin-top: 22px;
  }

  .board-bay {
    padding: 22px;
  }

  .simon-console {
    width: min(100%, 390px);
  }
}

@media (max-width: 500px) {
  .app-shell {
    padding-inline: 10px;
  }

  .topbar {
    min-height: 62px;
    gap: 8px;
  }

  .mini-signal {
    width: 46px;
    height: 46px;
    padding: 7px;
  }

  .back-link {
    min-width: 44px;
    padding-inline: 10px;
    font-size: 0;
  }

  .back-link::before {
    margin: 0;
    font-size: 1.15rem;
  }

  .settings > summary {
    min-width: 44px;
    padding-inline: 10px;
  }

  .settings > summary span:last-child {
    display: none;
  }

  .control-deck {
    padding: 20px;
  }

  h1 {
    font-size: 2rem;
  }

  .app-subtitle {
    font-size: 0.88rem;
  }

  .readout {
    min-height: 60px;
    padding-inline: 12px;
  }

  .readout strong {
    font-size: 1.55rem;
  }

  .board-bay {
    padding: 18px 12px 22px;
  }

  .board-heading {
    margin-bottom: 10px;
  }

  .simon-console {
    padding: 12px;
  }

  .simon-board {
    padding: 11px;
    gap: 9px;
  }

  .echo-dial {
    border-width: 6px;
  }

  .keyboard-hint {
    font-size: 0.66rem;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .app-shell {
    min-height: 100svh;
    padding: 0 10px 10px;
  }

  .topbar {
    min-height: 50px;
  }

  .mini-signal {
    width: 42px;
    height: 42px;
    padding: 7px;
  }

  .back-link,
  .settings > summary {
    min-height: 44px;
  }

  .back-link {
    padding: 7px 10px;
    font-size: 0.78rem;
  }

  .settings > summary {
    min-width: 44px;
    padding-inline: 10px;
  }

  .settings > summary span:last-child {
    display: none;
  }

  .instrument {
    width: min(100%, 920px);
    height: calc(100svh - 60px);
    min-height: 0;
    margin: 0 auto;
    grid-template-columns: minmax(238px, 0.94fr) minmax(280px, 1.06fr);
    border-radius: 12px;
  }

  .control-deck {
    padding: 12px 16px 14px;
    border-radius: 9px 0 0 9px;
  }

  .console-label {
    margin-bottom: 4px;
    padding: 3px 7px;
    font-size: 0.58rem;
  }

  h1 {
    max-width: none;
    font-size: 1.42rem;
    line-height: 1;
  }

  .app-subtitle,
  .keyboard-hint {
    display: none;
  }

  .readouts {
    margin-top: 9px;
    gap: 7px;
  }

  .readout {
    min-height: 44px;
    padding: 5px 9px;
  }

  .readout span {
    font-size: 0.64rem;
  }

  .readout strong {
    font-size: 1.25rem;
  }

  .status-deck {
    margin-top: 8px;
    padding: 5px 0 6px;
  }

  .status-heading {
    display: none;
  }

  #message {
    margin: 0;
    font-size: 0.9rem;
  }

  .progress-panel {
    margin-top: 7px;
  }

  .progress-heading {
    font-size: 0.64rem;
  }

  .progress-track {
    min-height: 10px;
    margin-top: 4px;
  }

  .progress-tick {
    height: 9px;
  }

  .start-button {
    min-height: 44px;
    margin-top: auto;
    box-shadow: 0 3px 0 #b98e18;
    font-size: 0.84rem;
  }

  .board-bay {
    padding: 8px 14px 10px;
  }

  .board-heading {
    display: flex;
    width: min(100%, 400px);
    min-height: 28px;
    margin-bottom: 5px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: left;
  }

  .board-heading h2 {
    flex: 0 0 auto;
    font-size: 0.78rem;
  }

  .board-heading p {
    max-width: 34ch;
    margin: 0;
    font-size: 0.6rem;
    text-align: right;
  }

  .simon-console {
    width: min(100%, calc(100svh - 103px));
    padding: 9px;
    box-shadow: 0 5px 0 #080b0d;
  }

  .simon-board {
    padding: 8px;
    gap: 7px;
  }

  .pad-index {
    top: 12%;
    font-size: 0.52rem;
  }

  .pad-name {
    font-size: 0.62rem;
  }

  .echo-dial {
    border-width: 5px;
  }

  .dial-caption {
    display: none;
  }

  #dial-level {
    font-size: clamp(1rem, 4vh, 1.4rem);
  }

  #dial-phase {
    font-size: 0.48rem;
  }

  .version-stamp {
    display: none;
  }
}

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

  .signal-pad.is-active,
  .signal-pad:active {
    transform: none;
  }

  .progress-tick.is-complete {
    transform: none;
  }
}
