:root {
  color-scheme: dark;
  --bg: #050505;
  --surface: #0d0d0d;
  --surface-2: #151515;
  --line: #4b5563;
  --line-strong: #f8fafc;
  --text: #ffffff;
  --muted: #cbd5e1;
  --primary: #ff8a00;
  --primary-2: #ffd24a;
  --blue: #38bdf8;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: contain;
  touch-action: manipulation;
}

button,
input,
summary {
  font: inherit;
}

button {
  min-height: 52px;
  border-radius: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible {
  outline: 4px solid var(--blue);
  outline-offset: 3px;
}

.app-shell {
  width: 100%;
  min-height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background:
    linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, .04) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px;
}

.screen {
  display: none;
  width: 100%;
  min-height: calc(100dvh - 20px);
}

.screen.active {
  display: grid;
}

.panel {
  border: 2px solid var(--line);
  border-radius: 0;
  background: rgba(10, 10, 10, .96);
  box-shadow: none;
}

#genreScreen.active {
  width: min(1440px, 100%);
  margin: 0 auto;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 10px;
  align-items: stretch;
}

.hero-panel,
.settings-panel {
  padding: 14px;
}

.topbar,
.stage-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary-2);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 4.4vw, 64px);
  line-height: 1;
  font-weight: 950;
}

h2 {
  margin: 0;
}

.description {
  display: none;
}

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

.genre-btn {
  min-height: 86px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--surface-2);
  color: var(--text);
  font-size: clamp(17px, 1.9vw, 25px);
  font-weight: 950;
  text-align: left;
  box-shadow: none;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}

.genre-btn small {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  font-weight: 900;
}

.genre-btn:hover,
.genre-btn:active {
  transform: none;
  border-color: var(--line-strong);
  background: #242424;
}

.genre-btn.featured {
  min-height: 104px;
  grid-column: span 2;
  color: #000000;
  border-color: var(--primary);
  background: var(--primary);
}

.genre-btn.featured small,
.genre-btn.random-all small {
  color: #111111;
}

.genre-btn.random-all {
  min-height: 104px;
  grid-column: span 4;
  color: #000000;
  border-color: var(--primary-2);
  background: var(--primary-2);
  font-size: clamp(24px, 3vw, 40px);
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-panel h2 {
  margin-bottom: 2px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--line);
  font-size: 24px;
}

.setting-row {
  margin: 0;
  padding: 0 0 12px;
  border-bottom: 1px solid var(--line);
}

.setting-row label,
.toggle-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
}

.toggle-label {
  justify-content: flex-start;
  align-items: center;
}

.toggle-label input {
  width: 24px;
  height: 24px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  margin-top: 10px;
}

.reset-status {
  margin: 8px 0 0;
  padding: 9px 10px;
  border: 2px solid var(--primary-2);
  border-radius: 0;
  color: #000000;
  background: var(--primary-2);
  font-size: 14px;
  font-weight: 950;
  line-height: 1.35;
}

.reset-status.error {
  color: #ffffff;
  background: #7f1d1d;
  border-color: var(--danger);
}

.reset-status[hidden] {
  display: none;
}

.settings-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--blue);
  font-weight: 900;
  cursor: pointer;
}

.file-input {
  display: none;
}

.file-label {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  margin-top: 8px;
  padding: 0 14px;
  border-radius: 0;
  border: 2px solid var(--line);
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
}

.ghost-btn,
.secondary-btn,
.primary-btn {
  min-height: 52px;
  border: 2px solid var(--line-strong);
  border-radius: 0;
  padding: 0 16px;
  font-weight: 950;
  box-shadow: none;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}

.ghost-btn,
.secondary-btn {
  background: #1f2937;
  color: var(--text);
}

.primary-btn {
  background: var(--primary);
  color: #000000;
  border-color: var(--primary);
}

.ghost-btn:hover,
.secondary-btn:hover,
.primary-btn:hover {
  transform: none;
  filter: none;
  background: var(--line-strong);
  color: #000000;
}

.badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  max-width: 100%;
  padding: 5px 10px;
  border: 2px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: #111827;
  font-size: 14px;
  font-weight: 900;
}

.stage-screen.active {
  min-height: calc(100dvh - 20px);
}

.stage-meta {
  position: fixed;
  z-index: 20;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
}

.stage-meta .badge {
  display: none;
}

.lead-card {
  width: 100%;
  min-height: calc(100dvh - 20px);
  padding: clamp(28px, 6vw, 92px);
  display: grid;
  place-items: center;
  cursor: pointer;
  background: #0a0a0a;
  border-color: var(--line);
}

.lead-text {
  margin: 0;
  max-width: 12em;
  text-align: center;
  font-size: clamp(42px, 9vw, 152px);
  line-height: 1.05;
  font-weight: 950;
}

.tap-hint {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  border: 2px solid var(--primary);
  border-radius: 0;
  color: #000000;
  background: var(--primary);
  font-weight: 950;
}

.question-layout {
  position: relative;
  width: 100%;
  min-height: calc(100dvh - 20px);
}

.question-side {
  min-height: calc(100dvh - 20px);
  display: grid;
  place-items: center;
  padding: clamp(34px, 6vw, 100px);
  background: #050505;
  border: 2px solid var(--line);
}

.question-side > .badge,
.question-side > .eyebrow,
.image-prompt,
.image-credit {
  display: none !important;
}

.question-text {
  margin: 0 auto;
  max-width: 14.8em;
  text-align: center;
  font-size: clamp(48px, 7.6vw, 148px);
  line-height: 1.08;
  font-weight: 950;
  text-wrap: balance;
}

.image-mode .question-side {
  min-height: 0;
  padding: 0;
  display: block;
  border: 0;
}

.image-mode .question-text {
  display: none;
}

.image-stage {
  width: 100%;
  min-height: calc(100dvh - 20px);
  margin: 0;
  padding: 0;
  display: grid;
  place-items: center;
  background: #000000;
  overflow: hidden;
  border: 2px solid var(--line);
}

.image-stage img {
  width: 100%;
  height: calc(100dvh - 20px);
  object-fit: contain;
  background: #000000;
}

.action-row {
  position: fixed;
  z-index: 30;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: min(520px, calc(100vw - 20px));
}

.action-row button {
  min-width: 116px;
}

.loading,
.error {
  padding: 14px;
  border-radius: 0;
  line-height: 1.5;
}

.loading {
  color: var(--muted);
  background: #111827;
}

.error {
  color: #ffffff;
  background: #7f1d1d;
  border: 2px solid var(--danger);
}

@media (min-width: 1280px) and (orientation: landscape) {
  .app-shell {
    padding: 12px;
  }

  .question-text {
    font-size: clamp(72px, 8vw, 160px);
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  .app-shell {
    padding: 8px;
  }

  .screen,
  .stage-screen.active,
  .lead-card,
  .question-layout,
  .question-side,
  .image-stage,
  .image-stage img {
    min-height: calc(100dvh - 16px);
  }

  #genreScreen.active {
    grid-template-columns: minmax(0, 1fr) 236px;
    gap: 8px;
  }

  .hero-panel,
  .settings-panel {
    padding: 10px;
  }

  .description,
  .settings-panel p,
  details {
    font-size: 12px;
  }

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

  .genre-btn {
    min-height: 58px;
    font-size: 15px;
    padding: 8px;
  }

  .genre-btn.featured,
  .genre-btn.random-all {
    min-height: 68px;
  }

  .genre-btn.random-all {
    grid-column: span 3;
    font-size: 22px;
  }

  .question-side {
    padding: 34px 70px;
  }

  .question-text {
    font-size: clamp(36px, 7.8vw, 72px);
  }
}

@media (max-width: 760px), (orientation: portrait) {
  #genreScreen.active {
    grid-template-columns: 1fr;
  }

  .genre-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .genre-btn.random-all {
    grid-column: span 2;
  }

  .question-side {
    padding: 72px 18px 88px;
  }

  .question-text {
    font-size: clamp(40px, 12vw, 82px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
