:root {
  --bg: #0f1420;
  --panel: #1a2133;
  --panel-2: #222b42;
  --text: #eef1f8;
  --muted: #9aa5bd;
  --accent: #5b8cff;
  --good: #3ecf8e;
  --bad: #ff6b6b;
  --border: #2d3752;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

/* ---------------------------------------------------------- layout: mobile first ---- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.topbar .brand {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.25;
}
.topbar nav { display: flex; gap: 14px; flex-shrink: 0; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.topbar nav a:hover { color: var(--text); }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

h1 { margin-top: 0; font-size: 1.4rem; }

.back-link {
  color: var(--accent);
  text-decoration: none;
  display: inline-block;
  margin-bottom: 8px;
  padding: 6px 0;
}

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

/* ---- deck list ---- */
.deck-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.deck-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.deck-card:active { border-color: var(--accent); }
.deck-card h2 { margin: 0; font-size: 1.05rem; }
.deck-card span { color: var(--muted); font-size: 0.9rem; }

/* ---- study page ---- */
.study-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}
.study-controls { display: flex; gap: 8px; }
.study-controls button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 40px;
  cursor: pointer;
  font-size: 0.85rem;
}
.study-controls button:active { border-color: var(--accent); }

.card-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.flashcard {
  width: 100%;
  max-width: 560px;
  height: 260px;
  perspective: 1200px;
  cursor: pointer;
  touch-action: manipulation;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, var(--panel), var(--panel-2));
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  font-size: 1.1rem;
  line-height: 1.5;
  overflow-y: auto;
}
.flashcard-face.back { transform: rotateY(180deg); color: #cfe7ff; }
.flashcard-face .hint {
  position: absolute;
  bottom: 10px;
  font-size: 0.72rem;
  color: var(--muted);
}

.card-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  max-width: 560px;
}

.nav-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 52px;
  height: 52px;
  min-width: 52px;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-btn:active { border-color: var(--accent); }

.know-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
  width: 100%;
}
.know-btn {
  border: none;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  color: #0b1020;
  font-weight: 600;
  flex: 1;
  min-height: 48px;
}
.know-btn.know { background: var(--good); }
.know-btn.dont { background: var(--bad); }

.score { text-align: center; color: var(--muted); margin-top: 14px; font-size: 0.9rem; }

/* ---- admin ---- */
.admin-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }

.stat-card {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 14px 0;
}
.stat-number { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--muted); font-size: 0.9rem; }
.logout-link { color: var(--muted); padding: 6px 0; }
.admin-section, .admin-deck {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}
.admin-deck-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input[type=text] {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px; min-width: 0; flex: 1; font-size: 1rem;
}

button, .inline-form button {
  background: var(--accent); color: #0b1020; border: none; border-radius: 8px;
  padding: 10px 14px; cursor: pointer; font-weight: 600; min-height: 40px; font-size: 0.95rem;
}
button.danger { background: var(--bad); }

/* card list (mobile-first: stacked cards instead of a table) */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.admin-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--panel-2);
}
.admin-card label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 6px 0 4px;
}
.admin-card label:first-child { margin-top: 0; }
.admin-card textarea {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
  font-size: 0.95rem;
  font-family: inherit;
}
.admin-card .row-actions { display: flex; gap: 8px; margin-top: 10px; }
.admin-card .row-actions button { flex: 1; }

.new-card-block { border: 2px dashed var(--border); background: transparent; }

.list-head { display: none; }

.login-form { display: flex; flex-direction: column; gap: 12px; max-width: 320px; }
.login-form input { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 1rem; }
.error { color: var(--bad); }

/* ---------------------------------------------------------- tablet and up ---- */
@media (min-width: 640px) {
  main { padding: 24px 20px 60px; }
  h1 { font-size: 1.8rem; }

  .deck-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
  .deck-card:hover { border-color: var(--accent); transform: translateY(-2px); }
  .deck-card { transition: transform .1s ease, border-color .1s ease; }

  .flashcard { height: 320px; }
  .flashcard-face { font-size: 1.3rem; padding: 28px; }

  .know-bar { max-width: 400px; margin-left: auto; margin-right: auto; }
  .know-btn { flex: initial; padding: 12px 22px; }

  .admin-deck-head { flex-direction: row; justify-content: space-between; align-items: center; }

  /* promote the stacked cards into a real table */
  .card-list { display: table; width: 100%; border-collapse: collapse; }
  .admin-card {
    display: table-row;
    background: none;
    border: none;
    border-radius: 0;
  }
  .admin-card.new-card-block { display: table-row; }
  .admin-card > div { display: table-cell; padding: 8px; border-top: 1px solid var(--border); vertical-align: top; }
  .admin-card label { display: none; }
  .admin-card .row-actions { display: table-cell; border-top: 1px solid var(--border); white-space: nowrap; vertical-align: top; margin-top: 0; }
  .admin-card .row-actions button { flex: initial; }
  .list-head { display: table-row; }
  .list-head > div { display: table-cell; color: var(--muted); font-size: 0.85rem; padding: 0 8px 6px; }
}

@media (min-width: 900px) {
  .topbar { padding: 14px 20px; }
}
