:root {
  --bg: #f4efe5;
  --paper: #fffdf8;
  --ink: #24201d;
  --muted: #6d675e;
  --line: #d8cfc0;
  --board: #ef5b49;
  --board-dark: #b9352c;
  --green: #20c878;
  --green-dark: #107247;
  --yellow: #f3bd2c;
  --shadow: 0 20px 54px rgba(44, 34, 22, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(32, 200, 120, 0.14), transparent 35%),
    linear-gradient(315deg, rgba(243, 189, 44, 0.22), transparent 34%),
    var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  overflow-x: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.is-hidden {
  display: none !important;
}

.start-screen {
  display: grid;
  min-height: calc(100vh - 48px);
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: stretch;
}

.brand-panel,
.record-panel,
.board-card,
.finish-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.brand-panel {
  display: grid;
  align-content: center;
  min-height: 560px;
  padding: clamp(28px, 7vw, 72px);
}

.eyebrow,
h1,
h2,
p {
  margin-top: 0;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--green-dark);
  font-size: 0.86rem;
  font-weight: 900;
}

h1 {
  max-width: 720px;
  margin-bottom: 14px;
  font-size: clamp(3rem, 7vw, 6.4rem);
  line-height: 0.9;
  letter-spacing: 0;
}

.lead {
  max-width: 620px;
  margin-bottom: 30px;
  color: var(--muted);
  font-size: clamp(1.08rem, 2vw, 1.35rem);
  font-weight: 800;
  line-height: 1.45;
}

.start-button {
  width: fit-content;
  min-height: 58px;
  padding: 14px 24px;
  border: 1px solid var(--green-dark);
  border-radius: 8px;
  background: var(--green);
  color: #082c1a;
  font-size: 1.08rem;
  font-weight: 900;
  cursor: pointer;
}

.secondary-button {
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.secondary-button:disabled {
  opacity: 0.42;
  cursor: default;
}

.record-panel {
  align-self: stretch;
  padding: 20px;
}

.record-head,
.game-header,
.score-box,
.lamp,
.button-face {
  display: flex;
  align-items: center;
}

.record-head,
.game-header {
  justify-content: space-between;
  gap: 14px;
}

.record-head {
  margin-bottom: 16px;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.best-record {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 8px;
  background: #e7f7ef;
  color: var(--green-dark);
  font-weight: 900;
}

.best-record span,
.record-empty,
.record-item span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.record-list {
  display: grid;
  gap: 8px;
}

.record-item {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-weight: 900;
}

.game-screen {
  display: grid;
  gap: 16px;
}

.tutorial-screen {
  display: grid;
  gap: 16px;
}

.game-header {
  min-height: 88px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.question-box {
  min-width: 0;
  text-align: center;
}

.question-box h2 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 3vw, 2.6rem);
  line-height: 1.15;
}

.round-text {
  margin-bottom: 6px;
  color: var(--green-dark);
  font-weight: 900;
}

.score-box {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 246px;
}

.score-box span {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-size: 0.9rem;
  font-weight: 900;
}

.board-card {
  position: relative;
  overflow: hidden;
  min-height: 650px;
  padding: 22px;
  border: 4px solid var(--board-dark);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 36%),
    var(--board);
}

.tutorial-card {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 4px solid var(--board-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 36%),
    var(--board);
  box-shadow: var(--shadow);
}

.tutorial-diagram {
  width: min(860px, 100%);
  margin: 0 auto;
}

.tutorial-copy {
  display: grid;
  gap: 8px;
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 16px;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  color: var(--ink);
}

.tutorial-rule,
.tutorial-example {
  margin-bottom: 0;
  font-weight: 900;
  line-height: 1.5;
}

.tutorial-example {
  color: var(--muted);
}

.tutorial-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.lamp {
  justify-content: center;
  gap: 14px;
  min-height: 92px;
  color: white;
  text-align: center;
}

.bulb {
  width: 76px;
  height: 76px;
  border: 8px solid rgba(30, 43, 37, 0.48);
  border-radius: 50%;
  background: #e1e7dc;
  box-shadow:
    inset 0 0 0 5px rgba(255, 255, 255, 0.45),
    0 6px 0 rgba(0, 0, 0, 0.18);
}

.lamp strong {
  min-width: 76px;
  font-size: 1.35rem;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.lamp.is-on .bulb {
  border-color: rgba(2, 86, 51, 0.72);
  background: var(--green);
  box-shadow:
    0 0 0 10px rgba(32, 200, 120, 0.22),
    0 0 44px rgba(32, 200, 120, 0.85),
    inset 0 0 0 5px rgba(255, 255, 255, 0.36);
}

.circuit-board {
  width: min(930px, 100%);
  margin: 26px auto 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}

.circuit-diagram {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 12px 18px rgba(42, 32, 24, 0.16));
}

.diagram-paper {
  fill: rgba(255, 255, 255, 0.93);
  stroke: rgba(41, 33, 27, 0.18);
  stroke-width: 2;
}

.diagram-wire {
  fill: none;
  stroke: #2c241d;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.diagram-wire.is-on {
  stroke: var(--green);
  stroke-width: 6;
  filter: drop-shadow(0 0 8px rgba(32, 200, 120, 0.72));
}

.diagram-joint {
  fill: #2c241d;
}

.diagram-joint.is-on {
  fill: var(--green);
}

.diagram-input text {
  fill: #2c241d;
  font-size: 24px;
  font-weight: 900;
}

.diagram-input .diagram-input-name {
  fill: rgba(44, 36, 29, 0.72);
  font-size: 16px;
}

.diagram-input circle {
  fill: #2c241d;
}

.diagram-input.is-on text {
  fill: var(--green-dark);
}

.diagram-input.is-on circle {
  fill: var(--green);
  filter: drop-shadow(0 0 9px rgba(32, 200, 120, 0.8));
}

.diagram-gate path,
.diagram-gate circle {
  fill: #f4f2ed;
  stroke: #2c241d;
  stroke-linejoin: round;
  stroke-width: 4;
}

.diagram-gate line {
  stroke: #2c241d;
  stroke-linecap: round;
  stroke-width: 5;
}

.diagram-gate text {
  fill: #2c241d;
  font-size: 20px;
  font-weight: 900;
  text-anchor: middle;
}

.diagram-gate.is-on path,
.diagram-gate.is-on circle {
  fill: #e2faed;
  stroke: var(--green-dark);
}

.diagram-gate.is-on line {
  stroke: var(--green);
}

.diagram-gate.is-on text {
  fill: var(--green-dark);
}

.diagram-output line {
  stroke: #2c241d;
  stroke-linecap: round;
  stroke-width: 4;
}

.diagram-output circle {
  fill: #e1e7dc;
  stroke: #2c241d;
  stroke-width: 4;
}

.diagram-output text {
  fill: #2c241d;
  font-size: 26px;
  font-weight: 900;
}

.diagram-output.is-on line {
  stroke: var(--green);
  stroke-width: 6;
}

.diagram-output.is-on circle {
  fill: var(--green);
  stroke: var(--green-dark);
  filter: drop-shadow(0 0 12px rgba(32, 200, 120, 0.85));
}

.button-deck {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  width: min(820px, 100%);
  margin: 22px auto 0;
}

.press-button {
  display: grid;
  gap: 8px;
  min-height: 134px;
  justify-items: center;
  padding: 14px 10px 10px;
  border: 0;
  border-radius: 8px;
  background: rgba(44, 35, 28, 0.24);
  color: white;
  cursor: pointer;
}

.press-button:disabled {
  cursor: default;
}

.button-face {
  justify-content: center;
  width: 88px;
  height: 88px;
  border: 7px solid rgba(48, 36, 26, 0.42);
  border-radius: 50%;
  background: var(--yellow);
  color: #4b3305;
  box-shadow:
    inset 0 -10px 0 rgba(0, 0, 0, 0.18),
    0 8px 0 rgba(0, 0, 0, 0.18);
  font-size: 1.6rem;
  font-weight: 900;
}

.press-button.is-pressed .button-face {
  transform: translateY(8px);
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.2),
    0 1px 0 rgba(0, 0, 0, 0.18);
}

.press-button[data-color="red"] .button-face {
  background: #ff6b64;
  color: #5b1716;
}

.press-button[data-color="blue"] .button-face {
  background: #62a9f1;
  color: #0d3760;
}

.press-button[data-color="green"] .button-face {
  background: #55d887;
  color: #0c4a2b;
}

.press-button[data-color="purple"] .button-face {
  background: #b593ed;
  color: #341c5e;
}

.button-label {
  color: white;
  font-size: 1rem;
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
}

.submit-row {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.submit-button {
  min-height: 56px;
  padding: 14px 24px;
  border: 1px solid var(--green-dark);
  border-radius: 8px;
  background: var(--green);
  color: #082c1a;
  font-size: 1.08rem;
  font-weight: 900;
  cursor: pointer;
}

.submit-button:disabled {
  opacity: 0.58;
  cursor: default;
}

.status-message {
  min-height: 30px;
  margin: 0;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 900;
  text-align: center;
}

.status-message.is-success {
  color: var(--green-dark);
}

.status-message.is-warning {
  color: #9f2d25;
}

.status-message.is-shake {
  animation: shake 320ms ease;
}

.finish-screen {
  display: grid;
  min-height: calc(100vh - 48px);
  place-items: center;
}

.finish-card {
  width: min(580px, 100%);
  padding: 34px;
  text-align: center;
}

.finish-card h2 {
  margin-bottom: 18px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
}

.finish-record {
  display: grid;
  gap: 8px;
  margin: 0 auto 24px;
  padding: 16px;
  border-radius: 8px;
  background: #e7f7ef;
  color: var(--green-dark);
  font-weight: 900;
}

.is-pop {
  animation: pop 520ms ease;
}

@keyframes pop {
  0%,
  100% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.035);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-3px);
  }
}

@media (max-width: 900px) {
  h1 {
    font-size: clamp(2.7rem, 12vw, 5.2rem);
  }

  .start-screen {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .brand-panel {
    min-height: 420px;
  }

  .game-header {
    align-items: stretch;
    flex-direction: column;
  }

  .question-box {
    text-align: left;
  }

  .score-box {
    justify-content: flex-start;
    min-width: 0;
  }

  .score-box span {
    flex: 1 1 120px;
    text-align: center;
  }

  .board-card,
  .tutorial-card {
    min-height: auto;
    padding: 18px;
  }

  .circuit-diagram {
    min-width: 720px;
  }

  .tutorial-diagram .circuit-diagram {
    min-width: 680px;
  }

  .button-deck {
    grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
  }
}

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

  .brand-panel,
  .record-panel,
  .board-card,
  .finish-card,
  .tutorial-card {
    padding: 14px;
  }

  .brand-panel {
    min-height: calc(100vh - 20px);
    align-content: center;
  }

  .lead {
    font-size: 1rem;
  }

  .start-button,
  .submit-button,
  .secondary-button {
    width: 100%;
  }

  .game-header {
    min-height: 0;
    padding: 12px;
  }

  .question-box h2 {
    font-size: clamp(1.35rem, 7vw, 2rem);
  }

  .score-box {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .score-box span {
    min-width: 0;
    padding: 7px 6px;
    font-size: 0.78rem;
    overflow-wrap: anywhere;
  }

  .lamp {
    min-height: 72px;
    gap: 10px;
  }

  .bulb {
    width: 58px;
    height: 58px;
    border-width: 6px;
  }

  .lamp strong {
    min-width: 58px;
    font-size: 1rem;
  }

  .circuit-board {
    margin-top: 14px;
  }

  .circuit-diagram {
    min-width: 620px;
  }

  .button-deck {
    grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
    gap: 10px;
    margin-top: 14px;
  }

  .press-button {
    min-height: 108px;
    padding: 10px 8px 8px;
  }

  .button-face {
    width: 68px;
    height: 68px;
    border-width: 5px;
    font-size: 1.25rem;
  }

  .button-label {
    font-size: 0.9rem;
  }

  .submit-row {
    margin-top: 14px;
  }

  .status-message {
    font-size: 0.95rem;
  }

  .tutorial-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding: 8px;
  }

  .board-card,
  .tutorial-card {
    border-width: 3px;
  }

  .circuit-diagram {
    min-width: 560px;
  }

  .score-box {
    grid-template-columns: 1fr;
  }

  .score-box span {
    text-align: left;
  }
}

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