/* Midsentence — a Polish exercise notebook. Warm paper, ink, one quiet accent. */

:root {
  --bg: #F7F3EB;
  --surface: #FFFDF8;
  --ink: #2B2622;
  --ink-muted: #6E655C;
  --line: #E4DCCD;
  --accent: #2F6B4F;
  --rule: rgba(47, 107, 79, 0.28);          /* ruled baseline under phrases */
  --accent-soft: rgba(47, 107, 79, 0.08);
  --danger: #9C3B2E;

  --chip-grammar-bg: #EFE9FA; --chip-grammar-fg: #4A3C7A;
  --chip-vocab-bg:   #E4F0E8; --chip-vocab-fg:   #2F6B4F;
  --chip-phrases-bg: #F6E8DE; --chip-phrases-fg: #8A4B2D;

  /* Shared with the landing page: one grid, one set of font metrics. */
  --cell:     26px;
  --measure:  1180px;
  --desk:     #EAE3D5;
  --margines: #C9877A;
  --margines-soft: rgba(201, 135, 122, 0.55);
  --kratka:   rgba(43, 38, 34, 0.07);
  --hole-rim: rgba(43, 38, 34, 0.14);
  --k-serif:  0.869;   /* Literata     (ascent + descent), from font metrics */
  --k-sans:   0.624;   /* Source Sans 3 */

  --serif: 'Literata', Georgia, serif;
  --sans: 'Source Sans 3', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

[data-theme="dark"] {
  --desk: #131110;
  --margines: #8E5C52;
  --margines-soft: rgba(142, 92, 82, 0.55);
  --kratka: rgba(237, 231, 220, 0.06);
  --hole-rim: rgba(0, 0, 0, 0.5);
  --bg: #1E1B17;
  --surface: #262220;
  --ink: #EDE7DC;
  --ink-muted: #A89E91;
  --line: #3A342E;
  --accent: #7FB89A;
  --rule: rgba(127, 184, 154, 0.30);
  --accent-soft: rgba(127, 184, 154, 0.10);
  --danger: #D08070;

  --chip-grammar-bg: #3B3260; --chip-grammar-fg: #CFC4F0;
  --chip-vocab-bg:   #28453A; --chip-vocab-fg:   #A9D8BE;
  --chip-phrases-bg: #4A3526; --chip-phrases-fg: #E9C5A8;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px 48px;
}

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.serif { font-family: var(--serif); font-weight: 500; }
.muted { color: var(--ink-muted); }

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0.05em 0.35em;
}

/* ---------- top bar ---------- */

.topbar {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.wordmark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink-muted);
  text-decoration: none;
}

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

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink-muted);
  font-size: 0.95rem;
  width: 34px;
  height: 30px;
  cursor: pointer;
  line-height: 1;
  text-decoration: none;
}

/* ---------- settings ---------- */

.settings-form label {
  display: block;
  font-weight: 500;
  margin-bottom: 14px;
}

.settings-form select {
  display: block;
  width: 100%;
  max-width: 280px;
  margin-top: 6px;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}

.settings-note { font-size: 0.9rem; margin: -4px 0 18px; }

/* ---------- headings & sections ---------- */

.greeting {
  font-size: 1.6rem;
  font-weight: 400;
  margin: 20px 0 24px;
}

section { margin-top: 32px; }

h1 { font-size: 1.35rem; font-weight: 600; }

h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin: 0 0 12px;
}

.empty {
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin: 8px 0;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-block;
  font: 500 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 18px;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFDF8;
}

[data-theme="dark"] .btn-primary { color: #1E1B17; }

.btn-danger {
  background: none;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-block { display: block; width: 100%; }

.quiet-action {
  background: none;
  border: none;
  padding: 0;
  font: 500 0.85rem var(--sans);
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.icon-link {
  color: var(--ink-muted);
  text-decoration: none;
  font-size: 1rem;
  padding: 6px 8px;
  border-radius: 8px;
}

.inline-form { display: inline; }

/* ---------- rehearsal & field capture ---------- */

.scenario-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.scenario-row form { display: contents; }

.nudge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border-radius: 10px;
  font-size: 0.95rem;
}

.capture-form { display: flex; gap: 8px; }

.capture-form input {
  flex: 1;
  min-width: 0;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
}

.capture-list {
  list-style: none;
  margin: 12px 0 8px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.capture-list li { padding: 8px 16px; font-size: 0.95rem; }

.capture-list li + li { border-top: 1px solid var(--line); }

/* ---------- sessions list ---------- */

.session-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.session-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 10px 16px;
}

.session-row + .session-row { border-top: 1px solid var(--line); }

.session-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--ink);
}

.session-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta { font-size: 0.82rem; color: var(--ink-muted); }

.session-actions { display: flex; flex-shrink: 0; }

/* ---------- learn grid ---------- */

.learn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.learn-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  text-decoration: none;
}

.learn-name { font-weight: 600; color: var(--ink); }
.learn-count { font-size: 0.82rem; color: var(--ink-muted); }

/* ---------- the card (signature element) ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}

.card-list { display: flex; flex-direction: column; gap: 12px; }

.card-phrase {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.2rem;
  line-height: 1.4;
  margin: 0 0 0;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--rule);   /* the ruled baseline */
}

.card-trans { margin: 0.55rem 0 0; }

.card-note {
  margin: 0.15rem 0 0;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 0.7rem;
}

.card-accent {
  border-left: 2px solid var(--accent);
  border-radius: 10px;
}

/* chips */

.chip {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 99px;
  white-space: nowrap;
}

.chip-grammar { background: var(--chip-grammar-bg); color: var(--chip-grammar-fg); }
.chip-vocab   { background: var(--chip-vocab-bg);   color: var(--chip-vocab-fg); }
.chip-phrases { background: var(--chip-phrases-bg); color: var(--chip-phrases-fg); }

/* "…" menu */

.menu { position: relative; margin-left: auto; }

.menu summary {
  list-style: none;
  cursor: pointer;
  color: var(--ink-muted);
  padding: 0 8px;
  border-radius: 8px;
  font-weight: 600;
}

.menu summary::-webkit-details-marker { display: none; }

.menu-pop {
  position: absolute;
  right: 0;
  top: 1.6rem;
  z-index: 5;
  display: flex;
  flex-direction: column;
  min-width: 110px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.menu-pop a, .menu-pop button {
  font: 400 0.92rem var(--sans);
  text-align: left;
  text-decoration: none;
  color: var(--ink);
  background: none;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  width: 100%;
}

.menu-pop button { color: var(--danger); }
.menu-pop a:hover, .menu-pop button:hover { background: var(--accent-soft); }

/* card edit form */

.card-edit label {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-muted);
  margin-bottom: 10px;
}

.card-edit input, .card-edit select {
  display: block;
  width: 100%;
  margin-top: 2px;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}

.edit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.edit-actions { display: flex; gap: 10px; margin-top: 4px; }

/* ---------- cards page ---------- */

.page-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 14px 0 18px;
}

.page-head h1 { margin: 0; }
.page-head .back { margin-left: -8px; }

.search-form { display: flex; gap: 8px; margin-bottom: 14px; }

.search-form input[type="search"] {
  flex: 1;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
}

.chips-row { display: flex; gap: 8px; flex-wrap: wrap; }

.filter-chip {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-muted);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 13px;
  background: var(--surface);
  cursor: pointer;
}

.filter-chip.active {
  color: var(--accent);
  border-color: var(--accent);
}

.result-count {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin: 14px 0 10px;
}

/* ---------- grammar rules ---------- */

.rule-list { display: flex; flex-direction: column; gap: 12px; }

.rule {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.rule-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--ink);
}

.rule-name {
  flex: 1;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.05rem;
}

.rule-count { font-size: 0.82rem; color: var(--ink-muted); }
.chevron { color: var(--ink-muted); font-size: 0.8rem; }

.rule-body {
  border-top: 1px solid var(--line);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rule-summary {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.93rem;
}

.show-all { align-self: flex-start; }

/* ---------- chat ---------- */

/* App-style layout: the page never scrolls, only #chat does. */
.chat-page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-page .topbar { flex-shrink: 0; width: 100%; }

.chat-page .container {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.chat-head-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.chat-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-meta { font-size: 0.8rem; color: var(--ink-muted); }

#chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

#chat::-webkit-scrollbar { width: 8px; }
#chat::-webkit-scrollbar-track { background: transparent; }
#chat::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 14px 30px 2px;
}

.msg { max-width: 86%; }

.msg-user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-radius: 12px 12px 4px 12px;
  padding: 9px 14px;
}

.msg-tutor {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px 12px 12px 4px;
  padding: 11px 15px;
}

.msg-tutor .pl {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.06em;
}

.msg-actions {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

.save-confirm {
  font-size: 0.82rem;
  color: var(--accent);
  margin-top: 6px;
  animation: fade-in 0.35s ease-out;
}

.save-fail { color: var(--danger); }

.chat-error {
  align-self: center;
  font-size: 0.9rem;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 7px 14px;
}

.chat-empty { text-align: center; margin-top: 40px; }

/* typing indicator */

.typing { display: flex; gap: 5px; padding: 14px 16px; }

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-muted);
  animation: blink 1.2s infinite both;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* messages dissolve into the paper above the composer — no hard clip line */

.chat-fade {
  flex-shrink: 0;
  height: 32px;
  margin-top: -32px;
  position: relative;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--bg));
}

/* composer — one quiet rounded surface, input and send inside */

#composer {
  position: relative;       /* anchors the floating Help pill */
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 calc(18px + env(safe-area-inset-bottom));
  padding: 6px 6px 6px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  transition: border-color 0.15s ease;
}

#composer:focus-within { border-color: var(--accent); }

#composer-input {
  flex: 1;
  min-width: 0;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: none;
  border: none;
  padding: 9px 0;
}

#composer-input:focus-visible { outline: none; }

#composer-input::placeholder { color: var(--ink-muted); opacity: 0.7; }

#composer .send-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #FFFDF8;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

[data-theme="dark"] #composer .send-btn { color: #1E1B17; }

#composer .send-btn:disabled { opacity: 0.45; cursor: default; }

/* ---------- glossary ---------- */

/* a notation the tutor used that the glossary can explain — tap to peek */
code.term {
  cursor: pointer;
  border-bottom: 1px dotted var(--accent);
  color: var(--accent);
}

#sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 34, 0.35);
  z-index: 40;
}

[data-theme="dark"] #sheet-backdrop { background: rgba(0, 0, 0, 0.5); }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-up 0.25s ease-out;
}

.sheet[hidden], #sheet-backdrop[hidden] { display: none; }

.sheet-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  justify-content: space-between;
}

#sheet-term { font-size: 1.15rem; }

#sheet-close {
  background: none;
  border: none;
  color: var(--ink-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 8px;
}

#sheet-body { margin: 10px 0 14px; }

#sheet-body .pl { font-family: var(--serif); font-weight: 500; }

@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ---------- live mode: help thread & notes ---------- */

.scenario-hint {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

/* the Help pill — floats above the composer's right corner, out of the layout
   flow so the fade can hug the input field */
.help-fab {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  z-index: 3;
  padding: 6px 16px;
  font: 600 0.88rem var(--sans);
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 99px;
  cursor: pointer;
}

#help-messages {
  max-height: 38vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.w-msg {
  max-width: 88%;
  font-size: 0.95rem;
  padding: 7px 12px;
  border-radius: 10px;
}

.w-user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-radius: 10px 10px 4px 10px;
}

.w-tutor {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px 10px 10px 4px;
}

.w-tutor .pl { font-family: var(--serif); font-weight: 500; }

.w-fail { color: var(--danger); border-color: var(--danger); }

.help-empty { margin: 4px 0; }

.help-quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }

#help-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

#help-form:focus-within { border-color: var(--accent); }

#help-input {
  flex: 1;
  min-width: 0;
  font: 400 0.95rem var(--sans);
  color: var(--ink);
  background: none;
  border: none;
  padding: 7px 0;
}

#help-input:focus-visible { outline: none; }

#help-form .send-btn { width: 32px; height: 32px; border-radius: 9px; font-size: 0.95rem; }

.msg-notes {
  border-left: 2px solid var(--accent);
  max-width: 100%;
}

.notes-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

/* glossary page */

.glossary-intro { margin: -6px 0 20px; font-size: 0.95rem; }

.glossary {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.glossary-entry { padding: 14px 18px; }

.glossary-entry + .glossary-entry { border-top: 1px solid var(--line); }

.glossary-entry dt { font-size: 1.05rem; }

.glossary-entry dd {
  margin: 4px 0 0;
  font-size: 0.95rem;
  color: var(--ink-muted);
}

.glossary-entry dd .pl {
  font-family: var(--serif);
  font-weight: 500;
  color: var(--ink);
}

.glossary-link { display: inline-block; margin-top: 12px; font-size: 0.9rem; }

.page-head-aside { margin-left: auto; font-size: 0.9rem; }

/* ---------- login & confirm ---------- */

.login-box, .confirm-box {
  max-width: 340px;
  margin: 14vh auto 0;
  text-align: center;
}

.login-box h1 { font-size: 2rem; margin-bottom: 0; }
.login-box p { margin-top: 4px; }

.login-box input[type="password"] {
  display: block;
  width: 100%;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 18px 0 12px;
  text-align: center;
}

.login-box input[type="email"] {
  display: block;
  width: 100%;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 18px 0 12px;
  text-align: center;
}

.code-input {
  display: block;
  width: 100%;
  font: 500 1.8rem var(--mono);
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 14px 0 12px;
  text-align: center;
}

.login-alt {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 16px;
}

.form-error { color: var(--danger); font-size: 0.9rem; }
.form-info { color: var(--accent); font-size: 0.9rem; }
.small { font-size: 0.88rem; }

/* settings */

.settings-form input,
.settings-form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  font: 400 1rem var(--sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  resize: vertical;
}

/* subscribe */

.subscribe-card { max-width: 420px; }
.subscribe-card .btn { margin: 14px 0 8px; }

.confirm-box { text-align: left; }

.confirm-actions { display: flex; gap: 10px; margin-top: 18px; }

/* ---------- motion & small screens ---------- */

@media (prefers-reduced-motion: reduce) {
  .typing span { animation: none; opacity: 0.6; }
  .save-confirm { animation: none; }
  .sheet { animation: none; }
}

@media (max-width: 420px) {
  .learn-grid { gap: 10px; }
  .msg { max-width: 94%; }
  .card-meta { gap: 10px; }
}

/* ===================== login: the page as a sheet ==========================
   Same system as the landing page. The sheet is painted by a fixed pseudo-
   element behind the content, because the topbar and <main> are siblings and
   there is no wrapper spanning both. Every vertical value is a whole number
   of cells; text baselines are seated with the font-metric correction; boxes
   are given whole-cell heights and let the grid place them.
   ========================================================================= */

body.login-page {
  background: var(--desk);
  min-height: 100svh;
}
body.login-page::before {
  content: "";
  position: fixed; inset: 0;
  width: 100%; max-width: var(--measure);
  margin: 0 auto;
  z-index: -1;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 23px 20%, var(--desk) 7.5px, var(--hole-rim) 8.4px, transparent 8.7px),
    radial-gradient(circle at 23px 32%, var(--desk) 7.5px, var(--hole-rim) 8.4px, transparent 8.7px),
    radial-gradient(circle at 23px 68%, var(--desk) 7.5px, var(--hole-rim) 8.4px, transparent 8.7px),
    radial-gradient(circle at 23px 80%, var(--desk) 7.5px, var(--hole-rim) 8.4px, transparent 8.7px),
    linear-gradient(90deg,
      transparent calc(var(--cell) * 2), var(--margines-soft) calc(var(--cell) * 2),
      var(--margines-soft) calc(var(--cell) * 2 + 1px), transparent calc(var(--cell) * 2 + 1px)),
    linear-gradient(var(--kratka) 1px, transparent 1px),
    linear-gradient(90deg, var(--kratka) 1px, transparent 1px);
  background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, repeat, repeat;
  background-size: auto, auto, auto, auto, auto, var(--cell) var(--cell), var(--cell) var(--cell);
  border-radius: 14px;
  box-shadow: 0 14px 38px -16px rgba(43, 38, 34, 0.26);
}
[data-theme="dark"] body.login-page::before {
  box-shadow: 0 14px 38px -16px rgba(0, 0, 0, 0.55);
}

/* Header — copied verbatim from the landing page so the two never diverge.
   Same markup, same classes, same values; the login page simply has no
   "Log in" link. If you change one, change the other. */
body.login-page .wrap {
  position: relative;
  width: 100%; max-width: var(--measure); margin: 0 auto;
  padding-left: clamp(calc(var(--cell) * 3), 7vw, calc(var(--cell) * 4));
  padding-right: clamp(24px, 4vw, 78px);
}
body.login-page .top {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px;
  height: calc(var(--cell) * 4);
  box-sizing: border-box;
}
body.login-page .mark {
  --lh: var(--cell); --k: var(--k-serif);
  font-family: var(--serif); font-size: 1.6rem; line-height: var(--lh);
  letter-spacing: -0.01em; text-decoration: none; color: var(--ink);
  position: relative;
  top: calc(var(--lh) / 2 - 1em * var(--k) / 2);
}
body.login-page .top-right { display: flex; align-items: flex-end; gap: 10px; }
body.login-page .top a.enter,
body.login-page .theme {
  display: inline-flex; align-items: center; justify-content: center;
  box-sizing: border-box;
  height: var(--cell);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: none;
  font-family: var(--sans); font-size: 0.96rem; line-height: 1;
  color: var(--ink-muted); text-decoration: none; cursor: pointer;
  transition: color .2s, border-color .2s;
}
body.login-page .top a.enter:hover,
body.login-page .theme:hover {
  color: var(--accent-ink); border-color: var(--accent);
}

/* Symmetric inline padding, so the centred box is centred on the sheet and
   not on whatever is left over. The minimum is 2.5 cells (65px), which keeps
   the form a full cell clear of the margin rule, even on a 320px phone. */
body.login-page main.container {
  box-sizing: border-box;
  max-width: var(--measure);
  margin: 0 auto;
  padding-inline: clamp(calc(var(--cell) * 3), 7vw, calc(var(--cell) * 4));
  padding-bottom: calc(var(--cell) * 4);
}

body.login-page .login-box,
body.login-page .confirm-box {
  width: 100%;
  max-width: 22rem;
  margin-inline: auto;
  padding-top: calc(var(--cell) * 4);
  text-align: center;
}
/* The header already carries the app name; the box repeated it. */
body.login-page .login-box h1 { display: none; }
body.login-page .login-box h1 {
  --lh: calc(var(--cell) * 2); --k: var(--k-serif);
  font-family: var(--serif); font-weight: 400;
  font-size: 2.6rem; line-height: var(--lh); letter-spacing: -0.02em;
  margin: 0 0 var(--cell);
  position: relative;
  top: calc(var(--lh) / 2 - 1em * var(--k) / 2);
}
body.login-page .login-box p,
body.login-page .form-error,
body.login-page .form-info {
  --lh: var(--cell); --k: var(--k-sans);
  font-size: 1rem; line-height: var(--lh);
  margin: 0 0 var(--cell);
  position: relative;
  top: calc(var(--lh) / 2 - 1em * var(--k) / 2);
}

/* Fields and primary actions: two cells tall, so a row of them keeps time. */
body.login-page .login-box input[type="email"],
body.login-page .login-box input[type="password"],
body.login-page .code-input {
  box-sizing: border-box;
  display: block; width: 100%;
  height: calc(var(--cell) * 2);
  margin: 0 0 var(--cell);
  padding: 0 14px;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--surface); color: var(--ink);
  font: 400 1rem var(--sans);
  text-align: left;
}
body.login-page .code-input {
  font: 500 1.35rem var(--mono);
  letter-spacing: 0.4em; text-indent: 0.4em;
}
body.login-page .login-box input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-color: transparent;
}
body.login-page .btn-primary {
  box-sizing: border-box;
  display: inline-flex; align-items: center; justify-content: center;
  height: calc(var(--cell) * 2);
  padding: 0 30px; border-radius: 3px;
  font-family: var(--sans); font-weight: 600; font-size: 1.02rem; line-height: 1;
}
body.login-page .btn-block { width: 100%; }

body.login-page .login-alt {
  display: flex; justify-content: center; gap: 10px;
  margin-top: var(--cell);
}
body.login-page .login-alt form { margin: 0; }
body.login-page .quiet-action {
  display: inline-flex; align-items: center; justify-content: center;
  box-sizing: border-box;
  height: var(--cell); padding: 0 12px;
  border: 1px solid var(--line); border-radius: 3px;
  background: none; color: var(--ink-muted);
  font-family: var(--sans); font-size: 0.92rem; line-height: 1;
  cursor: pointer; text-decoration: none;
  transition: color .2s, border-color .2s;
}
body.login-page .quiet-action:hover { color: var(--accent); border-color: var(--accent); }
body.login-page .quiet-action[disabled] { opacity: .5; cursor: default; }
body.login-page .login-alt .muted.small {
  --lh: var(--cell); --k: var(--k-sans);
  line-height: var(--lh); position: relative;
  top: calc(var(--lh) / 2 - 1em * var(--k) / 2);
}

.theme-dark { display: none; }
[data-theme="dark"] .theme-light { display: none; }
[data-theme="dark"] .theme-dark  { display: inline; }
