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

:root {
  --rust: #CE422B;
  --rust-dark: #a33520;
  --bg: #1a1a1a;
  --surface: #252525;
  --surface2: #2e2e2e;
  --text: #f0f0f0;
  --text-muted: #888;
  --radius: 16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

/* Header */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid #333;
  flex-shrink: 0;
}
header h1 { font-size: 1.1rem; font-weight: 700; color: var(--rust); letter-spacing: .02em; }
#category-label { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }

/* Progress */
#progress-bar-wrap {
  height: 4px; background: #333; flex-shrink: 0;
}
#progress-bar { height: 100%; background: var(--rust); transition: width .3s ease; width: 0%; }

#counter {
  text-align: center; padding: 8px 0 4px;
  font-size: .8rem; color: var(--text-muted); flex-shrink: 0;
}

/* Filter tabs */
#filter-bar {
  display: flex; gap: 8px; padding: 8px 20px;
  flex-shrink: 0; overflow-x: auto;
  scrollbar-width: none;
}
#filter-bar::-webkit-scrollbar { display: none; }
.filter-btn {
  padding: 6px 14px; border-radius: 20px; border: 1.5px solid #444;
  background: transparent; color: var(--text-muted); font-size: .8rem;
  cursor: pointer; white-space: nowrap; transition: all .15s;
  -webkit-appearance: none;
}
.filter-btn.active { border-color: var(--rust); color: var(--rust); background: rgba(206,66,43,.12); }

/* Card area */
#card-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 16px 20px;
  perspective: 1000px;
  overflow: hidden;
}

.card-wrap {
  width: 100%; max-width: 480px;
  height: min(360px, 55vw + 120px);
  position: relative;
  transition: transform .55s cubic-bezier(.4,0,.2,1);
  transform-style: preserve-3d;
  cursor: pointer;
}
.card-wrap.flipped { transform: rotateY(180deg); }
.card-wrap.swipe-left  { transform: translateX(-110vw) rotate(-15deg); opacity: 0; transition: transform .35s ease-in, opacity .3s ease-in; }
.card-wrap.swipe-right { transform: translateX(110vw)  rotate(15deg);  opacity: 0; transition: transform .35s ease-in, opacity .3s ease-in; }

.card-face {
  position: absolute; inset: 0;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1.5px solid #333;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 24px; text-align: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.card-face.back { transform: rotateY(180deg); background: var(--surface2); border-color: var(--rust); }

.card-face .hint {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-muted); margin-bottom: 14px;
}
.card-face .body {
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  line-height: 1.55;
  white-space: pre-line;
}
.card-face.back .body { font-size: clamp(.9rem, 3vw, 1.1rem); text-align: left; }

/* Empty state */
#empty-state {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: var(--text-muted); text-align: center; padding: 40px;
}
#empty-state.visible { display: flex; }
#empty-state p { font-size: 1.1rem; }
#empty-state small { font-size: .85rem; }

/* Action buttons */
#actions {
  display: flex; gap: 12px; padding: 12px 20px 20px;
  justify-content: center; flex-shrink: 0;
}
.action-btn {
  flex: 1; max-width: 160px;
  padding: 14px 10px; border-radius: var(--radius);
  font-size: .95rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: transform .1s, opacity .1s;
  -webkit-appearance: none;
}
.action-btn:active { transform: scale(.96); }
#btn-again { background: var(--surface2); color: var(--text); }
#btn-got-it { background: var(--rust); color: #fff; }
#btn-again:disabled, #btn-got-it:disabled { opacity: .35; cursor: default; }

/* Toolbar */
#toolbar {
  display: flex; gap: 10px; padding: 0 20px 16px;
  justify-content: center; flex-shrink: 0;
}
.tool-btn {
  padding: 10px 20px; border-radius: 10px;
  background: var(--surface); color: var(--text-muted);
  border: 1.5px solid #333; font-size: .8rem; cursor: pointer;
  transition: color .15s, border-color .15s;
  -webkit-appearance: none;
}
.tool-btn:active { color: var(--text); border-color: #555; }

/* Toast */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #333; color: var(--text); padding: 10px 20px; border-radius: 24px;
  font-size: .85rem; opacity: 0; transition: all .25s; pointer-events: none;
  white-space: nowrap; z-index: 99;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Install banner */
#install-banner {
  display: none; align-items: center; justify-content: space-between;
  background: var(--rust); color: #fff; padding: 10px 20px;
  font-size: .85rem; flex-shrink: 0; gap: 12px;
}
#install-banner.visible { display: flex; }
#install-banner button { background: rgba(255,255,255,.25); border: none; color: #fff; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-size: .8rem; }
