/* === RESET === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* === CUSTOM PROPERTIES — LIGHT (default) === */
:root,
[data-theme="light"] {
  --bg-primary: #f5f0e8;
  --bg-secondary: #ebe5d9;
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a6a;
  --text-muted: #8a8a96;
  --card-border-color: #1a1a2e;
  --card-face-color: #f8f4ec;
  --card-inner-border: #c9c0ab;
  --card-text-color: #1a1a2e;
  --card-number-color: #1a1a2e;
  --card-clarity-color: #6b6570;
  --btn-primary-bg: #1a1a2e;
  --btn-primary-text: #f5f0e8;
  --btn-primary-hover: #2d2d4a;
  --btn-secondary-bg: transparent;
  --btn-secondary-text: #1a1a2e;
  --btn-secondary-border: #1a1a2e;
  --btn-secondary-hover: rgba(26, 26, 46, 0.08);
  --mode-bg: #e2dcd0;
  --mode-active-bg: #1a1a2e;
  --mode-active-text: #f5f0e8;
  --mode-text: #5a5a6a;
  --accent: #d4a853;
  --shadow-soft: rgba(0, 0, 0, 0.08);
  --shadow-medium: rgba(0, 0, 0, 0.15);
  --shadow-strong: rgba(0, 0, 0, 0.22);
  --placeholder-bg: rgba(26, 26, 46, 0.04);
  --placeholder-border: rgba(26, 26, 46, 0.12);
  --divider: rgba(26, 26, 46, 0.1);
  --focus-ring: rgba(212, 168, 83, 0.5);
  color-scheme: light;
}

/* === DARK THEME === */
[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --text-primary: #e8e4dc;
  --text-secondary: #a8a4b0;
  --text-muted: #6e6a7a;
  --card-border-color: #d4a853;
  --card-face-color: #1e1e32;
  --card-inner-border: #3a3a52;
  --card-text-color: #e8e4dc;
  --card-number-color: #d4a853;
  --card-clarity-color: #8a86a0;
  --btn-primary-bg: #d4a853;
  --btn-primary-text: #0f0f1a;
  --btn-primary-hover: #e0b86a;
  --btn-secondary-bg: transparent;
  --btn-secondary-text: #d4a853;
  --btn-secondary-border: #d4a853;
  --btn-secondary-hover: rgba(212, 168, 83, 0.1);
  --mode-bg: #1a1a2e;
  --mode-active-bg: #d4a853;
  --mode-active-text: #0f0f1a;
  --mode-text: #8a86a0;
  --accent: #d4a853;
  --shadow-soft: rgba(0, 0, 0, 0.2);
  --shadow-medium: rgba(0, 0, 0, 0.35);
  --shadow-strong: rgba(0, 0, 0, 0.5);
  --placeholder-bg: rgba(212, 168, 83, 0.04);
  --placeholder-border: rgba(212, 168, 83, 0.15);
  --divider: rgba(255, 255, 255, 0.08);
  --focus-ring: rgba(212, 168, 83, 0.5);
  color-scheme: dark;
}

/* === AUTO THEME (follows system preference) === */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --text-primary: #e8e4dc;
    --text-secondary: #a8a4b0;
    --text-muted: #6e6a7a;
    --card-border-color: #d4a853;
    --card-face-color: #1e1e32;
    --card-inner-border: #3a3a52;
    --card-text-color: #e8e4dc;
    --card-number-color: #d4a853;
    --card-clarity-color: #8a86a0;
    --btn-primary-bg: #d4a853;
    --btn-primary-text: #0f0f1a;
    --btn-primary-hover: #e0b86a;
    --btn-secondary-bg: transparent;
    --btn-secondary-text: #d4a853;
    --btn-secondary-border: #d4a853;
    --btn-secondary-hover: rgba(212, 168, 83, 0.1);
    --mode-bg: #1a1a2e;
    --mode-active-bg: #d4a853;
    --mode-active-text: #0f0f1a;
    --mode-text: #8a86a0;
    --accent: #d4a853;
    --shadow-soft: rgba(0, 0, 0, 0.2);
    --shadow-medium: rgba(0, 0, 0, 0.35);
    --shadow-strong: rgba(0, 0, 0, 0.5);
    --placeholder-bg: rgba(212, 168, 83, 0.04);
    --placeholder-border: rgba(212, 168, 83, 0.15);
    --divider: rgba(255, 255, 255, 0.08);
    --focus-ring: rgba(212, 168, 83, 0.5);
    color-scheme: dark;
  }
}

/* === TYPOGRAPHY === */
body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === FOCUS STYLES === */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}

/* === HEADER === */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--divider);
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* === THEME TOGGLE === */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.theme-toggle:active {
  transform: scale(0.95);
}

.theme-icon {
  display: none;
}

[data-theme="light"] .theme-icon--light,
[data-theme="dark"] .theme-icon--dark,
[data-theme="auto"] .theme-icon--auto {
  display: block;
}

/* Auto theme: show appropriate icon based on system preference */
@media (prefers-color-scheme: light) {
  [data-theme="auto"] .theme-icon--auto { display: block; }
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] .theme-icon--auto { display: block; }
}

/* === MAIN === */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
  gap: 1.5rem;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* === MODE TOGGLE === */
.mode-toggle {
  display: flex;
  background: var(--mode-bg);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}

.mode-btn {
  padding: 0.5rem 1.5rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--mode-text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  user-select: none;
}

.mode-btn.active {
  background: var(--mode-active-bg);
  color: var(--mode-active-text);
  box-shadow: 0 2px 8px var(--shadow-soft);
}

.mode-btn:not(.active):hover {
  color: var(--text-primary);
  background: var(--btn-secondary-hover);
}

/* === CARD AREA === */
.card-area {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 380px;
  position: relative;
}

/* === CARD PLACEHOLDER === */
.card-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 3rem 2rem;
  border: 2px dashed var(--placeholder-border);
  border-radius: 16px;
  background: var(--placeholder-bg);
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.placeholder-icon {
  font-size: 3rem;
  font-weight: 800;
  color: var(--text-muted);
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--placeholder-border);
  border-radius: 50%;
  opacity: 0.6;
}

.card-placeholder p {
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 400;
}

/* === CARD === */
.card-outer {
  background: var(--card-face-color);
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 3 / 4;
  /* Layered borders: outer dark border, gap of face color, inner accent line */
  border: 10px solid var(--card-border-color);
  box-shadow:
    inset 0 0 0 2px var(--card-inner-border),
    0 4px 12px var(--shadow-soft),
    0 8px 32px var(--shadow-medium);
  transition: box-shadow 0.3s ease;
}

.card-outer:hover {
  box-shadow:
    inset 0 0 0 2px var(--card-inner-border),
    0 6px 16px var(--shadow-medium),
    0 12px 40px var(--shadow-strong);
}

.card-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  position: relative;
}

.card-number {
  position: absolute;
  top: 14px;
  left: 18px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--card-number-color);
  opacity: 0.7;
}

.card-question {
  font-size: clamp(1.2rem, 4.5vw, 1.7rem);
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.35;
  color: var(--card-text-color);
  letter-spacing: 0.01em;
  max-width: 100%;
  word-break: break-word;
}

.card-clarity {
  font-size: 0.85rem;
  font-weight: 400;
  font-style: italic;
  color: var(--card-clarity-color);
  text-align: center;
  line-height: 1.4;
  opacity: 0;
  max-height: 0;
  margin-top: 0;
  overflow: hidden;
  transition: opacity 0.35s ease, max-height 0.35s ease, margin-top 0.35s ease;
}

.card-outer.revealed .card-clarity {
  opacity: 1;
  max-height: 100px;
  margin-top: 1rem;
}

.card-clarity:empty {
  display: none;
}

/* Tap-to-reveal hint */
.card-reveal-hint {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  font-weight: 400;
  font-style: italic;
  color: var(--text-muted);
  text-align: center;
  opacity: 0.7;
  animation: hintPulse 2s ease-in-out infinite;
  transition: opacity 0.25s ease;
}

.card-outer.revealed .card-reveal-hint {
  display: none;
}

/* Pointer hint on unrevealed card */
.card-outer:not(.revealed):not(.hidden) {
  cursor: pointer;
}

@keyframes hintPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.9; }
}

/* === ALL DRAWN MESSAGE === */
.all-drawn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 3rem 2rem;
  text-align: center;
}

.all-drawn-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

.all-drawn-sub {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

/* === BUTTONS === */
.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 380px;
}

.btn-primary {
  width: 100%;
  padding: 1rem 2rem;
  border: none;
  border-radius: 12px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px var(--shadow-soft);
  user-select: none;
}

.btn-primary:hover {
  background: var(--btn-primary-hover);
  box-shadow: 0 4px 16px var(--shadow-medium);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 1px 4px var(--shadow-soft);
}

.btn-secondary {
  padding: 0.65rem 1.5rem;
  border: 1.5px solid var(--btn-secondary-border);
  border-radius: 10px;
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-secondary:hover {
  background: var(--btn-secondary-hover);
}

.btn-secondary:active {
  transform: scale(0.97);
}

/* === COUNTER ROW === */
.counter-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
  min-height: 1.6em;
}

.reset-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--divider);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.reset-icon-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  transform: rotate(-45deg);
}

.reset-icon-btn:active {
  transform: rotate(-90deg) scale(0.9);
}

/* === FOOTER === */
.footer {
  text-align: center;
  padding: 1.25rem;
  border-top: 1px solid var(--divider);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 400;
}

/* === HIDDEN UTILITY === */
.hidden {
  display: none !important;
}

/* === ANIMATIONS === */
@keyframes cardSlideIn {
  0% {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  60% {
    opacity: 1;
    transform: translateY(-4px) scale(1.01);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes cardSlideOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
}

@keyframes cardIdle {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-enter {
  animation: cardSlideIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.card-exit {
  animation: cardSlideOut 0.25s ease-in forwards;
}

.card-idle {
  animation: cardIdle 3s ease-in-out infinite;
}

.fade-in {
  animation: fadeIn 0.3s ease-out forwards;
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === RESPONSIVE === */

/* Mobile — small (up to 380px) */
@media (max-width: 380px) {
  .header {
    padding: 1rem;
  }

  .logo {
    font-size: 1.25rem;
  }

  .tagline {
    font-size: 0.78rem;
  }

  .main {
    padding: 1rem 0.75rem;
    gap: 1.25rem;
  }

  .card-area {
    min-height: 320px;
  }

  .card-outer {
    max-width: 300px;
  }

  .card-inner {
    padding: 2rem 1.25rem;
  }

  .card-question {
    font-size: clamp(1rem, 4vw, 1.4rem);
  }

  .mode-btn {
    padding: 0.45rem 1.2rem;
    font-size: 0.85rem;
  }
}

/* Tablet and up */
@media (min-width: 640px) {
  .header {
    padding: 1.5rem 2rem;
  }

  .logo {
    font-size: 1.75rem;
  }

  .main {
    padding: 2rem 1.5rem;
    gap: 2rem;
  }

  .card-area {
    min-height: 440px;
  }

  .card-outer {
    max-width: 420px;
    padding: 12px;
  }

  .card-inner {
    padding: 3rem 2rem;
  }

  .card-question {
    font-size: clamp(1.4rem, 3.5vw, 1.9rem);
  }

  .btn-primary {
    max-width: 420px;
    padding: 1.1rem 2.5rem;
    font-size: 1.1rem;
  }

  .actions {
    max-width: 420px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  .main {
    padding: 2.5rem 2rem;
  }

  .card-area {
    min-height: 480px;
  }

  .card-outer {
    max-width: 440px;
  }
}
