/* ========== Theme variables ========== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #1c2233;
  --muted: #6b7489;
  --primary: #4f6bed;
  --primary-2: #7c4dff;
  --know: #1fa971;
  --review: #f0a020;
  --border: #dde2ee;
  --shadow: 0 10px 30px rgba(30, 40, 80, 0.12);
  --radius: 20px;
}

[data-theme="dark"] {
  --bg: #0f1320;
  --surface: #1a2033;
  --surface-2: #232a40;
  --text: #e8ecf6;
  --muted: #98a1b8;
  --primary: #7b93ff;
  --primary-2: #a78bfa;
  --know: #34d399;
  --review: #fbbf24;
  --border: #2c3450;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

/* ========== Base ========== */
* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

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

.muted { color: var(--muted); }

/* ========== Top bar ========== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  max-width: 720px; margin: 0 auto;
}

.brand { font-size: 1.3rem; font-weight: 700; margin: 0; }
.brand span {
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 1.1rem; display: grid; place-items: center;
  transition: transform 0.2s, background 0.2s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Layout ========== */
.container {
  max-width: 720px; margin: 0 auto; padding: 0 20px 32px;
  display: flex; flex-direction: column; gap: 18px;
}

/* ========== Toolbar ========== */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.select-wrap select {
  appearance: none;
  padding: 9px 34px 9px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 0.9rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
}

.chip {
  padding: 9px 14px; border-radius: 999px; font-size: 0.9rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: all 0.2s;
}
.chip:hover { background: var(--surface-2); }
.chip-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-active:hover { background: var(--primary); }
.chip-ghost { margin-left: auto; background: transparent; color: var(--muted); }

/* ========== Progress ========== */
.progress-text {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px;
  font-size: 0.88rem; margin-bottom: 8px;
}
#counter { font-weight: 600; }

.progress-bar {
  height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  transition: width 0.35s ease;
}

/* ========== Status ========== */
.status {
  margin: 0; padding: 10px 14px; border-radius: 12px;
  background: var(--surface-2); color: var(--muted); font-size: 0.88rem; text-align: center;
}
.status[hidden] { display: none; }
.status-error { background: rgba(220, 60, 60, 0.12); color: #d64545; }

/* ========== Flash card ========== */
.card-area { perspective: 1400px; }

.card {
  position: relative; width: 100%; height: 340px;
  cursor: pointer; outline: none; user-select: none;
}
.card:focus-visible .card-face { box-shadow: 0 0 0 3px var(--primary), var(--shadow); }

.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
}
.card.is-flipped .card-inner { transform: rotateY(180deg); }
.card.is-switching .card-inner { transition: none; }

.card-face {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 28px; text-align: center;
  border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}

.card-front {
  background: linear-gradient(145deg, var(--primary), var(--primary-2));
  border: none; color: #fff;
}
.card-back { transform: rotateY(180deg); }

.card-label {
  position: absolute; top: 18px; left: 22px;
  font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.75;
}

.card-hint {
  position: absolute; bottom: 16px; font-size: 0.78rem; opacity: 0.6;
}

.card-text {
  margin: 0; font-size: clamp(1.6rem, 5vw, 2.3rem); font-weight: 700; line-height: 1.25;
  word-break: break-word;
}
.card-text-sm { font-size: clamp(1.15rem, 3.6vw, 1.5rem); font-weight: 500; line-height: 1.5; }

.card.is-empty .card-front { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.card.is-empty .card-hint { display: none; }

.badge {
  position: absolute; top: 16px; right: 18px;
  font-size: 0.75rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.22); color: #fff;
}
.badge[hidden] { display: none; }
.badge-known { background: var(--know); }
.badge-review { background: var(--review); color: #1c2233; }

/* ========== Buttons ========== */
.mark-actions, .nav-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}

.btn {
  padding: 14px 16px; border-radius: 14px; border: none;
  font-weight: 600; font-size: 1rem;
  transition: transform 0.12s, filter 0.2s, background 0.2s;
}
.btn:not(:disabled):active { transform: scale(0.97); }
.btn:not(:disabled):hover { filter: brightness(1.06); }

.btn-know { background: var(--know); color: #fff; }
.btn-review { background: var(--review); color: #1c2233; }
.btn-nav {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.btn-nav:not(:disabled):hover { background: var(--surface-2); filter: none; }

/* ========== Shortcuts ========== */
.shortcuts { text-align: center; font-size: 0.8rem; margin: 4px 0 0; }
kbd {
  font-family: inherit; font-size: 0.75rem; padding: 2px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface);
}

/* ========== Responsive ========== */
@media (max-width: 520px) {
  .card { height: 300px; }
  .shortcuts { display: none; }
  .chip-ghost { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner, .progress-fill { transition: none; }
}
