:root {
  color-scheme: dark;
  --background: #111820;
  --surface: #19232c;
  --line: #33414c;
  --text: #f4f7f9;
  --muted: #9cabb6;
  --accent: #ffd54a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

button, input { font: inherit; }

.page-shell {
  width: min(400px, calc(100% - 28px));
  margin: 0 auto;
  padding: 30px 0 44px;
}

h1 {
  margin: 0 0 22px;
  text-align: center;
  font-size: 28px;
  letter-spacing: -.04em;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

button:hover { border-color: #73818c; }
button:focus-visible, input:focus-visible { outline: 3px solid #6ec1e8; outline-offset: 2px; }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 auto 14px;
  padding: 4px;
  border-radius: 10px;
  background: #0b1117;
}

.mode-switch button { border-color: transparent; background: transparent; }
.mode-switch button.selected { color: #17130a; background: var(--accent); font-weight: 750; }

.game-column { position: relative; text-align: center; }
.canvas-frame {
  position: relative;
  width: min(362px, 100%);
  margin: auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
}

canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; touch-action: manipulation; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: var(--surface); }
body.loaded #loading { display: none; }

.controls { display: flex; justify-content: center; gap: 8px; margin-top: 14px; }
.controls button { min-width: 86px; }
.controls .primary { color: #17130a; border-color: var(--accent); background: var(--accent); font-weight: 750; }

.key-help { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
kbd { padding: 1px 4px; border: 1px solid #52606b; border-radius: 3px; font: 11px ui-monospace, monospace; }
.play-help { width: min(362px, 100%); margin: 12px auto 0; color: var(--muted); text-align: left; font-size: 13px; line-height: 1.5; }
.play-help summary, .ai-help-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  margin: auto;
  padding: 7px 11px 7px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 5px 16px rgba(0, 0, 0, .2);
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  list-style: none;
}
.play-help summary::-webkit-details-marker { display: none; }
.play-help summary:hover, .ai-help-button:hover { border-color: #73818c; }
.play-help[open] summary { border-color: var(--accent); }
.play-help.disabled summary { opacity: .42; border-color: var(--line); box-shadow: none; cursor: not-allowed; }
.play-help.disabled .shoulder-mark { color: var(--muted); background: #35414a; }
.shoulder-mark { display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 4px; border-radius: 999px; color: #17130a; background: var(--accent); font: 800 11px ui-monospace, monospace; }
.play-guide { margin-top: 12px; padding: 4px 14px 14px; border-top: 1px solid var(--line); }
.play-guide section { padding-top: 14px; }
.play-guide section + section { margin-top: 14px; border-top: 1px solid var(--line); }
.play-guide h3 { margin: 0 0 6px; color: var(--text); font-size: 13px; }
.play-guide p { margin: 0; }
.play-guide p + p { margin-top: 8px; }
.ai-help-button { margin-top: 12px; }

.ai-dialog {
  width: min(720px, calc(100% - 32px));
  max-height: min(760px, calc(100vh - 32px));
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--background);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .55);
}
.ai-dialog::backdrop { background: rgba(4, 8, 12, .78); }
.dialog-heading { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; gap: 24px; padding: 24px 28px 20px; border-bottom: 1px solid var(--line); background: var(--background); }
.dialog-kicker { margin: 0 0 5px; color: var(--accent); font: 700 10px ui-monospace, monospace; letter-spacing: .12em; }
.dialog-heading h2 { margin: 0; font-size: 24px; letter-spacing: -.03em; }
.dialog-close { align-self: start; width: 34px; height: 34px; padding: 0; border: 0; color: var(--muted); background: transparent; font-size: 26px; line-height: 1; }
.explanation { padding: 8px 28px 28px; }
.explanation section { display: grid; grid-template-columns: 28px 1fr; gap: 14px; padding: 20px 0; }
.explanation section + section { border-top: 1px solid var(--line); }
.explanation section > span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #17130a; background: var(--accent); font-size: 12px; font-weight: 800; }
.explanation h3 { margin: 2px 0 8px; font-size: 16px; }
.explanation p { margin: 0; color: var(--muted); line-height: 1.65; }
.explanation .formula { width: max-content; max-width: 100%; margin-top: 12px; padding: 7px 10px; border-radius: 5px; color: var(--text); background: var(--surface); font: 12px ui-monospace, monospace; }

.settings {
  display: grid;
  gap: 16px;
  width: min(362px, 100%);
  margin: 24px auto 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.speed-setting { display: grid; gap: 8px; }
.speed-setting > span, .hard-value { display: flex; justify-content: space-between; align-items: center; }
.speed-setting output { color: var(--text); font-weight: 700; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.settings-row, .hard-settings { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.seed-setting { display: flex; align-items: center; gap: 9px; }
.check-setting { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
input[type="number"] { width: 92px; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; color: var(--text); background: #0d141a; }
.hard-value { flex: 1; gap: 9px; }
.hard-value input { width: 64px; }
.hard-value span { white-space: nowrap; }

.hidden { display: none; }

@media (min-width: 1021px) {
  .play-help {
    position: absolute;
    top: 0;
    right: calc(100% + 18px);
    z-index: 2;
    width: 280px;
    margin: 0;
  }

  .play-help summary { margin: 0 0 0 auto; }
  .play-guide {
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 12px 32px rgba(0, 0, 0, .28);
  }

  .ai-help-button {
    position: absolute;
    top: 0;
    left: calc(100% + 18px);
    margin: 0;
    white-space: nowrap;
  }
}

@media (max-width: 420px) {
  .page-shell { padding-top: 20px; }
  h1 { margin-bottom: 16px; }
  .dialog-heading { padding: 20px; }
  .dialog-heading h2 { font-size: 21px; }
  .explanation { padding: 4px 20px 20px; }
}
