/* ===== base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  --radius: 22px;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.35s ease, color 0.35s ease;
}

/* ===== themes ===== */
body[data-theme="dopamine"] {
  --bg: #06010f;
  --ink: #f7f2ff;
  --muted: #b3a9d0;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.12);
  --input-bg: rgba(0, 0, 0, 0.35);
  --cell-bg: rgba(255, 255, 255, 0.07);
  --done-bg: linear-gradient(135deg, #ff2fb3, #a06bff);
  --accent: #ff2fb3;
  --accent-soft: rgba(255, 47, 179, 0.25);
  --cta-bg: linear-gradient(135deg, #ff2fb3, #b13bff 55%, #26e7ff);
  --cta-ink: #ffffff;
  --cta-shadow: 0 12px 34px rgba(255, 47, 179, 0.34);
  --menu-bg: rgba(12, 6, 24, 0.95);
  background-image:
    radial-gradient(70vw 55vw at 8% 4%, rgba(255, 47, 179, 0.2), transparent 62%),
    radial-gradient(60vw 55vw at 96% 10%, rgba(38, 231, 255, 0.16), transparent 62%),
    radial-gradient(80vw 60vw at 50% 112%, rgba(184, 255, 56, 0.12), transparent 65%);
  background-attachment: fixed;
  background-repeat: no-repeat;
}

body[data-theme="simple"] {
  --bg: #ffffff;
  --ink: #0d0d10;
  --muted: #5f5f6a;
  --panel: #f4f4f6;
  --panel-border: #dedee4;
  --input-bg: #ffffff;
  --cell-bg: #e8e8ed;
  --done-bg: #0d0d10;
  --accent: #0d0d10;
  --accent-soft: rgba(13, 13, 16, 0.12);
  --cta-bg: #0d0d10;
  --cta-ink: #ffffff;
  --cta-shadow: none;
  --menu-bg: #ffffff;
}

/* ===== app shell ===== */
#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9;
}

body[data-theme="simple"] #fx {
  display: none;
}

.app {
  width: min(1440px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(16px, 2.2vw, 28px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.screen[hidden] {
  display: none;
}

/* ===== setup ===== */
.setup {
  margin: auto;
  width: min(720px, 100%);
  padding: clamp(8px, 3vh, 36px) 0;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--muted);
}

.setup h1 {
  margin: 0 0 12px;
  font-size: clamp(32px, 4.4vw, 54px);
  line-height: 1.08;
  letter-spacing: -0.025em;
}

body[data-theme="dopamine"] .setup h1 {
  background-image: linear-gradient(100deg, #ffffff 8%, #ffd6f4 38%, #ff2fb3 66%, #26e7ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 26px rgba(255, 47, 179, 0.25));
}

.lead {
  margin: 0 0 22px;
  max-width: 52ch;
  color: var(--muted);
  font-size: clamp(14px, 1.4vw, 16px);
  line-height: 1.75;
}

.panel {
  padding: clamp(18px, 2.4vw, 26px);
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
}

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

.field {
  display: grid;
  gap: 8px;
}

.field-label,
.modes legend {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--panel-border);
  background: var(--input-bg);
  color: var(--ink);
  font: inherit;
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="number"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--panel-border);
  background: var(--input-bg);
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

body[data-theme="dopamine"] select option {
  background: #14101f;
  color: #f7f2ff;
}

.range-preview {
  margin: 14px 0 0;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px dashed var(--panel-border);
  background: var(--input-bg);
  text-align: center;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.modes {
  margin: 22px 0 0;
  padding: 0;
  border: 0;
}

.modes legend {
  padding: 0;
  margin-bottom: 10px;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-card {
  position: relative;
  display: grid;
  gap: 3px;
  padding: 15px 16px;
  border-radius: 16px;
  border: 1.5px solid var(--panel-border);
  background: var(--input-bg);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.mode-card:hover {
  transform: translateY(-1px);
}

.mode-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-card:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.mode-card:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mode-name {
  font-size: 16px;
  font-weight: 800;
}

.mode-desc {
  font-size: 13px;
  color: var(--muted);
}

/* ===== buttons ===== */
.cta {
  border: 0;
  border-radius: 16px;
  padding: 16px 22px;
  background: var(--cta-bg);
  color: var(--cta-ink);
  box-shadow: var(--cta-shadow);
  font-family: inherit;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.18s ease, box-shadow 0.18s ease;
}

.cta:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.cta:active {
  transform: translateY(1px) scale(0.995);
}

.cta:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

.start-btn {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 18px;
  font-size: 18px;
}

.resume-btn {
  display: block;
  width: 100%;
  margin-bottom: 14px;
  background: var(--panel);
  color: var(--ink);
  border: 1.5px solid var(--accent);
  box-shadow: none;
  font-size: 17px;
}

.resume-btn[hidden] {
  display: none;
}

.ghost {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.ghost:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.ghost:disabled,
.ghost:disabled:hover {
  opacity: 0.4;
  color: var(--muted);
  border-color: var(--panel-border);
  cursor: not-allowed;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ===== game layout ===== */
.game {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "top top"
    "stage side"
    "ctrl side"
    "board board";
  gap: clamp(10px, 1.6vh, 16px);
  min-height: 0;
}

.game-top {
  grid-area: top;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.menu-wrap {
  position: relative;
}

.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 15px;
}

.settings-btn::before {
  content: "⚙";
  font-size: 16px;
  line-height: 1;
}

.menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  width: min(264px, 82vw);
  padding: 8px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: var(--menu-bg);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.4);
}

.menu[hidden] {
  display: none;
}

.menu-title {
  margin: 6px 10px 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.menu-item:hover {
  background: var(--cell-bg);
}

.menu-item.is-on {
  color: var(--accent);
}

.menu-item:disabled,
.menu-item:disabled:hover {
  opacity: 0.4;
  background: transparent;
  cursor: not-allowed;
}

.menu-danger {
  color: #ff7a7a;
}

body[data-theme="simple"] .menu-danger {
  color: #b42323;
}

.menu-sep {
  height: 1px;
  margin: 6px 8px;
  background: var(--panel-border);
}

/* ===== stage ===== */
.stage {
  grid-area: stage;
  position: relative;
  display: grid;
  place-content: center;
  gap: clamp(12px, 2vh, 24px);
  min-height: 34vh;
  padding: clamp(16px, 2.5vh, 32px) clamp(14px, 2vw, 28px);
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

body[data-theme="dopamine"] .stage::before {
  content: "";
  position: absolute;
  inset: -55%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 47, 179, 0.5) 60deg,
    transparent 130deg,
    rgba(38, 231, 255, 0.45) 200deg,
    transparent 275deg,
    rgba(184, 255, 56, 0.35) 330deg,
    transparent 360deg
  );
  filter: blur(38px);
  opacity: 0.38;
  animation: swirl 9s linear infinite;
  pointer-events: none;
}

@keyframes swirl {
  to {
    transform: rotate(1turn);
  }
}

.reel {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
}

body[data-theme="dopamine"] .reel::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(40vh, 88%);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 70px rgba(255, 47, 179, 0.18), 0 0 44px rgba(38, 231, 255, 0.1);
  pointer-events: none;
}

#current-number {
  position: relative;
  font-size: clamp(72px, min(36vh, 27vw), 340px);
  font-weight: 900;
  line-height: 0.86;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

body[data-theme="dopamine"] #current-number {
  background-image: linear-gradient(170deg, #ffffff 8%, #ffe9fa 48%, #ff7ad4 84%, #ff2fb3 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 47, 179, 0.5)) drop-shadow(0 0 44px rgba(38, 231, 255, 0.2));
}

.reel.spinning {
  animation: shake 0.16s infinite alternate;
}

.reel.spinning #current-number {
  opacity: 0.88;
}

body[data-theme="simple"] .reel.spinning #current-number {
  opacity: 0.5;
  filter: blur(1.6px);
}

.reel.bang {
  animation: pop 0.5s cubic-bezier(0.22, 1.4, 0.4, 1);
}

@keyframes shake {
  from {
    transform: translateX(-3px);
  }
  to {
    transform: translateX(3px);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.8);
  }
  60% {
    transform: scale(1.07);
  }
  100% {
    transform: scale(1);
  }
}

.stage-hint {
  position: relative;
  z-index: 1;
  margin: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
}

/* ===== recent list ===== */
.side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.recent {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 16px 16px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.recent h2 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.recent-list {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  min-height: 0;
  margin: 0;
  padding: 2px;
  overflow: auto;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
}

.recent-list::-webkit-scrollbar,
.board::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.recent-list::-webkit-scrollbar-thumb,
.board::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--muted);
}

.recent-list li {
  display: grid;
  place-items: center;
  min-width: 76px;
  height: clamp(48px, 6.4vh, 66px);
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--cell-bg);
  font-size: clamp(21px, 3vh, 30px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.recent-list li:first-child {
  background: var(--done-bg);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 22px var(--accent-soft);
}

/* ===== board ===== */
.board {
  grid-area: board;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
  max-height: 22vh;
  padding: 12px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.board span {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 10px;
  background: var(--cell-bg);
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.board span.is-done {
  background: var(--done-bg);
  color: #fff;
  font-weight: 900;
  transform: scale(1.03);
  box-shadow: 0 4px 14px var(--accent-soft);
}

/* ===== controls ===== */
.controls {
  grid-area: ctrl;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

#draw {
  flex: 1 1 220px;
  padding: 24px 28px;
  font-size: clamp(20px, 3vh, 30px);
}

#auto {
  padding: 24px 20px;
  font-size: clamp(15px, 2vh, 19px);
  background: var(--panel);
  color: var(--ink);
  border: 1.5px solid var(--panel-border);
  box-shadow: none;
}

#auto.is-on {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#draw.is-stop {
  box-shadow: 0 0 0 4px var(--accent-soft), var(--cta-shadow);
}

.controls .ghost {
  padding: 18px 18px;
  border-radius: 14px;
  font-size: clamp(13px, 1.7vh, 16px);
}

.controls .hint {
  flex: 1 0 100%;
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* ===== responsive ===== */
@media (max-width: 900px) {
  .game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "top"
      "stage"
      "ctrl"
      "side"
      "board";
  }

  .recent {
    max-height: 26vh;
  }

  .board {
    max-height: 24vh;
  }

  .fields,
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

@media (pointer: coarse) {
  .ghost,
  #auto,
  .menu-item {
    min-height: 52px;
  }

  .recent-list li {
    min-width: 84px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body[data-theme="dopamine"] .stage::before,
  .reel.spinning {
    animation: none;
  }
}
