:root {
  --bg:        #1a1a1a;
  --surface:   #242424;
  --border:    #333;
  --text:      #f0e6d3;
  --muted:     #888;
  --accent:    #c8a96a;
  --correct:   #4caf7a;
  --incorrect: #e05252;
  --btn-h:     52px;
  --nav-h:     56px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-t:    env(safe-area-inset-top, 0px);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}

/* ---- Screens ---- */

.screen {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(24px, var(--safe-t)) 20px 24px;
}

.screen.active { display: block; }

#screen-setup {
  bottom: 0;
}
#screen-setup.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

/* ---- Bottom Nav ---- */

#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  z-index: 100;
}
#bottom-nav.hidden { display: none; }

.nav-btn {
  flex: 1;
  height: var(--nav-h);
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s;
  letter-spacing: 0.01em;
}
.nav-btn.active { color: var(--accent); }

/* ---- Setup ---- */

.setup-container {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.setup-container h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 36px;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: normal;
  letter-spacing: 0.05em;
}

.setup-sub {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 15px;
}

#setup-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- Inputs & Buttons ---- */

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 17px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent); }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-appearance: none;
}
button:active { transform: scale(0.97); opacity: 0.82; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

#setup-form button {
  width: 100%;
  height: var(--btn-h);
  background: var(--accent);
  color: #1a1a1a;
}

/* ---- Review ---- */

.review-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100%;
}

.queue-info {
  text-align: right;
  color: var(--muted);
  font-size: 13px;
  min-height: 18px;
}

.prompt {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 26px;
  font-weight: normal;
  color: var(--text);
  line-height: 1.4;
  text-align: center;
  padding: 20px 0 6px;
  min-height: 80px;
}

.deck-badge {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  min-height: 14px;
}

#answer-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#submit-btn {
  width: 100%;
  height: var(--btn-h);
  background: var(--accent);
  color: #1a1a1a;
}

/* ---- Result ---- */

.result-label {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  padding: 6px 0;
}
.result-label.correct   { color: var(--correct); }
.result-label.incorrect { color: var(--incorrect); }

.result-answer {
  text-align: center;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 22px;
  padding: 8px 0 18px;
  line-height: 1.5;
}

.alt-answers {
  color: var(--muted);
  font-size: 17px;
}

.grade-buttons {
  display: flex;
  gap: 10px;
}

.grade-btn {
  flex: 1;
  height: var(--btn-h);
  font-size: 15px;
}
.grade-wrong { background: rgba(224,82,82,0.12);  color: var(--incorrect); border: 1px solid rgba(224,82,82,0.4); }
.grade-hard  { background: rgba(200,180,74,0.12); color: #c8b44a;          border: 1px solid rgba(200,180,74,0.4); }
.grade-good  { background: rgba(76,175,122,0.12); color: var(--correct);   border: 1px solid rgba(76,175,122,0.4); }

/* ---- Center messages (empty / offline / loading) ---- */

.center-msg {
  text-align: center;
  padding: 60px 0 32px;
  flex: 1;
}
.center-msg-icon {
  font-size: 48px;
  color: var(--muted);
  margin-bottom: 12px;
}
.center-msg p {
  font-size: 20px;
  margin-bottom: 6px;
}
.center-msg .sub {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 24px;
}
.center-msg button {
  padding: 13px 32px;
  background: var(--accent);
  color: #1a1a1a;
}

/* ---- Decks ---- */

#screen-decks h2,
#screen-stats h2,
#screen-import h2 {
  font-family: Georgia, serif;
  font-size: 22px;
  color: var(--accent);
  font-weight: normal;
  margin-bottom: 18px;
}

#decks-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.deck-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: var(--surface);
  border-radius: 9px;
  transition: opacity 0.2s;
}
.deck-row.inactive { opacity: 0.4; }

.deck-name { font-size: 15px; font-weight: 500; }
.deck-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #ccc;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: #fff; }

/* ---- Stats ---- */

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}
.stat-value {
  font-size: 38px;
  font-weight: 700;
  color: var(--accent);
  font-family: Georgia, serif;
  line-height: 1;
}
.stat-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#screen-stats h3 {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.deck-stats {
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
}
.deck-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.deck-stat-row:last-child { border-bottom: none; }
.deck-stat-nums { color: var(--muted); font-variant-numeric: tabular-nums; }
.deck-stats-legend {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  margin-top: 6px;
}

/* ---- Import ---- */

.import-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.file-label {
  display: block;
  padding: 22px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 15px;
  transition: border-color 0.15s, color 0.15s;
}
.file-label:hover, .file-label:active { border-color: var(--accent); color: var(--accent); }
.file-label input { display: none; }

#import-preview {
  background: var(--surface);
  border-radius: 10px;
  padding: 16px;
}
#import-preview p { margin-bottom: 10px; font-size: 15px; }

.import-deck-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
}
.import-deck-row:last-child { border-bottom: none; }

#import-confirm {
  width: 100%;
  height: var(--btn-h);
  background: var(--accent);
  color: #1a1a1a;
}

.import-status {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  min-height: 20px;
}

/* ---- Utilities ---- */

.hidden  { display: none !important; }
.error   { color: var(--incorrect); font-size: 14px; margin-top: 6px; }
.loading { color: var(--muted); text-align: center; padding: 20px 0; }
