:root {
  --bg-felt: #0d131a;
  --bg-surface: #151e29;
  --bg-elevated: #1d2938;
  --border-subtle: #2b3b4e;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-gold: #eab308;
  --accent-blue: #38bdf8;
  --tile-empty: #111827;
  --tile-active: #38bdf8;
  --state-correct: #16a34a;
  --state-present: #d97706;
  --state-absent: #334155;
  --key-bg: #263344;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at top, #172331 0%, var(--bg-felt) 75%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

#app {
  max-width: 560px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 6px 10px 8px;
  gap: 6px;
}

.hidden {
  display: none !important;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px 10px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mana-dot {
  color: var(--accent-gold);
  font-size: 1rem;
}

.brand h1 {
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 5px;
}

.nav-btn {
  background: var(--bg-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.nav-btn.active {
  border-color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.16);
  color: #e0f2fe;
}

.nav-btn.accent-btn {
  border-color: rgba(234, 179, 8, 0.45);
  color: #fef08a;
}

.badge {
  background: var(--accent-blue);
  color: #082f49;
  font-weight: 800;
  font-size: 0.68rem;
  padding: 1px 5px;
  border-radius: 999px;
}

/* Main Game Layout (No-scroll mobile fit) */
.game-container {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  overflow: hidden;
}

/* Clue Card */
.clue-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 11px;
  flex-shrink: 0;
}

.clue-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.puzzle-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-gold);
}

.enum-tag {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent-blue);
  background: rgba(56, 189, 248, 0.12);
  padding: 1px 7px;
  border-radius: 6px;
}

.clue-prompt {
  font-size: 0.94rem;
  line-height: 1.3;
  font-weight: 500;
}

.tip-box {
  margin-top: 6px;
  padding: 5px 8px;
  background: rgba(234, 179, 8, 0.12);
  border-left: 3px solid var(--accent-gold);
  border-radius: 4px;
  font-size: 0.76rem;
  color: #fef9c3;
}

/* Guess History */
.history-section {
  flex: 1;
  min-height: 44px;
  overflow-y: auto;
  background: rgba(21, 30, 41, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-empty {
  margin: auto;
  font-size: 0.76rem;
  color: var(--text-muted);
  text-align: center;
}

.guess-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(43, 59, 78, 0.45);
}

.guess-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.word-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.mini-tile {
  width: 21px;
  height: 23px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.mini-tile.correct { background: var(--state-correct); }
.mini-tile.present { background: var(--state-present); }
.mini-tile.absent  { background: var(--state-absent); color: #cbd5e1; }

.punct-mark {
  font-weight: 800;
  color: var(--accent-gold);
  margin-left: 1px;
  font-size: 0.85rem;
}

/* Entry Area */
.entry-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 7px 8px;
  flex-shrink: 0;
}

.attempt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

#attempt-counter {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--text-muted);
}

.quick-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.action-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
}

.action-chip:hover {
  border-color: var(--accent-blue);
}

.action-chip.danger {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.4);
}

.slot-board {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 10px;
  padding: 2px 0;
}

.entry-word {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.letter-slot {
  width: clamp(23px, 6.4vw, 31px);
  height: clamp(29px, 7.4vw, 37px);
  background: var(--tile-empty);
  border: 1.5px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.12s, transform 0.08s;
}

.letter-slot.focused {
  border-color: var(--tile-active);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
  transform: translateY(-1px);
}

.letter-slot.locked-green {
  background: var(--state-correct);
  border-color: #22c55e;
  color: #ffffff;
}

.toast-banner {
  min-height: 16px;
  margin-top: 4px;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 600;
  color: #fde047;
}

/* On-Screen Keyboard */
.keyboard-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
  padding-bottom: 2px;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.kb-key {
  flex: 1;
  max-width: 44px;
  height: 39px;
  border: none;
  border-radius: 6px;
  background: var(--key-bg);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.kb-key.wide {
  flex: 1.55;
  max-width: 68px;
  font-size: 0.72rem;
}

.kb-key.correct { background: var(--state-correct); color: #fff; }
.kb-key.present { background: var(--state-present); color: #fff; }
.kb-key.absent  { background: #1a2330; color: #64748b; }

/* Cardfetcher Reveal Section */
.reveal-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--accent-gold);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reveal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(22, 163, 74, 0.22);
  color: #86efac;
  margin-bottom: 3px;
}

.status-pill.lost {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.card-title {
  font-size: 1.02rem;
  font-weight: 800;
}

.card-type {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.reveal-buttons {
  display: flex;
  gap: 6px;
}

.primary-btn {
  background: var(--accent-gold);
  color: #111827;
  border: none;
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
}

.reveal-body {
  display: grid;
  grid-template-columns: 135px 1fr;
  gap: 10px;
  align-items: start;
}

.card-visual-box {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.art-toggle-bar {
  display: flex;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  overflow: hidden;
}

.toggle-btn {
  flex: 1;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: none;
  padding: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}

.toggle-btn.active {
  background: var(--accent-blue);
  color: #082f49;
}

.card-frame {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: #0b1017;
}

.card-frame img {
  width: 100%;
  display: block;
  object-fit: cover;
}

.card-frame.art-mode img {
  aspect-ratio: 4 / 3;
  object-position: center 22%;
}

.card-fallback {
  padding: 8px;
  font-size: 0.68rem;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: linear-gradient(145deg, #1f2937, #111827);
}

.fallback-header {
  display: flex;
  justify-content: space-between;
  font-weight: 800;
  color: #f8fafc;
}

.fallback-art {
  height: 54px;
  border-radius: 5px;
  background: radial-gradient(circle at 30% 30%, #38bdf8, #1e1b4b 70%);
}

.card-frame.art-mode .fallback-header,
.card-frame.art-mode .fallback-type,
.card-frame.art-mode .fallback-rules {
  display: none;
}

.card-frame.art-mode .fallback-art {
  height: 92px;
}

.fallback-type {
  color: var(--accent-gold);
  font-weight: 700;
}

.fallback-rules {
  color: #cbd5e1;
  line-height: 1.25;
}

.card-details-box {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.detail-block h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-blue);
  margin-bottom: 2px;
}

.rules-copy, .breakdown-copy {
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text-main);
}

.scryfall-link {
  display: inline-block;
  margin-top: 2px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent-gold);
  text-decoration: none;
}

/* Archive View */
.archive-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px;
  gap: 8px;
}

.archive-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.archive-header h2 {
  font-size: 1rem;
}

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

.archive-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text-main);
}

.archive-item:hover {
  border-color: var(--accent-blue);
}

.archive-item-title {
  font-size: 0.82rem;
  font-weight: 700;
}

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

.archive-status {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 3px 7px;
  border-radius: 999px;
  background: #0f172a;
  color: var(--text-muted);
  white-space: nowrap;
}

.archive-status.solved { background: rgba(22, 163, 74, 0.25); color: #86efac; }
.archive-status.failed { background: rgba(239, 68, 68, 0.25); color: #fca5a5; }
.archive-status.today  { background: rgba(56, 189, 248, 0.22); color: #7dd3fc; }

/* Sponsor Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 15, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-surface);
  border: 1px solid var(--accent-gold);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sponsor-tag {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-gold);
}

.sponsor-copy {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.countdown-ring {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--accent-blue);
}

.progress-track {
  width: 100%;
  height: 6px;
  background: #0f172a;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-gold);
  transition: width 0.25s linear;
}

@media (max-width: 400px) {
  .reveal-body {
    grid-template-columns: 112px 1fr;
  }
  .kb-key {
    height: 36px;
    font-size: 0.78rem;
  }
}
