/* ============================================================
   language.css — the two flashcard rooms.
   ------------------------------------------------------------
   Styles for the Language Room behind the desk globe AND the
   Subjects room behind the card-index box — the two rooms share
   one view layer (see SRS_ROOMS in js/util.js), so these .lang-*
   classes dress both. Covers the room (shelf of books + the
   index-card stacks), the book page (card list), and the
   practice flow (the big flippable index card).

   Everything leans on palette.css variables (--ink, --bg-page,
   --accent, --highlight) so the rooms recolor themselves with
   the seasons and dark mode, like the rest of the library.
   ============================================================ */

/* --- The globe's door spot ---------------------------------------- */
/* The clickable wrapper around the globe (its "explore" wood sign
   lives here too — outside .shelf-globe, whose zoom would scale the
   sign up ~2.5×). Pointer cursor and the tiniest lift on hover. */
.globe-spot {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}
.globe-spot .shelf-globe {
  /* The base decor style sets pointer-events: none (it used to be
     purely ornamental) — turn clicks back on for the door. */
  pointer-events: auto;
  transition: transform 0.25s ease;
}
.globe-spot:hover .shelf-globe,
.globe-spot:focus-visible .shelf-globe {
  transform: translateY(-3px);
}
/* The globe drawing is zoomed, so its layout box is much taller than
   the drawn art — anchor the sign a fixed height above the shelf
   instead of above the box (tuned to sit just over the sphere). */
.globe-spot .globe-sign {
  bottom: 168px;
}

/* --- The room ------------------------------------------------------ */

.lang-room-note {
  margin: 10px 16px 0;
  font-size: 0.9rem;
  font-style: italic;
  color: var(--ink);
  opacity: 0.75;
  text-align: center;
}

/* Stack of index cards on the shelf tail — the door into practice.
   Three offset cream cards with a small caption underneath, in the
   spirit of the mug and globe decor. */
.lang-card-stack {
  margin-left: auto;              /* cluster at the right end, like the mug */
  align-self: flex-end;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 0 4px;
}
.lang-card-stack[data-action] { cursor: pointer; transition: transform 0.2s ease; }
.lang-card-stack[data-action]:hover,
.lang-card-stack[data-action]:focus-visible { transform: translateY(-2px); }
.lang-card-stack.is-empty { opacity: 0.55; }

.lang-stack-cards {
  position: relative;
  display: block;
  width: 50px;
  height: 34px;
}
.lang-stack-card {
  position: absolute;
  width: 44px;
  height: 28px;
  background: var(--bg-page);
  border: 1.5px solid var(--ink);
  border-radius: 3px;
}
.lang-stack-card--3 { left: 0;   top: 5px; transform: rotate(-7deg); }
.lang-stack-card--2 { left: 3px; top: 2px; transform: rotate(4deg); }
.lang-stack-card--1 {
  left: 2px;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
  /* one faint ruled line, like a real index card */
  background-image: linear-gradient(
    to bottom,
    transparent 0 19px,
    color-mix(in srgb, var(--accent) 55%, transparent) 19px 20px,
    transparent 20px
  );
}
.lang-stack-label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}

/* --- Language book page ------------------------------------------- */

.lang-book { display: flex; flex-direction: column; gap: 14px; }

.lang-book-toolbar { display: flex; justify-content: flex-start; }

.lang-book-empty {
  font-style: italic;
  color: var(--ink);
  opacity: 0.7;
}

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

/* Search + sort row above the chips. */
.lang-list-controls { display: flex; align-items: center; gap: 8px; }
.lang-search {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.85rem;
  padding: 6px 10px;
  border: 1.5px solid color-mix(in srgb, var(--ink) 55%, transparent);
  border-radius: 6px;
  background: var(--bg-page);
  color: var(--ink);
}
.lang-search:focus { outline: none; border-color: var(--ink); }
.lang-sort {
  flex: 0 0 auto;
  font: inherit;
  font-size: 0.8rem;
  padding: 6px 8px;
  border: 1.5px solid color-mix(in srgb, var(--ink) 55%, transparent);
  border-radius: 6px;
  background: var(--bg-page);
  color: var(--ink);
  cursor: pointer;
}

/* Collapsible deck sections in the "all" view. */
.lang-deck-section { display: flex; flex-direction: column; gap: 8px; }
.lang-deck-section.is-empty { opacity: 0.55; }
.lang-deck-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: left;
  padding: 7px 10px;
  border: 1.5px solid color-mix(in srgb, var(--ink) 45%, transparent);
  border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 5%, var(--bg-page));
  color: var(--ink);
  cursor: pointer;
}
.lang-deck-header--inert { cursor: default; }
.lang-deck-caret { font-size: 0.8rem; opacity: 0.7; }
.lang-deck-title { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
.lang-deck-counts {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.75;
  white-space: nowrap;
}
.lang-deck-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 10px;
}

/* Small date dividers inside a date-sorted list. */
.lang-list-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  font-style: italic;
  color: var(--ink);
  opacity: 0.55;
  margin-top: 2px;
}
.lang-list-divider::before,
.lang-list-divider::after {
  content: '';
  flex: 1;
  border-top: 1px dashed color-mix(in srgb, var(--ink) 35%, transparent);
}

/* Paging + search-overflow notes. */
.lang-show-more {
  font: inherit;
  font-size: 0.78rem;
  padding: 6px 10px;
  border: 1.5px dashed color-mix(in srgb, var(--ink) 45%, transparent);
  border-radius: 6px;
  background: none;
  color: var(--ink);
  opacity: 0.8;
  cursor: pointer;
}
.lang-show-more:hover { opacity: 1; border-style: solid; }
.lang-search-overflow {
  font-size: 0.78rem;
  font-style: italic;
  color: var(--ink);
  opacity: 0.65;
  text-align: center;
}

/* Inside a named section (or a filtered deck) the per-row deck tag is
   redundant — it only earns its place in mixed search results. */
.lang-card-list--sections .lang-card-row-deck { display: none; }

.lang-card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-page);
  border: 1.5px dashed color-mix(in srgb, var(--ink) 40%, transparent);
  border-radius: 6px;
}
.lang-card-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.lang-card-row-front { font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.lang-card-row-back {
  font-size: 0.85rem;
  color: var(--ink);
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lang-card-row-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 108px;
  text-align: right;
  font-size: 0.72rem;
  color: var(--ink);
  opacity: 0.85;
}
.lang-card-row-phrase { font-size: 0.72rem; font-style: italic; }
.lang-card-row-actions { display: flex; gap: 6px; }

/* Quiet footer link on the book page — the page's buttons are for
   study; anything about the book itself (name, color, removal) is
   tucked behind this. */
.lang-book-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 26px;
  padding-top: 10px;
  border-top: 1px dashed color-mix(in srgb, var(--ink) 25%, transparent);
}
.lang-foot-link {
  font: inherit;
  font-size: 0.75rem;
  color: var(--ink);
  opacity: 0.5;
  background: none;
  border: none;
  padding: 2px 4px;
  text-decoration: underline;
  cursor: pointer;
}
.lang-foot-link:hover { opacity: 0.9; }

/* --- Book settings page -------------------------------------------- */

.lang-book-settings {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 380px;
}
.lang-settings-field { display: flex; flex-direction: column; gap: 6px; }
.lang-settings-label {
  font-size: 0.8rem;
  color: var(--ink);
  opacity: 0.8;
}
/* A sentence of guidance under a settings label (e.g. what archiving
   does) — quieter than body text, still readable. */
.lang-settings-help {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink);
  opacity: 0.7;
}
.lang-swatch-row { display: flex; flex-wrap: wrap; gap: 8px; }
.lang-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--swatch);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.lang-swatch:hover { transform: translateY(-2px); }
.lang-swatch.is-current {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* "Remove this book…" lives alone at the very bottom of the settings
   page, as a quiet text link — deliberately far from everything else
   (and it asks you to type the book's name anyway). */
.lang-book-remove {
  display: flex;
  justify-content: flex-end;
  margin-top: 34px;
}
.lang-remove-link {
  font: inherit;
  font-size: 0.75rem;
  color: var(--ink);
  opacity: 0.45;
  background: none;
  border: none;
  padding: 2px 4px;
  text-decoration: underline;
  cursor: pointer;
}
.lang-remove-link:hover { opacity: 0.9; color: #b04a3a; }

/* --- Practice ------------------------------------------------------ */

.lang-practice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 8px 0 20px;
}

.lang-practice-pos {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--ink);
  opacity: 0.65;
}
/* ‹ › browse buttons flanking the "card X of Y" counter (also on the
   ← / → keys). Browsing never rates a card. */
.lang-nav-btn {
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 10px;
  border: 1.5px solid color-mix(in srgb, var(--ink) 45%, transparent);
  border-radius: 999px;
  background: var(--bg-page);
  color: var(--ink);
  cursor: pointer;
}
.lang-nav-btn:hover:not(:disabled) { border-color: var(--ink); }
.lang-nav-btn:disabled { opacity: 0.35; cursor: default; }

/* The big index card. Cream page, faint ruled lines, a slight tilt so
   it reads as a real card someone set down, not a UI panel. */
.lang-practice-card {
  position: relative;
  width: min(430px, 100%);
  min-height: 220px;
  box-sizing: border-box;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-page);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 27px,
    color-mix(in srgb, var(--accent) 30%, transparent) 27px 28px
  );
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 3px 4px 0 color-mix(in srgb, var(--ink) 22%, transparent);
  /* Each card sits at its own slight angle — the tilt comes in per
     card from a --lang-tilt inline style (derived from the card's id
     in renderLanguagePractice, so it's stable for that card). */
  transform: rotate(var(--lang-tilt, -0.6deg));
  cursor: pointer;
}
.lang-practice-card.is-flipped {
  /* Flipping leans the card the other way, like turning a real card. */
  transform: rotate(calc(var(--lang-tilt, -0.6deg) * -1));
  animation: lang-card-turn 0.3s ease;
}
@keyframes lang-card-turn {
  from { transform: rotateY(65deg); opacity: 0.4; }
  to   { transform: rotateY(0deg) rotate(calc(var(--lang-tilt, -0.6deg) * -1)); opacity: 1; }
}

.lang-practice-tag {
  position: absolute;
  top: 8px;
  right: 14px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink);
  opacity: 0.6;
}
.lang-practice-front {
  font-size: 2.6rem;
  line-height: 1.15;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  overflow-wrap: anywhere;
}
/* Once the card is flipped, the front shrinks back so the answer
   underneath gets the attention. */
.lang-practice-card.is-flipped .lang-practice-front { font-size: 1.35rem; }
.lang-practice-answer {
  width: 100%;
  padding-top: 12px;
  border-top: 1.5px dashed color-mix(in srgb, var(--ink) 45%, transparent);
  text-align: center;
}
.lang-practice-back {
  font-size: 1.15rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.lang-practice-example {
  margin-top: 6px;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink);
  opacity: 0.8;
  overflow-wrap: anywhere;
}
.lang-practice-note {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--ink);
  opacity: 0.72;
  overflow-wrap: anywhere;
}
.lang-note-link {
  margin-top: 10px;
  font: inherit;
  font-size: 0.75rem;
  color: var(--ink);
  opacity: 0.55;
  background: none;
  border: none;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}
.lang-note-link:hover { opacity: 0.9; }
.lang-practice-hint {
  font-size: 0.78rem;
  color: var(--ink);
  opacity: 0.6;
}
.lang-practice-keys {
  font-size: 0.72rem;
  color: var(--ink);
  opacity: 0.5;
}
/* Little keyboard-key chip inside the buttons (y / s / n / space). */
.lang-key-hint {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  font-size: 0.68rem;
  line-height: 1.5;
  border: 1px solid color-mix(in srgb, var(--ink) 55%, transparent);
  border-bottom-width: 2px;
  border-radius: 4px;
  opacity: 0.75;
}

/* Flip + rating buttons — soft pills, one decision at a time. */
.lang-flip-btn,
.lang-rate-btn {
  font: inherit;
  padding: 8px 22px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  background: var(--bg-page);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.lang-flip-btn:hover,
.lang-rate-btn:hover { transform: translateY(-1px); }
.lang-rate-btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.lang-rate-btn--gotit { background: var(--highlight); }
.lang-rate-btn--unsure { font-size: 0.9rem; opacity: 0.9; }
.lang-rate-btn--unsure:hover { background: color-mix(in srgb, var(--ink) 8%, var(--bg-page)); }
.lang-rate-btn--notyet:hover { background: color-mix(in srgb, var(--accent) 30%, var(--bg-page)); }
.lang-rate-btn--gotit:hover { background: color-mix(in srgb, var(--highlight) 80%, #ffffff); }

/* Closing page — a quiet end, not a win screen. */
.lang-practice--done { text-align: center; gap: 12px; padding-top: 24px; }
.lang-practice-done-msg { font-size: 1.05rem; color: var(--ink); }
.lang-practice-done-more { font-size: 0.9rem; color: var(--ink); opacity: 0.85; }
.lang-more-link {
  font: inherit;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0;
  margin-left: 4px;
  text-decoration: underline;
  cursor: pointer;
}

/* --- Practice stacks in the middle of the room ---------------------- */
/* One stack of index cards per language, set out below the shelf like
   cards left on a desk. The top card tints toward the book's spine
   color (--spine comes in as an inline style) so each stack reads as
   belonging to its book. */
.lang-stacks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 30px;
  margin-top: 38px;
  padding: 0 16px;
}
.lang-card-stack--book {
  /* Undo the shelf-tail placement the base stack class carries. */
  margin-left: 0;
  align-self: auto;
}
.lang-card-stack--book .lang-stack-card--1 {
  background-color: color-mix(in srgb, var(--spine, var(--accent)) 28%, var(--bg-page));
}
.lang-stack-name {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
}
/* Archived books — a quiet list under the stacks. Each name opens the
   book, where settings can bring it back to the shelf. */
.lang-archived-note {
  margin-top: 26px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink);
  opacity: 0.65;
}
.lang-archived-link {
  font: inherit;
  font-size: 0.78rem;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0 3px;
  text-decoration: underline;
  cursor: pointer;
}
.lang-archived-link:hover { opacity: 0.8; }

/* Footer links in the room (the daily goal and the tutorial door). */
.lang-room-links {
  margin-top: 18px;
  text-align: center;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 18px;
}

/* --- Deck chips on the book page ------------------------------------ */
.lang-deck-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.lang-chip {
  font: inherit;
  font-size: 0.75rem;
  padding: 3px 10px;
  border: 1.5px solid color-mix(in srgb, var(--ink) 55%, transparent);
  border-radius: 999px;
  background: var(--bg-page);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.lang-chip:hover { border-color: var(--ink); transform: translateY(-1px); }
.lang-chip.is-active {
  background: var(--highlight);
  border-color: var(--ink);
  font-weight: 700;
}
.lang-chip.is-muted { opacity: 0.55; }

/* Small deck tag on a card row, next to the status words. */
.lang-card-row-deck {
  font-size: 0.68rem;
  padding: 1px 7px;
  border: 1px solid color-mix(in srgb, var(--ink) 40%, transparent);
  border-radius: 999px;
  opacity: 0.8;
  white-space: nowrap;
}

/* --- Deck rows on the settings page --------------------------------- */
.lang-deck-rows { display: flex; flex-direction: column; gap: 6px; }
.lang-deck-row { display: flex; align-items: center; gap: 8px; }
.lang-deck-row .lang-deck-input { flex: 1; min-width: 0; }
.lang-deck-count {
  font-size: 0.72rem;
  color: var(--ink);
  opacity: 0.6;
  white-space: nowrap;
}

/* --- Small screens -------------------------------------------------- */
@media (max-width: 480px) {
  /* Search gets its own full line; the sort menu drops below it. */
  .lang-list-controls { flex-wrap: wrap; }
  .lang-search { flex: 1 1 100%; }
  .lang-deck-body { padding-left: 4px; }
  .lang-card-row { flex-wrap: wrap; }
  .lang-card-row-meta {
    min-width: 0;
    flex-direction: row;
    gap: 8px;
    align-items: baseline;
  }
  .lang-practice-card { min-height: 180px; }
  .lang-practice-front { font-size: 2rem; }
}
