/* Study screens. Builds on styles.css — same tokens, same light/dark, same
   type — so moving between the book and the deck does not feel like moving
   between two applications. */

:root {
  --good: #1f8a5f;
  --good-soft: #e3f4ec;
  --warn: #b07d19;
  --warn-soft: #fbf0d8;
  --bad: #b3402f;
  --bad-soft: #fbe7e3;
}
html[data-theme="dark"] {
  --good: #4bc48f;
  --good-soft: #12352a;
  --warn: #e0aa4a;
  --warn-soft: #34290f;
  --bad: #e8705c;
  --bad-soft: #3a1d18;
}

body.study #main {
  padding: calc(var(--head-h) + 22px) 20px 60px;
  max-width: 940px;
  margin: 0 auto;
}
body.study .brand strong { color: var(--accent); }

.duebadge {
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 3px 10px; font-size: 12px; font-weight: 700; white-space: nowrap;
}

.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; margin: 0 0 18px; box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 4px; font-size: 15px; color: var(--accent); }

/* ---------- the numbers ---------- */
.statrow {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px; margin: 0 0 16px;
}
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 12px; text-align: center; box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 26px; line-height: 1.1; color: var(--accent); }
.stat span { font-size: 11.5px; color: var(--muted); text-transform: uppercase;
             letter-spacing: .04em; }

.actions { display: flex; gap: 10px; margin: 0 0 18px; flex-wrap: wrap; }
.actions button, .donebox button, .drillfilter button {
  padding: 11px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer;
}
.actions button:hover, .donebox button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: none; border: 1px solid var(--line); color: var(--bad);
                padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer;
                margin-top: 14px; }
button.link { background: none; border: 0; color: var(--accent); font: inherit;
              cursor: pointer; padding: 0; text-decoration: underline; }

/* ---------- forecast ---------- */
.forecast {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  align-items: end; gap: 5px; height: 118px;
}
.fcol { display: flex; flex-direction: column; align-items: center; height: 100%;
        justify-content: flex-end; gap: 4px; }
.fnum { font-size: 10.5px; color: var(--muted); height: 13px; }
.fbar { width: 100%; background: var(--accent-soft); border: 1px solid var(--line);
        border-bottom: 0; border-radius: 4px 4px 0 0; min-height: 2px; }
.fbar.now { background: var(--accent); border-color: var(--accent); }
.fday { font-size: 10.5px; color: var(--muted); }

/* ---------- chapters ---------- */
.chapters { display: grid; gap: 8px; }
.chrow {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  cursor: pointer; background: var(--bg);
}
.chrow:hover { border-color: var(--accent); }
.chrow.only { border-color: var(--accent); background: var(--accent-soft); }
.chhead { display: flex; justify-content: space-between; align-items: baseline;
          gap: 10px; margin-bottom: 7px; }
.chname { font-weight: 600; font-size: 14px; }
.chcount { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar { height: 7px; border-radius: 999px; background: var(--line);
       overflow: hidden; display: flex; }
.seg.strong { background: var(--good); }
.seg.weak { background: var(--warn); }
.chfoot { display: flex; justify-content: space-between; margin-top: 6px;
          font-size: 12px; color: var(--muted); }

/* ---------- settings ---------- */
.settings { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 14px; }
.settings label { display: flex; flex-direction: column; gap: 5px; font-size: 13px;
                  color: var(--muted); }
.settings input, .settings select, .drillfilter select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-size: 14px;
}
.types { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
         gap: 8px; }
.typebox { display: flex; gap: 9px; align-items: flex-start; padding: 9px 11px;
           border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.typebox input { margin-top: 3px; }
.typebox b { display: block; font-size: 13.5px; font-weight: 600; }
.typebox small { color: var(--muted); font-size: 12px; }

/* ---------- the card ---------- */
.qbar { display: flex; justify-content: space-between; font-size: 12.5px;
        color: var(--muted); margin-bottom: 10px; }
.qcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 26px 28px; box-shadow: var(--shadow); min-height: 220px;
}
.chip {
  display: inline-block; font-size: 11px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--label); background: var(--accent-soft);
  border-radius: 999px; padding: 3px 10px; margin-bottom: 16px; font-weight: 700;
}
.front .topic { font-size: 24px; font-weight: 700; line-height: 1.25; }
.front .ask {
  margin-top: 8px; font-size: 13px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--label);
}
.front .cue { font-size: 17px; line-height: 1.5; }
.front .chain { font-size: 19px; line-height: 1.5; font-weight: 600; }
.front .ctx { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.back {
  margin-top: 20px; padding-top: 18px; border-top: 2px solid var(--accent-soft);
  font-size: 17px; line-height: 1.6;
}
.cardfoot {
  margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  font-size: 12.5px; color: var(--muted);
}
.cardfoot a { color: var(--accent); }

/* ---------- grading ---------- */
.gradebar { display: flex; gap: 8px; margin-top: 16px; }
.gradebar button {
  flex: 1; padding: 13px 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer; display: flex; flex-direction: column; align-items: center;
  gap: 3px;
}
.gradebar button small { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.gradebar button.wide { flex: 1; flex-direction: row; gap: 10px; }
.gradebar .g1:hover { border-color: var(--bad); background: var(--bad-soft); }
.gradebar .g2:hover { border-color: var(--warn); background: var(--warn-soft); }
.gradebar .g3:hover, .gradebar .g4:hover { border-color: var(--good);
                                            background: var(--good-soft); }
kbd {
  font: inherit; font-size: 11px; border: 1px solid currentColor; opacity: .55;
  border-radius: 4px; padding: 0 5px;
}

.donebox {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 30px; text-align: center; box-shadow: var(--shadow);
}
.donebox h2 { margin: 0 0 8px; font-size: 20px; color: var(--accent); }
.donebox button { margin: 6px 4px 0; }

/* ---------- drill ---------- */
.drillhead h2 { margin: 0 0 4px; font-size: 19px; }
.drillfilter { display: flex; gap: 10px; margin: 0 0 16px; flex-wrap: wrap; }
.drilllist { display: grid; gap: 7px; }
.drillitem {
  text-align: left; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel); color: var(--ink); font: inherit;
  cursor: pointer;
}
.drillitem:hover { border-color: var(--accent); }
.drillitem b { display: block; font-size: 14px; }
.drillitem small { color: var(--muted); font-size: 12px; }

.drillcols { display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
             margin: 10px 0 4px; }
.colpick {
  font: inherit; font-size: 11.5px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  cursor: pointer;
}
.colpick.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.tablewrap { overflow-x: auto; margin: 12px 0; -webkit-overflow-scrolling: touch; }
table.fa.drill {
  width: 100%; border-collapse: collapse; font-size: 14px;
  /* On a phone a five-column table has nowhere to go. Without a floor the
     table's box obeys width:100% while its cells still demand ~720px, so the
     columns are crushed to unreadable slivers *and* the wrapper never scrolls -
     it measures the box, not the overflowing content. A min-width lets the box
     grow, which is what gives `.tablewrap` something to scroll. */
  min-width: 620px;
}
table.fa.drill th, table.fa.drill td {
  border: 1px solid var(--line); padding: 8px 10px; text-align: left;
  vertical-align: top;
}
table.fa.drill th { background: var(--accent-soft); font-size: 12px;
                    text-transform: uppercase; letter-spacing: .03em; }
table.fa.drill th.asked { background: var(--accent); color: #fff; }
table.fa.drill tr.done td { opacity: .55; }
table.fa.drill tr.at { outline: 2px solid var(--accent); }
table.fa.drill tr.at td { background: var(--accent-soft); }
td.asked.hidden { text-align: center; color: var(--muted); font-weight: 700;
                  background: repeating-linear-gradient(
                    45deg, transparent, transparent 5px,
                    var(--line) 5px, var(--line) 6px); }
td.asked.open { color: var(--good); font-weight: 600; }

@media (max-width: 640px) {
  .qcard { padding: 20px 18px; }
  .front .topic { font-size: 20px; }
  .gradebar button { padding: 11px 4px; font-size: 13px; }
  body.study #main { padding-left: 12px; padding-right: 12px; }
}

/* ---------- figures on a card ---------- */
.plate {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center;
  gap: 12px; margin: 14px 0 2px;
}
.plate.big { margin: 4px 0 14px; }
.cardfig { margin: 0; flex: 0 1 auto; min-width: 0; max-width: 100%; }
.cardfig img {
  width: 100%; height: auto; display: block; border-radius: 6px;
  border: 1px solid var(--line); background: #fff; cursor: zoom-in;
}
/* The question is the picture, so it gets the room the answer usually takes. */
.plate.big .cardfig { min-width: min(280px, 100%); }
.back .answer { margin: 0; }

#lightbox {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  padding: 24px; background: rgba(8, 14, 20, .82); cursor: zoom-out;
}
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; background: #fff; }

td.cellpic { text-align: center; }
td.cellpic img {
  max-width: 130px; width: 100%; height: auto; border-radius: 4px;
  cursor: zoom-in; display: inline-block;
}

.clearfilter {
  width: 100%; text-align: left; padding: 9px 12px; margin-bottom: 4px;
  border: 1px solid var(--accent); border-radius: 9px; cursor: pointer;
  background: var(--accent-soft); color: var(--accent); font: inherit;
  font-size: 13px; font-weight: 600;
}
