@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;1,9..144,500&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root{
  --ink:#0E2A22;
  --ink-soft:#3B5347;
  --paper:#F1ECDA;
  --paper-shadow:#D9D0B4;
  --rail:#123328;
  --rail-deep:#0A211A;
  --gold:#B8923F;
  --ok:#3E7A52;
  --ok-soft:#DCEBDF;
  --bad:#B23A20;
  --bad-soft:#F4E1DA;
  --focus:#E8C468;
  --danger:#B23A20;
}

*{ box-sizing:border-box; }

html,body{
  margin:0; padding:0; min-height:100%;
  background:
    radial-gradient(1200px 800px at 15% -10%, #1B4535 0%, transparent 60%),
    linear-gradient(180deg, var(--rail) 0%, var(--rail-deep) 100%);
  color:var(--ink);
  font-family:'IBM Plex Mono', monospace;
  -webkit-font-smoothing:antialiased;
}

a{ color:inherit; }

/* ---- Top bar ---- */
.topbar{
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 20px; border-bottom:1px solid rgba(255,255,255,.08);
}
.brand{ display:flex; align-items:center; gap:8px; text-decoration:none; }
.brand-mark{ color:var(--gold); font-size:16px; }
.brand-text{ color:#E9E2C8; font-family:'Fraunces', serif; font-style:italic; font-weight:600; font-size:17px; }
.topnav{ display:flex; align-items:center; gap:10px; }
.topnav-user{ color:#9FB6A7; font-size:12px; }
.inline-form{ display:inline; }

.wrap{ max-width:760px; margin:0 auto; padding:24px 18px 60px; }

/* ---- Shared bits ---- */
.tab-mark{
  display:inline-block; background:var(--gold); color:var(--rail-deep); font-weight:600; font-size:11px;
  letter-spacing:.14em; text-transform:uppercase; padding:6px 12px; border-radius:2px 2px 0 0;
}
.title, .page-title, .auth-title{
  color:#E9E2C8; font-family:'Fraunces', serif; font-size:26px; font-style:italic; font-weight:500; margin:8px 0 2px;
}
.subtitle, .page-subtitle{ color:#9FB6A7; font-size:11.5px; letter-spacing:.05em; }

.page-head{ display:flex; align-items:flex-end; justify-content:space-between; gap:14px; flex-wrap:wrap; margin-bottom:22px; }

.flash{
  padding:11px 14px; border-radius:6px; font-size:12.5px; margin-bottom:14px;
  border:1px solid rgba(255,255,255,.14);
}
.flash-success{ background:rgba(62,122,82,.18); color:#B7E3C4; border-color:rgba(62,122,82,.4); }
.flash-error{ background:rgba(178,58,32,.18); color:#F3B7A6; border-color:rgba(178,58,32,.4); }

/* ---- Buttons ---- */
.btn{
  font-family:'IBM Plex Mono', monospace; font-size:12.5px; letter-spacing:.03em; border-radius:5px;
  border:1px solid rgba(255,255,255,.18); background:rgba(255,255,255,.05); color:#E9E2C8;
  padding:10px 14px; cursor:pointer; transition:background .15s ease, transform .1s ease; text-decoration:none;
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
}
.btn:hover{ background:rgba(255,255,255,.1); }
.btn:active{ transform:scale(.97); }
.btn:focus-visible{ box-shadow:0 0 0 3px var(--focus); outline:none; }
.btn.icon{ padding:10px 16px; font-size:15px; }
.btn.wide{ flex:1; width:100%; }
.btn.small{ padding:7px 11px; font-size:11.5px; }
.btn.primary{ background:var(--gold); color:var(--rail-deep); border-color:var(--gold); font-weight:600; }
.btn.primary:hover{ background:#cba552; }
.btn.danger{ background:var(--bad-soft); color:#7A2A17; border-color:transparent; }
.btn.danger:hover{ background:#f0c9ba; }
.btn.ghost{ background:transparent; }
.btn.know{ background:var(--ok-soft); color:#1F4A2E; border-color:transparent; }
.btn.know:hover{ background:#c9e4d0; }
.btn.review{ background:var(--bad-soft); color:#7A2A17; border-color:transparent; }
.btn.review:hover{ background:#f0c9ba; }

/* Buttons on light "paper" cards need dark text, not the light nav scheme */
.manage-card .btn:not(.primary):not(.danger),
.deck-card .btn:not(.primary):not(.danger){
  color:var(--ink); background:rgba(14,42,34,.06); border-color:rgba(14,42,34,.22);
}
.manage-card .btn:not(.primary):not(.danger):hover,
.deck-card .btn:not(.primary):not(.danger):hover{ background:rgba(14,42,34,.12); }

.form-actions{ display:flex; gap:8px; margin-top:14px; flex-wrap:wrap; }
.form-actions .btn.primary{ flex:1; min-width:140px; }

/* ---- Auth pages ---- */
.auth-wrap{ display:flex; justify-content:center; padding-top:30px; }
.auth-card{
  background:var(--paper); border:1px solid #C9BE9C; border-radius:8px;
  padding:26px 26px 22px; width:100%; max-width:380px;
  box-shadow:0 20px 40px -18px rgba(0,0,0,.55);
}
.auth-title{ color:var(--ink); font-style:italic; margin-top:10px; }
.auth-switch{ margin-top:18px; font-size:12px; color:var(--ink-soft); text-align:center; }
.auth-switch a{ color:var(--gold); font-weight:600; text-decoration:none; }

/* ---- Manage cards / forms ---- */
.manage-card{
  background:var(--paper); border:1px solid #C9BE9C; border-radius:6px;
  padding:18px 20px; margin-bottom:20px; box-shadow:0 14px 24px -14px rgba(0,0,0,.5);
}
.manage-card h3{
  font-family:'Fraunces', serif; font-style:italic; font-weight:600; font-size:18px;
  color:var(--ink); margin:0 0 14px 0;
}
.field{ margin-bottom:12px; }
.field label{
  display:block; font-size:10.5px; letter-spacing:.08em; text-transform:uppercase;
  color:var(--ink-soft); margin-bottom:5px; font-weight:600;
}
.field .opt{ text-transform:none; font-weight:400; }
.field input[type=text], .field input[type=email], .field input[type=password], .field textarea, .field select{
  width:100%; font-family:'Fraunces', serif; font-size:14.5px; color:var(--ink);
  background:#FBF8EF; border:1px solid #C9BE9C; border-radius:4px; padding:9px 11px;
  resize:vertical;
}
.field input[type=file]{
  width:100%; font-family:'IBM Plex Mono', monospace; font-size:12px; color:var(--ink);
  background:#FBF8EF; border:1px solid #C9BE9C; border-radius:4px; padding:8px 10px;
}
.field input:focus, .field textarea:focus, .field select:focus{
  outline:none; border-color:var(--gold); box-shadow:0 0 0 2px rgba(184,146,63,.25);
}
.field textarea{ min-height:64px; font-style:normal; }
.field-hint{ font-size:10.5px; color:var(--ink-soft); opacity:.75; margin-top:3px; }

/* ---- Dashboard: deck grid ---- */
.folder-section-title{
  color:#E9E2C8; font-family:'Fraunces', serif; font-style:italic; font-weight:600;
  font-size:16px; margin:26px 0 12px; padding-bottom:6px; border-bottom:1px dashed rgba(255,255,255,.15);
}
.deck-grid{ display:grid; grid-template-columns:1fr; gap:14px; }
@media (min-width:620px){ .deck-grid{ grid-template-columns:1fr 1fr; } }
.deck-card{
  background:var(--paper); border:1px solid #C9BE9C; border-radius:6px; padding:16px 18px;
  box-shadow:0 14px 24px -14px rgba(0,0,0,.5); display:flex; flex-direction:column;
}
.deck-card-top{ display:flex; justify-content:space-between; align-items:flex-start; gap:8px; }
.deck-card-top h3{ font-family:'Fraunces', serif; font-weight:600; font-size:16.5px; margin:0; color:var(--ink); }
.deck-count{ font-size:10.5px; color:var(--ink-soft); white-space:nowrap; }
.deck-desc{ font-size:12px; color:var(--ink-soft); margin-top:6px; font-style:italic; }
.deck-progress-track{ height:5px; background:rgba(14,42,34,.12); border-radius:3px; overflow:hidden; margin-top:12px; }
.deck-progress-fill{ height:100%; background:linear-gradient(90deg, var(--ok), #6bc98a); }
.deck-progress-label{ font-size:10px; color:var(--ink-soft); margin-top:5px; }
.deck-actions{ display:flex; gap:8px; margin-top:14px; }

/* ---- Category / folder chips & list items (management) ---- */
.cat-manager{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-bottom:4px; }
.cat-chip{
  display:inline-flex; align-items:center; gap:7px;
  background:#FBF8EF; border:1px solid #C9BE9C; border-radius:14px;
  padding:5px 6px 5px 12px; font-family:'IBM Plex Mono', monospace; font-size:11.5px; color:var(--ink);
}
.cat-chip button{
  background:transparent; border:none; cursor:pointer; padding:2px 6px;
  color:var(--ink-soft); font-size:12px; border-radius:50%; line-height:1;
}
.cat-chip button:hover{ background:rgba(178,58,32,.12); color:var(--danger); }
.cat-chip .rename-btn:hover{ background:rgba(184,146,63,.18); color:var(--gold); }
.cat-empty-hint{ font-size:11.5px; color:var(--ink-soft); opacity:.75; }
.cat-name{ cursor:pointer; }

.deck-list-header{ display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; gap:8px; flex-wrap:wrap; }
.deck-list-header .count-label{ color:#CBD9CE; font-size:12px; }

.card-list{ display:flex; flex-direction:column; gap:8px; }
.list-item{ background:rgba(255,255,255,.04); border:1px solid rgba(255,255,255,.1); border-radius:6px; padding:12px 14px; }
.list-item .li-top{ display:flex; justify-content:space-between; gap:10px; align-items:flex-start; }
.li-recto{ font-family:'Fraunces', serif; font-weight:600; font-size:14.5px; color:#E9E2C8; }
.li-verso{ font-family:'Fraunces', serif; font-style:italic; font-size:12.5px; color:#9FB6A7; margin-top:4px; }
.li-cat{
  font-size:10px; letter-spacing:.06em; text-transform:uppercase; color:var(--gold);
  border:1px solid rgba(184,146,63,.4); border-radius:10px; padding:2px 8px; white-space:nowrap; flex-shrink:0;
}
.li-thumb{ width:48px; height:48px; object-fit:cover; border-radius:4px; border:1px solid rgba(255,255,255,.15); flex-shrink:0; }
.li-actions{ display:flex; gap:6px; margin-top:10px; }
.li-actions .btn{ padding:5px 10px; font-size:11px; }
.empty-list{ text-align:center; color:#7C917F; font-size:12px; padding:24px 10px; }

/* ---- Empty states ---- */
.empty-state{ text-align:center; padding:50px 20px; color:#CBD9CE; }
.empty-state .em-title{ font-family:'Fraunces', serif; font-style:italic; font-size:22px; color:#E9E2C8; margin-bottom:8px; }
.empty-state .em-text{ font-size:12.5px; color:#9FB6A7; max-width:340px; margin:0 auto 16px; line-height:1.6; }
.empty-state .btn{ margin-top:6px; }

/* ================= STUDY VIEW (drawer / flip card) ================= */
.drawer-label{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:18px; }

.progress-row{ display:flex; align-items:center; gap:10px; margin-bottom:16px; color:#CBD9CE; font-size:12px; }
.progress-track{ flex:1; height:5px; background:rgba(255,255,255,.12); border-radius:3px; overflow:hidden; }
.progress-fill{ height:100%; background:linear-gradient(90deg, var(--gold), #E8C468); width:0%; transition:width .25s ease; }
.counts{ display:flex; gap:14px; font-size:11.5px; color:#9FB6A7; white-space:nowrap; }
.counts b.ok{ color:#7FC79A; }
.counts b.bad{ color:#E0917A; }

.stage{ perspective:1800px; margin-bottom:22px; }
.card-shadow-2{ position:relative; }
.card-shadow-2::before, .card-shadow-2::after{
  content:""; position:absolute; left:8px; right:8px; height:100%;
  background:var(--paper-shadow); border-radius:6px; z-index:0;
}
.card-shadow-2::before{ top:10px; transform:rotate(-1.1deg); opacity:.8; }
.card-shadow-2::after{ top:5px; transform:rotate(0.8deg); opacity:.9; }

.card{
  position:relative; z-index:2; min-height:300px; border-radius:6px; cursor:pointer;
  transform-style:preserve-3d; transition:transform .5s cubic-bezier(.2,.8,.2,1); outline:none;
}
.card.flipped{ transform:rotateY(180deg); }
.card:focus-visible{ box-shadow:0 0 0 3px var(--focus); border-radius:8px; }

.face{
  position:absolute; inset:0; backface-visibility:hidden; border-radius:6px;
  background:
    repeating-linear-gradient(180deg, transparent 0 31px, rgba(59,83,71,.09) 31px 32px),
    var(--paper);
  border:1px solid #C9BE9C; box-shadow:0 18px 30px -14px rgba(0,0,0,.55);
  display:flex; flex-direction:column; padding:22px 24px;
}
.face.back{ transform:rotateY(180deg); }

.face-top{ display:flex; justify-content:space-between; align-items:flex-start; gap:8px; }
.lang-stamp{
  display:inline-block; font-family:'IBM Plex Mono', monospace; font-size:10.5px; font-weight:600;
  letter-spacing:.1em; border:1.5px solid var(--gold); color:var(--gold); padding:3px 9px; border-radius:3px;
  transform:rotate(-3deg); opacity:.9; max-width:220px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.card-no{ font-size:11px; color:var(--ink-soft); letter-spacing:.05em; white-space:nowrap; }

.face-body{ flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; padding:8px 2px; overflow-y:auto; gap:10px; }
.word{ font-family:'Fraunces', serif; font-size:clamp(34px, 11vw, 60px); font-weight:600; line-height:1.25; color:var(--ink); }
.face.back .word{ font-family:'Fraunces', serif; font-style:italic; font-weight:500; font-size:clamp(16px,4.6vw,21px); color:#1B4535; }

.card-media-image{ max-width:100%; max-height:150px; object-fit:contain; border-radius:6px; box-shadow:0 4px 10px rgba(0,0,0,.15); }
.card-media-audio{ width:100%; max-width:280px; height:34px; }

.face-bottom{ text-align:center; font-size:10.5px; color:var(--ink-soft); letter-spacing:.08em; opacity:.7; }

.nav-row{ display:flex; align-items:center; justify-content:center; gap:10px; margin-bottom:14px; }
.judge-row{ display:flex; gap:10px; margin-bottom:22px; }

.toolbar{
  display:flex; flex-wrap:wrap; gap:8px; align-items:center; justify-content:space-between;
  border-top:1px dashed rgba(255,255,255,.15); padding-top:16px; margin-bottom:14px;
}
.toggle-group{ display:flex; gap:6px; flex-wrap:wrap; }
.toggle{
  font-family:'IBM Plex Mono', monospace; font-size:11px; letter-spacing:.04em; padding:7px 11px;
  border-radius:14px; border:1px solid rgba(255,255,255,.18); background:transparent; color:#9FB6A7; cursor:pointer;
}
.toggle.active{ background:var(--gold); border-color:var(--gold); color:var(--rail-deep); font-weight:600; }

.save-row{ display:flex; align-items:center; justify-content:space-between; gap:10px; margin-top:14px; font-size:10.5px; letter-spacing:.04em; color:#7C917F; flex-wrap:wrap; }

.search-box{ position:relative; margin-top:12px; }
.search-box input{
  width:100%; font-family:'IBM Plex Mono', monospace; font-size:12.5px; padding:8px 10px;
  border-radius:5px; border:1px solid rgba(255,255,255,.18); background:rgba(255,255,255,.05); color:#E9E2C8;
}
.search-box input::placeholder{ color:#7C917F; }
.search-box input:focus{ outline:none; box-shadow:0 0 0 2px var(--focus); }
.results{ max-height:220px; overflow-y:auto; border-radius:6px; border:1px solid rgba(255,255,255,.12); background:rgba(0,0,0,.18); margin-top:8px; }
.result-row{ display:flex; justify-content:space-between; gap:10px; padding:8px 12px; font-size:12px; color:#CBD9CE; cursor:pointer; border-bottom:1px solid rgba(255,255,255,.06); }
.result-row:last-child{ border-bottom:none; }
.result-row:hover{ background:rgba(255,255,255,.06); }
.result-row .r-cat{ color:#8FAF9B; font-size:10px; text-transform:uppercase; letter-spacing:.05em; white-space:nowrap; }

.hint{ text-align:center; color:#7C917F; font-size:11px; letter-spacing:.03em; margin-top:4px; }

@media (max-width:420px){ .card{ min-height:320px; } }
