/* 1. Reset */
* { box-sizing: border-box; }
html { min-width: 320px; background: #0b0b0d; }
body, h1, h2, p { margin: 0; }
button, a { font: inherit; }

/* 2. Tokens */
:root {
  color-scheme: dark;
  --bg: #0b0b0d;
  --surface: #151518;
  --surface-hover: #1d1d21;
  --text: #f3f1ec;
  --text-secondary: #aaa7a0;
  --text-muted: #77746e;
  --border: rgba(255, 255, 255, 0.12);
  --accent: #d8ff65;
  --accent-text: #101108;
  --danger: #ff8b8b;
  --danger-bg: rgba(255, 139, 139, 0.14);
  --shadow: 0 16px 54px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --content-width: 1280px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* 3. Base */
body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 0%, rgba(216, 255, 101, 0.12), transparent 24rem),
    linear-gradient(180deg, #111114 0%, var(--bg) 40%, #080809 100%);
  text-rendering: optimizeLegibility;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }

/* 4. Layout */
.shell {
  width: 100%;
  max-width: var(--content-width);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px 48px;
}

.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.wide-button { width: 100%; }

.primary-button, .ghost-button, .quiet-button, .danger-button, .text-button, .about-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  border: 1px solid var(--border);
  padding: 0 16px;
  color: var(--text);
  background: var(--surface-hover);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-button {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent);
  font-weight: 800;
}

.quiet-button, .text-button { background: transparent; }
.text-button { border-color: transparent; color: var(--accent); padding-inline: 6px; }
.danger-button { border-color: rgba(255, 139, 139, 0.45); color: #fff4f4; background: var(--danger-bg); }

.primary-button:hover, .ghost-button:hover, .quiet-button:hover, .danger-button:hover, .about-link:hover {
  transform: translateY(-1px);
}

.primary-button:active, .ghost-button:active, .quiet-button:active, .danger-button:active, .about-link:active, .soup-card:active {
  transform: scale(0.99);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* 5. Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

.brand, .about-link {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.brand { padding: 0; background: transparent; }
.about-link { min-height: 40px; padding: 0 12px; }

.brand-mark, .card-icon, .story-icon {
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}

.brand-mark { width: 36px; height: 36px; font-size: 0.86rem; }
.category-icon { flex: 0 0 auto; }

/* 6. Home */
.hero {
  display: grid;
  gap: 18px;
  margin-bottom: 20px;
}

.eyebrow { margin-bottom: 8px; color: var(--accent); font-size: 0.95rem; font-weight: 800; }
h1 { color: var(--text); font-size: clamp(50px, 13vw, 76px); line-height: 0.98; letter-spacing: 0; }
h2 { color: var(--text); font-size: 1rem; line-height: 1.35; }
.home-screen h1 { font-size: clamp(56px, 9vw, 104px); }
.host-screen h1 { font-size: clamp(40px, 6vw, 72px); }
.players-screen h1 { font-size: clamp(40px, 7vw, 76px); }
.reveal-screen h1, .about-page h1 { font-size: clamp(42px, 6vw, 72px); }

.hero-copy {
  max-width: 440px;
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 1.04rem;
  line-height: 1.65;
}

.hero-action { width: min(100%, 340px); margin-top: 16px; }

.notice {
  margin-bottom: 12px;
  border: 1px solid rgba(216, 255, 101, 0.32);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--accent);
  background: rgba(216, 255, 101, 0.08);
}

/* 7. Filters */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.filters::-webkit-scrollbar { display: none; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 13px;
  color: var(--text-secondary);
  background: transparent;
  white-space: nowrap;
}

.filter-chip.is-active {
  border-color: var(--accent);
  color: var(--accent-text);
  background: var(--accent);
  font-weight: 800;
}

/* 8. Cards */
.soup-grid, .related-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.soup-card {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 32px;
  gap: 14px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.soup-card:hover {
  border-color: rgba(216, 255, 101, 0.45);
  background: var(--surface-hover);
  transform: translateY(-3px);
}

.soup-card.is-compact { min-height: auto; box-shadow: none; }
.card-icon { width: 48px; height: 48px; font-size: 1.85rem; line-height: 1; }
.card-body { display: grid; min-width: 0; gap: 8px; }
.card-body strong { color: var(--text); font-size: 1.18rem; line-height: 1.25; }

.surface-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--text-secondary);
  font-size: 0.98rem;
  line-height: 1.48;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card-meta { color: var(--text-secondary); font-size: 0.9rem; line-height: 1.4; }
.card-arrow { align-self: center; justify-self: end; color: var(--accent); }
.tag-row { display: flex; gap: 7px; overflow: hidden; white-space: nowrap; }
.tag-row .tag:nth-child(n+5) { display: none; }

.tag {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 8px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.82rem;
}

.empty { border: 1px dashed var(--border); border-radius: var(--radius); padding: 24px; color: var(--text-secondary); text-align: center; }
.empty-state { max-width: 760px; padding: 64px 0; color: var(--text); }
.empty-state h1 { margin: 0 0 16px; font-size: clamp(36px, 7vw, 64px); line-height: 1.05; }
.empty-state p { margin: 0; color: var(--text-secondary); font-size: 18px; line-height: 1.65; }

/* 9. Host */
.host-screen { display: grid; gap: 16px; padding-bottom: 88px; }
.host-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.story-meta { display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; color: var(--text-secondary); font-size: 0.92rem; line-height: 1.45; text-align: right; }

.host-hero, .panel, .reveal-panel, .related-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.host-hero { display: grid; gap: 16px; align-content: start; }
.story-icon { width: 52px; height: 52px; font-size: 2rem; }
.host-surface { color: var(--text); font-size: clamp(24px, 5vw, 36px); line-height: 1.55; }
.host-grid { display: grid; gap: 14px; }
.panel { display: grid; gap: 10px; }
.helper-text { color: var(--text-muted); font-size: 0.9rem; line-height: 1.5; }

.hold-answer-button {
  width: 100%;
  border: 1px dashed rgba(216, 255, 101, 0.5);
  color: var(--accent);
  background: rgba(216, 255, 101, 0.08);
  font-weight: 800;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.answer-box {
  min-height: 140px;
  max-height: min(42vh, 360px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--text-muted);
  background: #101012;
  line-height: 1.65;
  white-space: pre-wrap;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.answer-box.is-visible { border-color: rgba(216, 255, 101, 0.42); color: #fbffe9; background: rgba(216, 255, 101, 0.07); }

.host-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.host-list li { border-left: 2px solid rgba(216, 255, 101, 0.5); padding-left: 10px; color: var(--text-secondary); line-height: 1.56; }
.hint-list { display: grid; gap: 8px; }

.hint-button {
  display: grid;
  width: 100%;
  gap: 6px;
  border: 1px solid var(--border);
  padding: 12px;
  color: var(--text-secondary);
  text-align: left;
  background: transparent;
}

.hint-button.is-open { border-color: rgba(216, 255, 101, 0.45); color: var(--text); background: rgba(216, 255, 101, 0.06); }
.hint-button strong { color: #fbffe9; font-weight: 600; line-height: 1.55; }

.action-bar {
  position: sticky;
  z-index: 5;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(180px, 260px);
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  background: rgba(21, 21, 24, 0.96);
  box-shadow: var(--shadow);
}

/* 10. Players */
.players-screen {
  min-height: calc(100dvh - 28px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-bottom: max(78px, env(safe-area-inset-bottom));
}

.players-card { display: grid; gap: 22px; }
.players-card h1 { text-align: center; }
.players-surface {
  width: min(100%, 820px);
  margin: 0 auto;
  color: var(--text);
  font-size: clamp(30px, 7vw, 48px);
  line-height: 1.55;
  text-align: center;
}

.players-footer {
  position: fixed;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 16px;
  display: grid;
  max-width: calc(var(--content-width) - 32px);
  margin: 0 auto;
}

/* 11. Reveal */
.reveal-screen { display: grid; gap: 16px; }
.reveal-panel { display: grid; gap: 18px; }
.reveal-section { display: grid; gap: 8px; }
.reveal-section p, .answer-text { color: var(--text-secondary); line-height: 1.7; white-space: pre-wrap; }
.answer-text { max-width: 900px; color: #fbffe9; line-height: 1.75; }
.related-section { display: grid; gap: 12px; }

/* 12. Dialog */
.modal-root {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-root[hidden] {
  display: none !important;
}

.dialog-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.72); }
.dialog {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(100%, 420px);
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.dialog p { color: var(--text-secondary); line-height: 1.55; }

/* 13. About */
.about-page .topbar { margin-bottom: 28px; }
.about-content {
  display: grid;
  gap: 18px;
  width: min(100%, 820px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.about-content p { color: var(--text-secondary); font-size: 1.08rem; line-height: 1.78; }
.about-back { justify-self: start; }
.contact-box { display: grid; gap: 8px; border-top: 1px solid var(--border); padding-top: 16px; }

/* 14. Responsive */
@media (min-width: 720px) {
  .shell { padding-inline: 24px; }
  .hero { max-width: 620px; }
  .soup-grid, .related-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .host-grid { grid-template-columns: minmax(320px, 1.2fr) minmax(260px, 0.8fr); }
  .answer-panel { grid-row: span 2; }
  .hints-panel { grid-column: 1 / -1; }
  .action-bar { justify-content: end; }
}

@media (min-width: 1080px) {
  .soup-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .host-grid { grid-template-columns: minmax(330px, 0.9fr) repeat(2, minmax(0, 1fr)); align-items: start; }
}

@media (max-width: 520px) {
  .shell { padding-inline: 12px; }
  .topbar { margin-bottom: 18px; }
  .brand { gap: 8px; font-size: 0.95rem; }
  .brand-mark { width: 32px; height: 32px; font-size: 0.78rem; }
  .about-link span { display: none; }
  .hero-action { width: 100%; }
  .soup-card { grid-template-columns: 42px minmax(0, 1fr) 28px; padding: 14px; }
  .card-icon { width: 42px; height: 42px; font-size: 1.65rem; }
  .tag-row .tag:nth-child(n+4) { display: none; }
  .host-top { align-items: flex-start; }
  .story-meta { max-width: 170px; }
  .action-bar { grid-template-columns: 1fr; }
  .about-content { padding: 18px; }
}

@media (max-width: 340px) {
  .brand span:last-child { display: none; }
  h1 { font-size: 48px; }
}

/* 15. Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
