/* ============================================================
   STUDYABLE  —  blocky, friendly, no-nonsense theme.
   System fonts, solid blocks, chunky borders, soft shadows.
   ============================================================ */

:root {
  --bg: #f3f1ea;          /* warm paper */
  --panel: #ffffff;
  --ink: #1f2430;         /* near-black text */
  --muted: #6b7280;
  --line: #1f2430;        /* chunky outlines */
  --accent: #3b6ea5;      /* friendly blue */
  --accent-2: #e8b500;    /* warm yellow */
  --good: #2f9e54;
  --bad: #d1495b;
  --shadow: 4px 4px 0 var(--line);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
}

button { font-family: var(--font); cursor: pointer; }
a { color: var(--accent); }

/* ---------- generic block ---------- */
.block {
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  background: var(--accent);
  color: #fff;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  font-weight: 700;
  font-size: 15px;
  transition: transform .04s ease;
}
.btn:hover { transform: translate(1px, 1px); box-shadow: 3px 3px 0 var(--line); }
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--line); }
.btn.secondary { background: #fff; color: var(--ink); }
.btn.yellow { background: var(--accent-2); color: var(--ink); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }

/* ============================================================
   LOGIN GATE
   ============================================================ */
#gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#gate .card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
  text-align: center;
}
#gate .logo {
  font-size: 44px;
  margin-bottom: 6px;
}
#gate h1 { margin: 0 0 4px; font-size: 26px; }
#gate p { color: var(--muted); margin: 0 0 20px; }
#gate input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-family: var(--font);
}
#gate .btn { width: 100%; }
#gate .err {
  color: var(--bad);
  font-weight: 700;
  min-height: 20px;
  margin-bottom: 10px;
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app { display: none; }
#app.show { display: block; }
#gate.hide { display: none; }

header.topbar {
  background: var(--accent);
  color: #fff;
  border-bottom: 4px solid var(--line);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
header.topbar .brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
header.topbar .spacer { flex: 1; }
header.topbar .pill {
  background: #fff;
  color: var(--ink);
  border: 3px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
}

.layout {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 18px;
}

.hero {
  margin-bottom: 22px;
}
.hero h2 { margin: 0 0 4px; font-size: 24px; }
.hero p { margin: 0; color: var(--muted); }

/* ---------- mode grid ---------- */
.group-title {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  font-weight: 800;
  margin: 26px 0 12px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}
.mode-card {
  padding: 16px;
  text-align: left;
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: transform .05s ease;
}
.mode-card:hover { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--line); }
.mode-card .ico { font-size: 28px; }
.mode-card .name { font-weight: 800; font-size: 17px; margin-top: 6px; }
.mode-card .desc { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

/* ============================================================
   WORKSPACE (a chosen mode)
   ============================================================ */
.workspace { display: none; }
.workspace.show { display: block; }

.ws-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.ws-head .back {
  background: #fff;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 12px;
  font-weight: 800;
}
.ws-head .ico { font-size: 30px; }
.ws-head h2 { margin: 0; font-size: 24px; }
.ws-head .blurb { color: var(--muted); font-size: 14px; }

.panel {
  padding: 18px;
  margin-bottom: 18px;
}
.panel label {
  display: block;
  font-weight: 800;
  margin-bottom: 8px;
  font-size: 14px;
}
textarea, select, input.text {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font);
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 150px; resize: vertical; }

.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-top: 12px;
}
.row .field { flex: 1; min-width: 140px; }
.row .field.small { flex: 0 0 130px; }

.dropzone {
  border: 3px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  color: var(--muted);
  background: #faf9f4;
  margin-top: 12px;
  font-size: 14px;
}
.dropzone.drag { background: #fff8d9; }
.filechip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-2);
  border: 3px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 700;
  font-size: 13px;
  margin-top: 10px;
}
.filechip button {
  border: none;
  background: transparent;
  font-weight: 800;
  cursor: pointer;
  font-size: 15px;
}

.run-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.webtoggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 14px;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
}
.webtoggle input { width: 18px; height: 18px; cursor: pointer; }

/* sources list under a web-powered result */
.sources {
  margin-top: 16px;
  border-top: 3px solid var(--line);
  padding-top: 12px;
}
.sources .sources-title {
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 8px;
}
.sources a {
  display: block;
  padding: 6px 10px;
  margin-bottom: 6px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #faf9f4;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  word-break: break-word;
}
.sources a:hover { background: #fff8d9; }
.sources a .src-host { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---------- result area ---------- */
.result {
  padding: 22px;
}
.result .result-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.tag {
  background: #eef2f7;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
}
.tag.model { background: #e3eefb; }
.tag.effort { background: #fdf3cf; }

.rendered h2 { font-size: 20px; border-bottom: 3px solid var(--line); padding-bottom: 4px; }
.rendered h3 { font-size: 17px; }
.rendered table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}
.rendered th, .rendered td {
  border: 2px solid var(--line);
  padding: 8px 10px;
  text-align: left;
}
.rendered th { background: #eef2f7; }
.rendered blockquote {
  border-left: 5px solid var(--accent-2);
  margin: 12px 0;
  padding: 4px 14px;
  background: #fffdf3;
}
.rendered code {
  background: #eef0f3;
  padding: 1px 5px;
  border-radius: 5px;
  font-family: "Consolas", "SF Mono", monospace;
}
.rendered ul, .rendered ol { padding-left: 22px; }
.rendered a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  word-break: break-word;
}
.rendered a:hover { background: #fff8d9; }
.rendered svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 14px auto;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
}

/* ============================================================
   FOLLOW-UP CHAT THREAD (under a result)
   ============================================================ */
.chat-thread { margin-top: 20px; border-top: 3px solid var(--line); padding-top: 16px; }
.chat-thread .chat-title {
  font-weight: 800;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 12px;
}
.bubble {
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  max-width: 92%;
}
.bubble.user {
  background: var(--accent);
  color: #fff;
  margin-left: auto;
  font-weight: 600;
}
.bubble.ai { background: #fff; }
.bubble .who {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .5px;
  opacity: .7;
  margin-bottom: 4px;
}
.followup-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 6px;
}
.followup-row textarea {
  min-height: 52px;
  flex: 1;
}
.followup-row .btn { white-space: nowrap; }

/* ---------- spinner ---------- */
.thinking {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  color: var(--muted);
}
.spinner {
  width: 22px; height: 22px;
  border: 4px solid #d9d6cc;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   QUIZ
   ============================================================ */
.quiz-q {
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  background: #fff;
}
.quiz-q .qtext { font-weight: 800; margin-bottom: 12px; }
.choice {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  margin-bottom: 8px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: 15px;
  font-weight: 600;
}
.choice:hover { background: #f0f4f9; }
.choice.correct { background: #d9f2e3; }
.choice.wrong { background: #f9dde1; }
.choice.picked { outline: 3px solid var(--accent); }
.explain {
  margin-top: 8px;
  font-size: 14px;
  color: var(--ink);
  background: #fffdf3;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  display: none;
}
.explain.show { display: block; }
.quiz-score {
  font-size: 20px;
  font-weight: 800;
  padding: 14px;
  text-align: center;
  background: var(--accent-2);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

/* ============================================================
   FLASHCARDS
   ============================================================ */
.cards-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.flip {
  perspective: 1000px;
  height: 160px;
  cursor: pointer;
}
.flip-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform .4s;
  transform-style: preserve-3d;
}
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  overflow: auto;
}
.flip-front { background: #fff; }
.flip-back { background: var(--accent-2); transform: rotateY(180deg); }
.flip .hint { position: absolute; bottom: 6px; right: 10px; font-size: 11px; color: var(--muted); font-weight: 600; }

/* ---------- result toolbar ---------- */
.result-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.toast {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 700;
  box-shadow: var(--shadow);
  display: none;
  z-index: 50;
}
.toast.show { display: block; }

/* ============================================================
   ANALYTICS
   ============================================================ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card {
  padding: 16px;
  text-align: center;
}
.stat-card .num { font-size: 32px; font-weight: 800; line-height: 1.1; }
.stat-card .lbl { color: var(--muted); font-weight: 700; font-size: 13px; margin-top: 4px; }
.stat-card.good .num { color: var(--good); }
.stat-card.bad .num { color: var(--bad); }
.stat-card.blue .num { color: var(--accent); }

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin: 18px 0;
}
@media (max-width: 720px) { .analytics-grid { grid-template-columns: 1fr; } }

/* vertical day bars */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 140px;
  margin-top: 8px;
  padding-top: 6px;
}
.bars .bar {
  flex: 1;
  background: var(--accent);
  border: 2px solid var(--line);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  position: relative;
}
.bars .bar:hover { background: var(--accent-2); }
.bars .bar .tip {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  margin-bottom: 4px;
  z-index: 5;
}
.bars .bar:hover .tip { display: block; }

/* horizontal labelled bars */
.hbars { margin-top: 8px; }
.hbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.hbar .name { flex: 0 0 130px; font-size: 13px; font-weight: 700; text-align: right; }
.hbar .track { flex: 1; background: #eef0f3; border: 2px solid var(--line); border-radius: 6px; height: 22px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-right: 2px solid var(--line); }
.hbar .val { flex: 0 0 36px; font-weight: 800; font-size: 13px; }
.hbar.alt .fill { background: var(--accent-2); }

.recent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 2px solid #eee;
  font-size: 14px;
}
.recent-item:last-child { border-bottom: none; }
.recent-item .dot { font-size: 12px; }
.recent-item .when { color: var(--muted); margin-left: auto; font-size: 12px; }
.empty-note { color: var(--muted); font-style: italic; padding: 8px 0; }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  header.topbar .brand { font-size: 18px; }
  header.topbar .btn { padding: 5px 8px !important; font-size: 12px; }
}
