/* ============================================================
   Refrain — dark, flat design system. No gradients anywhere;
   every fill is a solid color. Primary accent is #0066ff.
   ============================================================ */

:root {
  --color-bg: #0b0d10;
  --color-surface: #14171c;
  --color-surface-2: #1b1f26;
  --color-surface-3: #232833;
  --color-border: #2a3038;

  --color-text: #f2f4f7;
  --color-text-muted: #9aa3af;
  --color-text-faint: #6b7280;

  --color-primary: #0066ff;
  --color-primary-hover: #1a75ff;
  --color-primary-active: #0052cc;
  --color-primary-text: #ffffff;

  --color-success: #1fae5e;
  --color-success-bg: #12331f;
  --color-warn: #d6a300;
  --color-warn-bg: #332b0d;
  --color-error: #e5484d;
  --color-error-bg: #341415;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --max-width: 520px;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* Several elements below set their own `display` (flex/grid) at the same
   specificity as the browser's default `[hidden] { display: none }` rule,
   which would otherwise let the later, more specific author rule win and
   show elements marked hidden. This keeps `hidden` authoritative everywhere. */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input {
  font-family: inherit;
}

img {
  max-width: 100%;
  display: block;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  flex: 0 0 auto;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-size: 0.95rem;
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 3px;
  margin: 0 auto;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.tab.is-active {
  background: var(--color-primary);
  color: var(--color-primary-text);
}

.topbar-actions {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:active {
  background: var(--color-surface-2);
}

/* ---------- Layout ---------- */

.app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.round-meta {
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  min-height: 1.2em;
}

.category-tabs {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.cat-tab {
  appearance: none;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.cat-tab.is-active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-text);
}

.game-card {
  position: relative;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------- Loading overlay ---------- */

.loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 5;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-surface-3);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

/* ---------- Attempt bar ---------- */

.attempt-bar {
  display: flex;
  gap: 4px;
  height: 10px;
}

.attempt-seg {
  flex: 1;
  background: var(--color-surface-3);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.attempt-seg .fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
}

.attempt-seg.is-used .fill {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
}

.attempt-seg.is-current .fill {
  background: var(--color-primary);
}

.attempt-seg.is-correct .fill {
  width: 100% !important;
  background: var(--color-success) !important;
  border: none !important;
}

.attempt-seg.is-failed .fill {
  background: var(--color-surface-2);
  border: 1px solid var(--color-error);
}

/* ---------- Player ---------- */

.player-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.play-btn {
  flex: 0 0 auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary);
  color: var(--color-primary-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.play-btn:active {
  background: var(--color-primary-active);
}

.play-btn:disabled {
  background: var(--color-surface-3);
  color: var(--color-text-faint);
  cursor: default;
}

.play-btn svg {
  fill: currentColor;
}

.icon-play.is-hidden,
.icon-pause.is-hidden {
  display: none;
}

.player-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  font-weight: 700;
}

.hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.genre-hint {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-top: 2px;
}

/* ---------- Guess form ---------- */

.guess-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.autocomplete {
  position: relative;
}

.guess-input {
  width: 100%;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 16px; /* prevents iOS auto-zoom */
  padding: 13px 14px;
  border-radius: var(--radius-md);
  outline: none;
}

.guess-input:focus {
  border-color: var(--color-primary);
}

.guess-input:disabled {
  opacity: 0.6;
}

.suggestions {
  list-style: none;
  margin: 6px 0 0;
  padding: 6px;
  position: absolute;
  left: 0;
  right: 0;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  max-height: 260px;
  overflow-y: auto;
  z-index: 20;
}

.suggestion {
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.suggestion .s-title {
  font-weight: 600;
  font-size: 0.92rem;
}

.suggestion .s-artist {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.suggestion.is-active,
.suggestion:hover {
  background: var(--color-surface-3);
}

.guess-actions {
  display: flex;
  gap: 10px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
}

.btn-primary:active {
  background: var(--color-primary-active);
}

.btn-primary:disabled {
  background: var(--color-surface-3);
  color: var(--color-text-faint);
  cursor: default;
}

.btn-secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  flex: 0 0 auto;
}

.btn-secondary:active {
  background: var(--color-surface-3);
}

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---------- Guess history ---------- */

.guess-history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guess-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

.guess-row .g-icon {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--color-primary-text);
  background: var(--color-text-faint);
}

.guess-row.is-correct .g-icon { background: var(--color-success); }
.guess-row.is-artist .g-icon { background: var(--color-warn); }
.guess-row.is-wrong .g-icon { background: var(--color-error); }
.guess-row.is-skip .g-icon { background: var(--color-text-faint); }

.guess-row .g-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.guess-row .g-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.guess-row .g-artist {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.guess-row .g-tag {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-warn);
}

/* ---------- Reveal ---------- */

.reveal {
  display: grid;
  grid-template-columns: 76px 1fr;
  column-gap: 14px;
  row-gap: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--color-border);
}

.reveal-art {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-md);
  object-fit: cover;
  background: var(--color-surface-2);
}

.reveal-art-fallback {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: var(--color-text-faint);
}

.reveal-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.reveal-result {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-success);
}

.reveal-result.is-lost {
  color: var(--color-error);
}

.reveal-title {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reveal-artist {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reveal-link {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--color-primary);
  text-decoration: none;
  width: fit-content;
}

.reveal-link:active {
  color: var(--color-primary-active);
}

.reveal-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
}

.daily-countdown {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.82rem;
  color: var(--color-text-muted);
}

.daily-countdown span {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--color-text);
}

.status {
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-error);
  min-height: 1.2em;
  margin: 0;
}

/* ---------- Modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

@media (min-width: 560px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 560px) {
  .modal {
    border-radius: var(--radius-lg);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 8px;
  position: sticky;
  top: 0;
  background: var(--color-surface);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  padding: 8px 18px 22px;
}

.rules {
  margin: 0 0 16px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--color-text);
}

.rules-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.legend-correct { background: var(--color-success); }
.legend-artist { background: var(--color-warn); }
.legend-wrong { background: var(--color-error); }
.legend-skip { background: var(--color-text-faint); }

.rules-note {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin: 0;
}

.rules-note strong {
  color: var(--color-text);
}

/* ---------- Stats ---------- */

.stats-tabs {
  display: flex;
  gap: 4px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 3px;
  width: fit-content;
  margin-bottom: 18px;
}

.stats-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
}

.stats-tab.is-active {
  background: var(--color-primary);
  color: var(--color-primary-text);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat {
  text-align: center;
}

.stat-num {
  font-size: 1.5rem;
  font-weight: 800;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.distribution {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
}

.dist-row .dist-label {
  width: 14px;
  color: var(--color-text-muted);
  flex: 0 0 auto;
}

.dist-row .dist-bar-wrap {
  flex: 1;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 20px;
}

.dist-row .dist-bar {
  height: 100%;
  background: var(--color-text-faint);
  min-width: 20px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  color: var(--color-primary-text);
  font-size: 0.75rem;
  font-weight: 700;
}

.dist-row.is-best .dist-bar {
  background: var(--color-primary);
}

/* ---------- Small screens ---------- */

@media (max-width: 360px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    row-gap: 16px;
  }
}

.icon-btn svg{
  fill: currentColor;
}