:root {
  color-scheme: dark;
  --ink: #f8f5ed;
  --muted: #c8c1b4;
  --panel: rgba(23, 22, 27, 0.82);
  --line: rgba(255, 255, 255, 0.16);
  --gold: #f2c95d;
  --rose: #e97b8f;
  --teal: #53cabd;
  --plum: #6c4a88;
  --night: #14151d;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 12% 18%, rgba(83, 202, 189, 0.22), transparent 30%),
    radial-gradient(circle at 88% 20%, rgba(233, 123, 143, 0.2), transparent 34%),
    linear-gradient(135deg, #171923 0%, #2a2330 52%, #1c2630 100%);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 12px 22px;
  background: linear-gradient(135deg, var(--gold), #ff9f68);
  color: #23180c;
  font: 700 16px/1.2 inherit;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(242, 201, 93, 0.23);
}

button:focus-visible {
  outline: 3px solid #fff3b0;
  outline-offset: 3px;
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-color: rgba(255, 255, 255, 0.34);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  font: 700 12px/1.2 ui-monospace, Consolas, monospace;
  text-align: center;
}

.game-shell {
  width: min(1180px, calc(100vw - 28px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
  align-items: stretch;
}

.stage-panel,
.side-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
}

.stage-panel {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  aspect-ratio: 16 / 9;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #151720;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background: linear-gradient(135deg, rgba(16, 18, 27, 0.7), rgba(31, 24, 34, 0.56));
}

.overlay.hidden {
  display: none;
}

.dialog {
  width: min(520px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 28px;
  background: rgba(22, 20, 25, 0.88);
  text-align: center;
}

.dialog h1,
.dialog h2 {
  margin: 8px 0 12px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
}

.dialog p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.7;
}

.kicker {
  color: var(--teal) !important;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-radius: 8px;
  padding: 18px;
}

.portrait {
  position: relative;
  min-height: 170px;
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(150deg, rgba(83, 202, 189, 0.18), transparent 52%),
    linear-gradient(25deg, rgba(233, 123, 143, 0.22), transparent 58%),
    #1d1d28;
}

.hair {
  position: absolute;
  left: 50%;
  top: 18px;
  width: 114px;
  height: 132px;
  translate: -50% 0;
  border-radius: 54% 54% 44% 44%;
  background: linear-gradient(160deg, #44324d 0%, #292238 64%, #17151f 100%);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05);
}

.face {
  position: absolute;
  left: 50%;
  top: 48px;
  width: 78px;
  height: 84px;
  translate: -50% 0;
  border-radius: 42% 42% 48% 48%;
  background: linear-gradient(#f4d4bf, #eab69d);
}

.eye {
  position: absolute;
  top: 34px;
  width: 9px;
  height: 13px;
  border-radius: 50%;
  background: #5a2a35;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18) inset;
}

.eye.left {
  left: 21px;
}

.eye.right {
  right: 21px;
}

.smile {
  position: absolute;
  left: 50%;
  top: 57px;
  width: 18px;
  height: 8px;
  translate: -50% 0;
  border-bottom: 2px solid #8f4650;
  border-radius: 0 0 18px 18px;
}

.ribbon {
  position: absolute;
  left: 50%;
  top: 126px;
  width: 78px;
  height: 28px;
  translate: -50% 0;
  background: linear-gradient(135deg, var(--rose), #ffb06b);
  clip-path: polygon(0 0, 42% 33%, 50% 0, 58% 33%, 100% 0, 80% 100%, 54% 58%, 50% 100%, 46% 58%, 20% 100%);
}

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

.status-grid div,
.sequence,
.tips {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.status-grid div {
  min-width: 0;
  padding: 10px 8px;
}

.status-grid span,
.sequence span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 22px;
}

.sequence {
  padding: 14px;
}

.digits {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.digits b {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 24px;
}

.digits b.active {
  background: var(--gold);
  color: #21160a;
}

.digits b.done {
  background: var(--teal);
  color: #051917;
}

.tips {
  padding: 14px;
  color: var(--muted);
  line-height: 1.55;
}

.tips p {
  margin: 0 0 10px;
}

.tips p:last-child {
  margin-bottom: 0;
}

@media (max-width: 880px) {
  body {
    align-items: start;
    padding: 14px 0;
  }

  .game-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    display: grid;
    grid-template-columns: minmax(120px, 170px) 1fr;
  }

  .tips,
  .sequence {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .game-shell {
    width: calc(100vw - 16px);
    gap: 10px;
  }

  .side-panel {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .portrait {
    display: none;
  }

  .dialog {
    padding: 20px;
  }
}
