/* ==========================================================================
   Lingrow Vocabulary — design tokens
   Concept: a linguist's field notebook — index cards, phonetic stamps,
   audio waveforms — rendered as a dark, focused, app-like SPA.
   ========================================================================== */
:root {
  --ink: #12151c;
  --ink-2: #171b24;
  --panel: #1c212c;
  --panel-hi: #242a37;
  --line: rgba(246, 241, 228, 0.09);
  --line-soft: rgba(246, 241, 228, 0.05);
  --parchment: #f6f1e4;
  --parchment-dim: #d9d3c2;
  --ink-text: #e9e6dd;
  --ink-text-dim: #9aa0ad;
  --amber: #e3a23a;
  --amber-hi: #f2b559;
  --coral: #e1573f;
  --sage: #6fae7c;
  --shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.55);

  --font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 15% -10%, #1a2030 0%, var(--ink) 55%);
  color: var(--ink-text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font-family: inherit; }
a { color: inherit; }
::selection { background: var(--amber); color: #17130a; }

:focus-visible {
  outline: 2px solid var(--amber-hi);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------------------------------------------------------------------- */
/* App shell                                                              */
/* ---------------------------------------------------------------------- */
#app {
  display: grid;
  grid-template-columns: 88px 1fr;
  height: 100vh;
  height: 100dvh;
}

.rail {
  border-right: 1px solid var(--line);
  background: var(--ink-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0;
  gap: 6px;
}
.rail__brand {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(155deg, var(--amber) 0%, #c97f22 100%);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 600; font-size: 19px; color: #1a1305;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.rail__nav { display: flex; flex-direction: column; gap: 4px; width: 100%; align-items: center; }
.rail__item {
  width: 56px; height: 56px;
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  background: transparent; border: none; color: var(--ink-text-dim);
  cursor: pointer; transition: background .15s, color .15s;
  font-size: 10px; letter-spacing: .02em;
}
.rail__item svg { width: 20px; height: 20px; }
.rail__item:hover { background: var(--panel); color: var(--ink-text); }
.rail__item.is-active { background: var(--panel-hi); color: var(--amber-hi); }
.rail__spacer { flex: 1; }
.rail__user {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--panel-hi); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 12px; color: var(--amber-hi);
  cursor: pointer;
}

.stage { position: relative; overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--ink) 0%, rgba(18,21,28,0) 100%);
}
.topbar__title { font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.topbar__meta { font-family: var(--font-mono); font-size: 12px; color: var(--ink-text-dim); }
.topbar__spacer { flex: 1; }
.searchbox {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px; width: 240px;
}
.searchbox input {
  background: none; border: none; color: var(--ink-text); font-size: 13px; width: 100%;
}
.searchbox input:focus { outline: none; }
.searchbox svg { width: 15px; height: 15px; color: var(--ink-text-dim); flex-shrink: 0; }

.view { flex: 1; overflow-y: auto; padding: 26px 28px 60px; }
.view::-webkit-scrollbar { width: 8px; }
.view::-webkit-scrollbar-thumb { background: var(--panel-hi); border-radius: 8px; }

/* ---------------------------------------------------------------------- */
/* Deck grid                                                              */
/* ---------------------------------------------------------------------- */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.deck-card {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  aspect-ratio: 4/3;
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform .18s ease, border-color .18s;
}
.deck-card:hover { transform: translateY(-3px); border-color: var(--amber); }
.deck-card__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .55; transition: opacity .18s, transform .4s; }
.deck-card:hover .deck-card__img { opacity: .7; transform: scale(1.04); }
.deck-card__scrim { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(18,21,28,0) 20%, rgba(15,17,22,.95) 100%); }
.deck-card__body { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px; }
.deck-card__name { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.deck-card__count { font-family: var(--font-mono); font-size: 11.5px; color: var(--parchment-dim); margin-top: 3px; }
.deck-card--empty .deck-card__img { display: none; }
.deck-card--empty { background: repeating-linear-gradient(135deg, var(--panel), var(--panel) 10px, var(--panel-hi) 10px, var(--panel-hi) 11px); }

/* ---------------------------------------------------------------------- */
/* Word list — catalog cards                                             */
/* ---------------------------------------------------------------------- */
.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.word-card {
  background: var(--parchment);
  color: #241d10;
  border-radius: var(--radius-md);
  padding: 16px 16px 14px;
  cursor: pointer;
  position: relative;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0,0,0,.06);
  transition: transform .15s ease;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 130px;
}
.word-card:hover { transform: translateY(-2px) rotate(-.2deg); }
.word-card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.word-card__title { font-family: var(--font-display); font-size: 20px; font-weight: 600; line-height: 1.15; }
.word-card__ipa { font-family: var(--font-mono); font-size: 11px; color: #6b6248; margin-top: 2px; word-break: break-word; }
.word-card__stamp {
  font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: .04em;
  border: 1.5px solid #b5461f; color: #b5461f;
  border-radius: 6px; padding: 2px 6px; transform: rotate(4deg);
  flex-shrink: 0;
}
.word-card__foot { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.word-card__play {
  width: 30px; height: 30px; border-radius: 50%;
  background: #241d10; color: var(--parchment);
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
}
.word-card__play svg { width: 13px; height: 13px; }
.word-card__save {
  background: none; border: none; cursor: pointer; color: #8a7f5f; padding: 4px;
}
.word-card__save.is-saved { color: #b5461f; }
.word-card__save svg { width: 18px; height: 18px; }
.word-card__practiced {
  position: absolute; top: 10px; left: 10px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--sage);
  box-shadow: 0 0 0 3px rgba(111,174,124,.25);
}

/* ---------------------------------------------------------------------- */
/* Word detail panel (slide-over)                                        */
/* ---------------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10,11,15,.6);
  backdrop-filter: blur(2px);
  display: flex; justify-content: flex-end;
  z-index: 40; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.overlay.is-open { opacity: 1; pointer-events: auto; }
.detail-panel {
  width: min(520px, 100%); height: 100%; background: var(--ink-2);
  border-left: 1px solid var(--line); overflow-y: auto;
  transform: translateX(24px); transition: transform .22s ease;
  padding: 28px 26px 60px;
}
.overlay.is-open .detail-panel { transform: translateX(0); }
.detail-panel__close {
  position: absolute; top: 18px; right: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 50%;
  width: 34px; height: 34px; color: var(--ink-text); cursor: pointer;
}
.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.detail-head__play {
  width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(155deg, var(--amber) 0%, #c97f22 100%);
  border: none; color: #1a1305; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
}
.detail-head__play svg { width: 20px; height: 20px; }
.detail-head__title { font-family: var(--font-display); font-size: 30px; font-weight: 600; }
.detail-head__ipa { font-family: var(--font-mono); color: var(--ink-text-dim); font-size: 13px; margin-top: 2px; }
.detail-badges { display: flex; gap: 8px; margin: 14px 0 22px; }
.badge {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .03em;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-text-dim);
}
.badge--level { color: var(--amber-hi); border-color: rgba(227,162,58,.4); }
.badge--deck { cursor: pointer; }
.detail-actions { display: flex; gap: 10px; margin-bottom: 24px; }

.desc-block { border-top: 1px solid var(--line); padding: 18px 0; }
.desc-block__text { font-size: 14.5px; line-height: 1.6; color: var(--ink-text); }
.desc-block__text p { margin: 0 0 8px; }
.example {
  display: flex; align-items: flex-start; gap: 10px;
  margin-top: 12px; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.example__play {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; margin-top: 1px;
  background: var(--panel-hi); border: 1px solid var(--line); color: var(--amber-hi);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.example__play svg { width: 11px; height: 11px; }
.example__text { font-size: 13.5px; line-height: 1.55; color: var(--ink-text-dim); }
.example__text b { color: var(--ink-text); font-weight: 600; }

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */
.btn {
  font-family: var(--font-body); font-size: 13.5px; font-weight: 600;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink-text); cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-hi); }
.btn svg { width: 15px; height: 15px; }
.btn--primary { background: var(--amber); border-color: var(--amber); color: #1a1305; }
.btn--primary:hover { background: var(--amber-hi); }
.btn--ghost { background: transparent; }
.btn--danger-outline { border-color: rgba(225,87,63,.4); color: var(--coral); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------------------------------------------------------------- */
/* Games hub                                                              */
/* ---------------------------------------------------------------------- */
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.game-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 22px; cursor: pointer; transition: border-color .15s, transform .15s;
  display: flex; flex-direction: column; gap: 10px; min-height: 170px;
}
.game-card:hover { border-color: var(--amber); transform: translateY(-2px); }
.game-card__icon {
  width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  background: rgba(227,162,58,.12); color: var(--amber-hi);
}
.game-card__icon svg { width: 20px; height: 20px; }
.game-card__title { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.game-card__desc { font-size: 13px; color: var(--ink-text-dim); line-height: 1.5; }
.game-card__stat { margin-top: auto; font-family: var(--font-mono); font-size: 11.5px; color: var(--amber-hi); }
.game-card--soon { opacity: .5; cursor: default; }
.game-card--soon:hover { transform: none; border-color: var(--line); }

/* ---------------------------------------------------------------------- */
/* Game player (full screen focus mode)                                  */
/* ---------------------------------------------------------------------- */
.player {
  position: fixed; inset: 0; background: var(--ink); z-index: 50;
  display: flex; flex-direction: column; align-items: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.player.is-open { opacity: 1; pointer-events: auto; }
.player__top { width: 100%; max-width: 640px; padding: 22px 20px 0; display: flex; align-items: center; gap: 14px; }
.player__exit { background: none; border: none; color: var(--ink-text-dim); cursor: pointer; }
.player__exit svg { width: 20px; height: 20px; }
.player__progress { flex: 1; height: 6px; border-radius: 4px; background: var(--panel); overflow: hidden; }
.player__progress-bar { height: 100%; background: linear-gradient(90deg, var(--amber), var(--amber-hi)); transition: width .25s; }
.player__count { font-family: var(--font-mono); font-size: 12px; color: var(--ink-text-dim); white-space: nowrap; }

.player__body { flex: 1; width: 100%; max-width: 640px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; gap: 26px; }
.player__level { font-family: var(--font-mono); font-size: 11px; color: var(--amber-hi); letter-spacing: .05em; }
.player__audio-btn {
  width: 84px; height: 84px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(155deg, var(--amber) 0%, #c97f22 100%); color: #1a1305;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
  position: relative;
}
.player__audio-btn svg { width: 30px; height: 30px; }
.player__audio-btn.is-playing::before {
  content: ''; position: absolute; inset: -8px; border-radius: 50%;
  border: 2px solid var(--amber); animation: pulse-ring 1s ease-out infinite;
}
@keyframes pulse-ring { from { transform: scale(.9); opacity: .8; } to { transform: scale(1.35); opacity: 0; } }

.player__sentence {
  font-family: var(--font-display); font-size: clamp(19px, 3.4vw, 26px);
  text-align: center; line-height: 1.5; max-width: 560px;
}
.player__blank {
  display: inline-block; min-width: 110px;
  border-bottom: 2px solid var(--amber);
  font-family: var(--font-mono); font-size: .7em; text-align: center;
  padding: 0 4px;
}

.player__input-row { display: flex; gap: 10px; align-items: center; }
.player__input {
  font-family: var(--font-mono); font-size: 20px; text-align: center;
  background: var(--panel); border: 1.5px solid var(--line); border-radius: 12px;
  color: var(--ink-text); padding: 12px 18px; width: 260px;
  transition: border-color .15s, background .15s;
}
.player__input:focus { outline: none; border-color: var(--amber); }
.player__input.is-correct { border-color: var(--sage); background: rgba(111,174,124,.12); }
.player__input.is-wrong { border-color: var(--coral); background: rgba(225,87,63,.12); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.player__reveal { font-family: var(--font-mono); font-size: 13px; color: var(--ink-text-dim); min-height: 18px; }
.player__reveal b { color: var(--sage); }

.player__footer { width: 100%; max-width: 640px; padding: 0 20px 30px; display: flex; justify-content: center; }

.report { display: flex; flex-direction: column; align-items: center; gap: 22px; text-align: center; }
.report__ring { position: relative; width: 160px; height: 160px; }
.report__ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.report__ring-num { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.report__ring-num strong { font-family: var(--font-display); font-size: 34px; }
.report__ring-num span { font-family: var(--font-mono); font-size: 11px; color: var(--ink-text-dim); }
.report__stats { display: flex; gap: 26px; }
.report__stat strong { display: block; font-family: var(--font-display); font-size: 22px; }
.report__stat.correct strong { color: var(--sage); }
.report__stat.wrong strong { color: var(--coral); }
.report__stat span { font-size: 11.5px; color: var(--ink-text-dim); font-family: var(--font-mono); }
.report__list { width: 100%; max-width: 420px; text-align: left; margin-top: 6px; }
.report__row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.report__row.wrong .report__row-word { color: var(--coral); }
.report__row.correct .report__row-word { color: var(--sage); }

/* ---------------------------------------------------------------------- */
/* Stats view                                                             */
/* ---------------------------------------------------------------------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 16px 18px; }
.stat-card__num { font-family: var(--font-display); font-size: 30px; font-weight: 600; color: var(--amber-hi); }
.stat-card__label { font-size: 12px; color: var(--ink-text-dim); margin-top: 3px; }
.activity-chart { display: flex; align-items: flex-end; gap: 6px; height: 90px; margin-bottom: 30px; }
.activity-chart__bar { flex: 1; background: var(--panel-hi); border-radius: 4px 4px 0 0; position: relative; min-height: 3px; }
.activity-chart__bar.has-activity { background: linear-gradient(180deg, var(--amber-hi), var(--amber)); }
.section-title { font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 0 0 12px; }
.weak-list { display: flex; flex-direction: column; gap: 8px; }
.weak-row { display: flex; justify-content: space-between; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; }
.weak-row__title { font-family: var(--font-display); font-size: 15px; }
.weak-row__ratio { font-family: var(--font-mono); font-size: 12px; color: var(--coral); }

/* ---------------------------------------------------------------------- */
/* Misc states                                                            */
/* ---------------------------------------------------------------------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-text-dim); }
.empty-state__title { font-family: var(--font-display); font-size: 20px; color: var(--ink-text); margin-bottom: 6px; }
.skeleton { background: linear-gradient(90deg, var(--panel) 25%, var(--panel-hi) 37%, var(--panel) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-md); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

.toast-stack { position: fixed; top: 18px; right: 18px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel-hi); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; font-size: 13px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px; max-width: 300px;
  animation: toast-in .18s ease;
}
.toast--error { border-color: rgba(225,87,63,.4); }
.toast a { color: var(--amber-hi); text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.crumb { font-family: var(--font-mono); font-size: 12px; color: var(--ink-text-dim); margin-bottom: 4px; cursor: pointer; }
.crumb:hover { color: var(--amber-hi); }

/* ---------------------------------------------------------------------- */
/* Mobile                                                                 */
/* ---------------------------------------------------------------------- */
@media (max-width: 780px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr 64px; }
  .rail {
    order: 2; flex-direction: row; border-right: none; border-top: 1px solid var(--line);
    padding: 8px 6px; justify-content: space-around;
  }
  .rail__brand { display: none; }
  .rail__nav { flex-direction: row; justify-content: space-around; width: 100%; }
  .rail__spacer { display: none; }
  .rail__user { width: 34px; height: 34px; }
  .stage { order: 1; }
  .topbar { padding: 14px 16px; flex-wrap: wrap; }
  .searchbox { width: 100%; order: 3; margin-top: 4px; }
  .view { padding: 16px 16px 40px; }
  .deck-grid, .word-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .detail-panel { width: 100%; padding: 24px 18px 50px; }
  .player__input { width: 100%; max-width: 260px; }
  .report__stats { gap: 16px; }
}
