:root {
  --bg: #1b1730;
  --card: #2a2450;
  --accent: #7c5cd6;
  --accent2: #c084fc;
  --text: #f2eefc;
  --sub: #b6aed6;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  background: linear-gradient(160deg, #1b1730, #241d45);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 20px 20px 14px;
  text-align: center;
}
.app-header h1 { margin: 0; font-size: 1.3rem; }
.tagline { margin: 4px 0 0; color: var(--sub); font-size: 0.85rem; }

#screens {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 90px;
}

.screen { display: none; }
.screen.active { display: block; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}

.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 99px;
  overflow: hidden;
  margin: 10px 0;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}

.group-label { font-size: 0.75rem; color: var(--sub); }
.category-label {
  display: inline-block;
  background: rgba(124,92,214,0.25);
  color: var(--accent2);
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  margin-bottom: 10px;
}

.question-text { font-size: 1.05rem; line-height: 1.5; margin: 8px 0 14px; }

textarea, input[type=text] {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  padding: 12px;
  font-size: 1rem;
  resize: vertical;
  font-family: inherit;
}
textarea { min-height: 100px; }

button {
  font-family: inherit;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s;
}
button:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  color: white;
  width: 100%;
  margin-top: 10px;
  font-weight: bold;
}
.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: var(--text);
  width: 100%;
  margin-top: 8px;
}
.btn-ai {
  background: rgba(192,132,252,0.18);
  color: var(--accent2);
  width: 100%;
  margin-top: 8px;
  border: 1px dashed var(--accent2);
}

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(20,16,40,0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 6px env(safe-area-inset-right) calc(6px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
}
.tab {
  flex: 1;
  background: transparent;
  color: var(--sub);
  padding: 10px 4px;
  font-size: 0.8rem;
}
.tab.active { color: var(--accent2); font-weight: bold; }

.qa-item { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.qa-q { font-size: 0.85rem; color: var(--sub); margin-bottom: 4px; }
.qa-a { font-size: 0.95rem; white-space: pre-wrap; }
.qa-edit-btn { font-size: 0.75rem; background: none; color: var(--accent2); padding: 4px 0; }

.category-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.category-row .count { font-size: 0.8rem; color: var(--sub); }

.script-text {
  white-space: pre-wrap;
  font-size: 0.9rem;
  line-height: 1.6;
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  padding: 12px;
  margin-top: 8px;
}

#toastwrap {
  position: fixed;
  top: 12px; left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 999;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 0.85rem;
  color: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.success { background: linear-gradient(90deg, #34c97b, #1f9d63); }
.toast.error { background: linear-gradient(90deg, #f87171, #dc2626); }

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1b1730, #241d45);
  padding: 20px;
}
.login-gate.hidden { display: none; }
.login-card { text-align: center; max-width: 340px; }
.login-card h1 { margin: 0 0 4px; }
.login-hint { color: var(--sub); font-size: 0.85rem; margin: 16px 0; }
#g_id_signin { display: flex; justify-content: center; }

.app-header, #screens, .tabbar { display: none; }
body.authed .app-header, body.authed #screens, body.authed .tabbar { display: block; }
body.authed .tabbar { display: flex; }

.empty-state { text-align: center; color: var(--sub); padding: 40px 20px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent2);
  border-radius: 50%;
  margin: 20px auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
