:root{
  --bg:#0b0f14; --card:#0f1520; --accent:#d4af37; --text:#e8eef7; --muted:#a9b6c7;
  --line:#22324a; --panel:#0e1420; --chip:#152030; --chipLine:#263a58;
  --ok:#8dd18d; --warn:#ffd479;
}

/* Theme: default is dark. Add class "light" on body for light theme.
   Light theme reverses the palette: light background uses the current accent tones,
   dark tones become text and surfaces. */
body.light{
  --bg:#e9d8a6;
  --card:#fff6dc;
  --accent:#0b0f14;
  --text:#0b0f14;
  --muted:#22324a;
  --line:#c7b37a;
  --panel:#fff2cf;
  --chip:#fff2cf;
  --chipLine:#c7b37a;
  --ok:#1f7a1f;
  --warn:#8a5a00;
}

*{box-sizing:border-box}
body{
  margin:0; background:linear-gradient(180deg,var(--bg) 0%, var(--card) 100%); color:var(--text);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,"Apple Color Emoji","Segoe UI Emoji";
}
header{padding:20px 16px;text-align:center;border-bottom:1px solid rgba(255,255,255,.06)}
h1{margin:6px 0 4px;font-size:22px;letter-spacing:.4px}
p.sub{margin:0;font-size:13px;color:var(--muted)}
.container{max-width:1100px;margin:0 auto;padding:20px}

.controls{display:flex;gap:10px;flex-wrap:wrap;justify-content:center;margin-bottom:14px;align-items:center}
input[type="search"]{
  background:var(--panel);border:1px solid #1e2a3d;color:var(--text);
  padding:10px 12px;border-radius:10px;outline:none;min-width:260px
}
.btn{
  background:#132030;color:var(--text);border:1px solid var(--line);
  padding:10px 12px;border-radius:10px;cursor:pointer
}
.btn.primary{border-color:rgba(212,175,55,.35); box-shadow:inset 0 0 0 1px rgba(212,175,55,.08)}
.btn.ghost{background:transparent}
.pill{
  display:inline-flex; align-items:center; gap:8px;
  padding:8px 10px; border-radius:999px; border:1px solid var(--line);
  background:rgba(19,32,48,.55); color:var(--muted); font-size:12px
}
.pill strong{color:var(--text);font-weight:600}
.divider{width:1px;height:28px;background:rgba(255,255,255,.08);display:none}
@media (min-width:720px){ .divider{display:block} }

.view{display:none}
.view.active{display:block}

/* TABLE VIEW */
.tableWrap{
  border:1px solid rgba(255,255,255,.08);
  border-radius:16px;
  background:rgba(15,21,32,.35);
  padding:14px;
}
.tableTitle{
  display:flex; align-items:center; justify-content:space-between;
  gap:10px; flex-wrap:wrap; margin-bottom:10px
}
.tableTitle h2{margin:0;font-size:14px;color:#e9d8a6;font-weight:700;letter-spacing:.3px}
.tableNote{font-size:12px;color:var(--muted)}
.lettersTable{
  width:100%;
  border-collapse:separate;
  border-spacing:10px;
}
.cell{
  background:radial-gradient(120% 120% at 50% 0%, #13202f 0%, #0f1520 60%, #0b0f14 100%);
  border:1px solid #23344e;
  border-radius:14px;
  padding:12px 12px;
  cursor:pointer;
  transition:transform .08s ease, border-color .15s ease;
  box-shadow:inset 0 0 0 1px rgba(212,175,55,.06);
  user-select:none;
}
.cell:hover{transform:translateY(-1px); border-color:rgba(212,175,55,.45)}
.cell:active{transform:translateY(0px)}
.cellTop{display:flex; align-items:flex-start; justify-content:space-between; gap:10px}
.cellBadge{
  background:var(--chip); border:1px solid var(--chipLine);
  padding:3px 8px; border-radius:999px; font-size:12px; color:#cbd5e1
}
.cellHeb{
  font-family:"SBL Hebrew","Ezra SIL","Cardo","Noto Serif Hebrew","Frank Ruehl","David","Times New Roman",serif;
  font-size:42px; line-height:1; direction:rtl; letter-spacing:1px;
}
.cellName{margin-top:8px; font-size:13px; color:#cfe3ff}
.cellMeaning{margin-top:2px; font-size:12px; color:#e9d8a6; opacity:.95}
.cellMeta{margin-top:8px; font-size:11px; color:var(--muted); line-height:1.35}
.cellMark{
  margin-top:10px; font-size:11px; color:var(--muted)
}

/* CARDS VIEW */
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:16px}
.card{perspective:1000px; scroll-margin-top:18px}
.inner{position:relative;width:100%;height:560px;transform-style:preserve-3d;transition:transform .6s}
.card.flipped .inner{transform:rotateY(180deg)}
.face{
  position:absolute;inset:0;background:radial-gradient(120% 120% at 50% 0%, #13202f 0%, #0f1520 60%, #0b0f14 100%);
  border:1px solid #23344e;border-radius:16px;padding:16px;display:flex;flex-direction:column;justify-content:center;align-items:center;
  backface-visibility:hidden;box-shadow:0 10px 30px rgba(0,0,0,.25), inset 0 0 0 1px rgba(212,175,55,.08)
}
.back{transform:rotateY(180deg);padding:16px 14px;align-items:flex-start;overflow:auto}
.hebrew{
  font-family:"SBL Hebrew","Ezra SIL","Cardo","Noto Serif Hebrew","Frank Ruehl","David","Times New Roman",serif;
  font-size:210px;
  line-height:1; margin:6px 0 6px; letter-spacing:6px; direction:rtl; text-rendering:optimizeLegibility
}
.name{font-size:16px;color:#cfe3ff;margin-bottom:6px}
.meaning{font-size:16px;text-align:center;color:#e9d8a6;margin-bottom:6px}
.badge{
  position:absolute;top:10px;left:10px;background:var(--chip);border:1px solid var(--chipLine);
  padding:4px 8px;border-radius:999px;font-size:12px;color:#cbd5e1; display:flex; gap:8px; align-items:center
}
.badge .miniBtn{
  font-size:11px; padding:3px 8px; border-radius:999px; border:1px solid rgba(255,255,255,.18);
  background:rgba(0,0,0,.12); color:var(--text); cursor:pointer;
}
.badge .miniBtn:active{transform:translateY(1px)}
.fliphint{position:absolute;bottom:10px;right:10px;font-size:11px;color:var(--muted)}
/* Play triangle button on front */
.playBtn{
  position:absolute; top:10px; right:10px;
  width:38px;height:38px;border-radius:12px;
  border:1px solid rgba(212,175,55,.35);
  background:rgba(19,32,48,.55);
  display:grid; place-items:center;
  cursor:pointer;
  box-shadow:inset 0 0 0 1px rgba(212,175,55,.08);
}
.playBtn:active{transform:translateY(1px)}
.playTri{
  width:0;height:0;
  border-top:8px solid transparent;
  border-bottom:8px solid transparent;
  border-left:13px solid #e9d8a6;
  margin-left:2px;
}
.playBtn.off{opacity:.35; cursor:not-allowed}
.playBtn.off .playTri{border-left-color:#cbd5e1}
.back h3{margin:10px 0 5px;font-size:14px;color:#e9d8a6}
.back p{margin:0 0 10px;font-size:14px;line-height:1.5}
.section{margin-bottom:4px}



.metaBox{
  width:100%;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(0,0,0,.16);
  border-radius:14px;
  padding:10px 10px;
  margin-bottom:10px;
}
.metaGrid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px 10px;
  font-size:12px;
}
.metaItem{color:var(--muted); line-height:1.25}
.metaItem b{color:var(--text); font-weight:650}
.metaWide{grid-column:1/-1}
.noteBox{
  width:100%;
  border:1px solid rgba(212,175,55,.22);
  background:rgba(212,175,55,.06);
  border-radius:14px;
  padding:10px 10px;
  margin:6px 0 12px;
  color:#e9d8a6;
  font-size:12.5px;
  line-height:1.45;
}

.card.flash{
  outline:2px solid rgba(212,175,55,.7);
  outline-offset:4px;
  border-radius:18px;
}
mark{
  background:rgba(255,212,121,.22);
  color:var(--text);
  padding:0 2px;
  border-radius:4px;
}

footer{padding:20px;text-align:center;color:var(--muted);font-size:12px}
a{color:#a3d5ff;text-decoration:none}

.smallHelp{
  margin:10px auto 0;
  max-width:980px;
  font-size:12px;
  color:var(--muted);
  text-align:center;
  line-height:1.45;
}
kbd{
  font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
  font-size:11px;
  padding:1px 6px;
  border:1px solid rgba(255,255,255,.16);
  border-bottom-color:rgba(255,255,255,.28);
  border-radius:6px;
  background:rgba(0,0,0,.18);
  color:var(--text);
}

/* Floating back-to-top */
.fab{
  position:fixed;
  right:14px;
  bottom:14px;
  z-index:9999;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.fab button{
  width:46px;height:46px;border-radius:16px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(19,32,48,.72);
  color:var(--text);
  cursor:pointer;
  box-shadow:0 10px 30px rgba(0,0,0,.25), inset 0 0 0 1px rgba(212,175,55,.08);
}
.fab button:active{transform:translateY(1px)}
.fab .up::before{
  content:"↑";
  font-size:18px;
  display:block;
  line-height:1;
}
.fab .home::before{
  content:"⌂";
  font-size:18px;
  display:block;
  line-height:1;
}
.fab button[disabled]{opacity:.35;cursor:not-allowed}

.foundation{
  margin:14px auto 16px;
  max-width:980px;
  border:1px solid rgba(212,175,55,.22);
  background:rgba(212,175,55,.06);
  border-radius:16px;
  padding:14px 14px;
}
.foundation h2{
  margin:0 0 8px;
  font-size:14px;
  color:#e9d8a6;
  letter-spacing:.25px;
}
.foundation p{
  margin:0 0 10px;
  font-size:13px;
  color:#e9d8a6;
  line-height:1.5;
}
.foundation .muted{
  color:rgba(232,238,247,.78);
}


.foundationToggle{
  display:flex;
  justify-content:space-between;
  align-items:center;
  cursor:pointer;
}
.foundationToggle button{
  background:transparent;
  border:1px solid rgba(212,175,55,.35);
  color:#e9d8a6;
  padding:4px 10px;
  border-radius:999px;
  font-size:12px;
  cursor:pointer;
}
.foundationContent{
  margin-top:8px;
  display:none;
}
.foundation.open .foundationContent{
  display:block;
}
.foundationPreview{
  font-size:13px;
  color:#e9d8a6;
  line-height:1.5;
}


/* ===== Foundation styling (user requested) ===== */
.foundation{
  border:1px solid rgba(255,255,255,.14);
  background:rgba(255,255,255,.04);
}
.foundation h2{
  font-size:18px;
  font-weight:800;
  color:#ffffff;
  letter-spacing:.2px;
}
.foundationToggle button{
  color:#ffffff;
  border-color:rgba(255,255,255,.22);
}
.foundationPreview{
  font-size:11px;
  color:inherit;
  line-height:1.35;
  opacity:.9;
}
.foundationContent{
  color:inherit;
}
.foundationPre{
  margin:10px 0 0;
  color:inherit;
  font-family:inherit;
  font-size:13px;
  line-height:1.5;
  white-space:pre-wrap;
}
.foundationKeyTitle{
  margin:10px 0 6px;
  font-size:14px;
  font-weight:800;
  color:inherit;
}
.foundationKeyList{
  margin:0 0 8px 0;
  padding:0;
  color:inherit;
}
.foundationKeyList li{
  list-style:none;
  margin:4px 0;
  padding-left:14px;
  position:relative;
}
.foundationKeyList li::before{
  content:"›";
  position:absolute;
  left:0;
  color:#e9d8a6;
  font-weight:900;
}


/* Key points sizing: same as body text, just bold */
.foundationKeyList li{
  font-size:13px;
  font-weight:800;
  line-height:1.45;
}
.foundationKeyTitle{
  font-size:13px;
  font-weight:900;
}
.foundationKeyList li b{font-weight:900;}

/* =========================
   Modal (Foundation Info)
   ========================= */
.modalOverlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.62);
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:10000;
}
.modalOverlay.open{ display:flex; }

.modalCard{
  width:min(980px, 100%);
  max-height:min(82vh, 720px);
  background:rgba(15,21,32,.98);
  border:1px solid rgba(255,255,255,.14);
  border-radius:16px;
  box-shadow:0 20px 60px rgba(0,0,0,.5);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.modalHeader{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  padding:12px 12px;
  border-bottom:1px solid rgba(255,255,255,.08);
}
.modalHeader h2{
  margin:0;
  font-size:14px;
  color:var(--text);
  letter-spacing:.2px;
}
.modalHeaderBtns{
  display:flex;
  gap:8px;
  align-items:center;
}

.modalBtn{
  background:rgba(19,32,48,.72);
  border:1px solid rgba(255,255,255,.14);
  color:var(--text);
  padding:8px 12px;
  border-radius:10px;
  cursor:pointer;
}
.modalBtn.primary{
  border-color:rgba(212,175,55,.35);
  box-shadow:inset 0 0 0 1px rgba(212,175,55,.08);
}
.modalBtn:active{ transform:translateY(1px); }

.modalBody{
  padding:14px 14px;
  overflow:auto;
  -webkit-overflow-scrolling:touch;
}

/* prevent background scroll while modal open */
body.modalOpen{
  overflow:hidden;
}


/* BACK SIDE ONLY: move badge (Top button) to top-right */
.back .badge{
  left: auto;
  right: 10px;
}


/* =========================
   Icon buttons (play/stop) in top controls
   ========================= */
.iconBtn{
  width:38px;
  height:38px;
  border-radius:12px;
  border:1px solid rgba(212,175,55,.35);
  background:rgba(19,32,48,.55);
  display:grid;
  place-items:center;
  cursor:pointer;
  box-shadow:inset 0 0 0 1px rgba(212,175,55,.08);
}
.iconBtn:active{transform:translateY(1px)}

/* Stop square (hidden by default) */
.stopSq{
  width:14px;
  height:14px;
  background:#e9d8a6;
  border-radius:3px;
  display:none;
}

/* Toggle play/stop visuals */
.playBtn.playing .playTri,
.iconBtn.playing .playTri{display:none}
.playBtn.playing .stopSq,
.iconBtn.playing .stopSq{display:block}

/* Keep triangle visible by default */
.playBtn .playTri,
.iconBtn .playTri{display:block}


/* ===== Light theme overrides ===== */
body.light header{border-bottom:1px solid rgba(11,15,20,.12)}
body.light p.sub{color:rgba(11,15,20,.75)}
body.light .tableWrap{background:rgba(255,246,220,.75); border-color:rgba(11,15,20,.12)}
body.light input[type="search"]{
  background:var(--panel);
  border-color:rgba(11,15,20,.18);
  color:var(--text);
}
body.light input[type="search"]::placeholder{color:rgba(11,15,20,.55)}
body.light .btn{
  background:rgba(255,242,207,.9);
  border-color:rgba(11,15,20,.18);
  color:var(--text);
}
body.light .btn.ghost{background:transparent}
body.light .pill{
  background:rgba(255,242,207,.75);
  border-color:rgba(11,15,20,.18);
  color:rgba(11,15,20,.75);
}
body.light .pill strong{color:var(--text)}
body.light .lettersTable{color:var(--text)}
body.light .cell{
  background:radial-gradient(120% 120% at 50% 0%, rgba(255,242,207,1) 0%, rgba(255,246,220,1) 60%, rgba(233,216,166,1) 100%);
  border-color:rgba(11,15,20,.18);
  box-shadow:inset 0 0 0 1px rgba(11,15,20,.05);
}
body.light .cellName{color:rgba(11,15,20,.9)}
body.light .cellMeaning{color:rgba(11,15,20,.85)}
body.light .cellMeta{color:rgba(11,15,20,.65)}
body.light .cellBadge{
  background:rgba(233,216,166,.55);
  border-color:rgba(11,15,20,.18);
  color:rgba(11,15,20,.85);
}
body.light .face{
  background:radial-gradient(120% 120% at 50% 0%, rgba(255,242,207,1) 0%, rgba(255,246,220,1) 60%, rgba(233,216,166,1) 100%);
  border-color:rgba(11,15,20,.18);
  box-shadow:0 10px 30px rgba(0,0,0,.12), inset 0 0 0 1px rgba(11,15,20,.05);
}
body.light .back h3{color:rgba(11,15,20,.9)}
body.light .back p{color:rgba(11,15,20,.85)}
body.light .meaning{color:rgba(11,15,20,.85)}
body.light .name{color:rgba(11,15,20,.9)}
body.light .badge{
  background:rgba(233,216,166,.55);
  border-color:rgba(11,15,20,.18);
  color:rgba(11,15,20,.85);
}
body.light .badge .miniBtn{
  border-color:rgba(11,15,20,.22);
  background:rgba(255,242,207,.75);
  color:rgba(11,15,20,.9);
}
body.light .fliphint{color:rgba(11,15,20,.55)}
body.light mark{
  background:rgba(11,15,20,.10);
  color:var(--text);
}
body.light .modalCard{
  background:rgba(255,246,220,.98);
  border-color:rgba(11,15,20,.14);
}
body.light .modalHeader{border-bottom:1px solid rgba(11,15,20,.12)}
body.light .modalBtn{
  background:rgba(255,242,207,.9);
  border-color:rgba(11,15,20,.18);
  color:var(--text);
}
body.light .iconBtn, body.light .playBtn{
  background:rgba(255,242,207,.9);
  border-color:rgba(11,15,20,.22);
}
body.light .playTri{border-left-color:rgba(11,15,20,.85)}
body.light .stopSq{background:rgba(11,15,20,.85)}
body.light footer{color:rgba(11,15,20,.65)}
body.light a{color:rgba(11,15,20,.85)}



/* === FIX: Force 3 cells per row in Table view (Android phone/WebView) === */
.lettersTable td{
  width:33.3333%;
  vertical-align:top;
}

@media (max-width:720px){
  .lettersTable{border-spacing:8px;}
  .cell{padding:8px 8px;}
}

/* ===== Android WebView back-side fix (additive only) =====
   Android WebView sometimes shows the back face already scrolled, which makes the header rows
   (Letter / Name) look cut off. These rules ensure content starts below the badge and can scroll smoothly. */
.back{
  justify-content:flex-start;          /* override .face center alignment */
  padding-top:72px;                   /* leave space below the badge (slightly more for WebView) */
  scroll-padding-top:72px;            /* when focusing/scrolling, keep top content visible */
  -webkit-overflow-scrolling:touch;
}

body.light .noteBox{
  color: rgba(11,15,20,.88);
  border-color: rgba(11,15,20,.18);
  background: rgba(11,15,20,.06);
}

/* =========================
   Guided Help / Tour (added)
   ========================= */
.guideOverlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.65);
  z-index:20000;
}

.guideTooltip{
  position:fixed;
  z-index:20002;
  width:min(360px, calc(100vw - 24px));
  max-width:min(360px, calc(100vw - 24px));
  background:var(--panel);
  color:var(--text);
  border:1px solid rgba(255,255,255,.12);
  border-radius:14px;
  box-shadow:0 20px 60px rgba(0,0,0,.55);
  padding:12px 12px;
  font-size:13px;
  line-height:1.35;
  white-space:normal;
  word-break:normal;
}

body.light .guideOverlay{ background:rgba(0,0,0,.45); }
body.light .guideTooltip{
  border-color:rgba(11,15,20,.18);
  box-shadow:0 18px 50px rgba(0,0,0,.18);
}

/* highlight target */
.guideFocus{
  position:relative;
  z-index:20003 !important;
  outline:3px solid rgba(212,175,55,.75);
  outline-offset:6px;
  border-radius:14px;
}

/* ensure Help/Feedback icons visible on both themes */
#guideBtn,#feedbackBtn{
  color:var(--text);
  font-weight:900;
  font-size:16px;
  line-height:1;
}
