/* Study Plan — phone first, English LTR. Layout: top bar, one scrolling column, bottom nav. */
@font-face { font-family: "Thmanyah Sans"; src: url("/fonts/thmanyah-sans-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Thmanyah Sans"; src: url("/fonts/thmanyah-sans-700.woff2") format("woff2"); font-weight: 600 700; font-display: swap; }
@font-face { font-family: "Schibsted Grotesk"; src: url("/fonts/schibsted-grotesk-latin-var.woff2") format("woff2"); font-weight: 400 900; font-display: swap; unicode-range: U+0000-024F, U+2000-206F, U+2212; }

:root {
  --bg: #F2F4F1; --surface: #FFFFFF; --ink: #16201D; --muted: #5F6C67; --faint: #E4E9E5; --line: #D6DDD8;
  --accent: #7E2236; --accent-soft: #F4E3E6; --on-accent: #FFFFFF; --good: #0D6E5B; --good-soft: #E0EEE8; --uw: #4357C8; --uw-soft: #E6E9FA;
  --weight: #B07418; --weight-soft: #F5EBD8; --low: #B4462F; --low-soft: #F7E3DD;
  --shadow: 0 12px 32px rgba(22, 32, 29, .16);
  --f-body: "Schibsted Grotesk", "Thmanyah Sans", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  --f-num: "Schibsted Grotesk", system-ui, sans-serif;
  --f-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0F1513; --surface: #18201D; --ink: #E5ECE9; --muted: #95A39D; --faint: #222C29; --line: #2C3834;
  --accent: #E58A9A; --accent-soft: #3A1E25; --on-accent: #2B0A12; --good: #4FC3A6; --good-soft: #1B342E; --uw: #8D9CF2; --uw-soft: #232948;
  --weight: #E0A955; --weight-soft: #33291A; --low: #EE8D76; --low-soft: #3A221D;
  --shadow: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
/* Arabic someone types (a name, a lesson) renders in Thmanyah: Schibsted only covers Latin, so the stack falls through. */

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.6; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
input, select { font-size: 16px; } /* iOS zooms on smaller focused fields */
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.en { direction: ltr; unicode-bidi: isolate; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }

.boot { min-height: 100vh; display: grid; place-items: center; }

/* ---------- shell */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); }
.top-in { max-width: 860px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: baseline; gap: 8px; direction: ltr; }
.brand b { font-weight: 800; letter-spacing: -.01em; font-size: 1.05rem; }
.brand span { font-size: .72rem; letter-spacing: .14em; color: var(--accent); font-weight: 600; }
.who { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 5px 12px 5px 6px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .85rem; }
.av { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none; }

main { max-width: 860px; margin: 0 auto; padding-block: 22px calc(96px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 26px; }

.nav { position: fixed; inset: auto 0 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  display: flex; justify-content: center; gap: 4px; }
.nav button { flex: 0 1 140px; border: 0; background: none; border-radius: 12px; padding: 7px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .74rem; color: var(--muted); cursor: pointer; position: relative; }
.nav button svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button[aria-current="page"] { color: var(--accent); font-weight: 600; }
.nav .badge { position: absolute; top: 2px; inset-inline-start: calc(50% + 6px); min-width: 17px; height: 17px; border-radius: 99px; background: var(--low); color: #fff; font-size: .65rem; display: grid; place-items: center; padding: 0 4px; font-family: var(--f-num); }

/* ---------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 22px; }
.auth-head { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-head .logo { width: 76px; height: 76px; border-radius: 22%; box-shadow: 0 10px 26px rgba(94, 20, 38, .28); margin-bottom: 4px; }
.auth-head .eyebrow { font-size: .7rem; letter-spacing: .16em; color: var(--accent); font-weight: 600; direction: ltr; }
.auth-head h1 { margin: 0; font-size: 1.9rem; font-weight: 800; letter-spacing: -.01em; direction: ltr; }
.auth-head p { margin: 0; color: var(--muted); font-size: .9rem; }
.form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.input { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.input.ltr { direction: ltr; text-align: left; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .input { flex: 1; min-width: 0; }
.err { color: var(--low); font-size: .85rem; min-height: 1.2em; margin: 0; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 11px; padding: 10px 16px; cursor: pointer; font-weight: 600; font-size: .9rem; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--low); border-color: color-mix(in srgb, var(--low) 40%, var(--line)); }
.btn.danger.solid { background: var(--low); color: #fff; border-color: var(--low); }
.btn.small { padding: 6px 11px; font-size: .8rem; border-radius: 9px; }
.btn.ghost { border-color: transparent; background: none; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { width: 100%; padding-block: 12px; }

/* ---------- dashboard */
.dash { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding-block: 26px 20px; padding-inline: clamp(16px, 4vw, 32px); display: flex; flex-direction: column; align-items: center; gap: 20px; }
.dash-title { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.dash-title .eyebrow { font-size: .68rem; letter-spacing: .16em; color: var(--accent); font-weight: 600; direction: ltr; }
.dash-title h1 { margin: 0; font-size: clamp(1.45rem, 4.5vw, 1.9rem); font-weight: 800; line-height: 1.2; }
.ring { position: relative; width: 176px; height: 176px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring .track { stroke: var(--faint); }
.ring .s { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray .5s; }
.ring .u { stroke: var(--uw); stroke-linecap: round; transition: stroke-dasharray .5s, stroke-dashoffset .5s; }
.ring .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .pct { font-family: var(--f-num); font-weight: 800; font-size: 2.5rem; line-height: 1; font-variant-numeric: tabular-nums; direction: ltr; }
.ring .lbl { font-size: .76rem; color: var(--muted); margin-top: 6px; }
.next { font-size: .88rem; color: var(--muted); text-align: center; margin-top: -6px; }
.next b { color: var(--ink); font-weight: 600; }
.stats { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat { padding: 13px 6px; text-align: center; min-width: 0; }
.stat + .stat { border-inline-start: 1px solid var(--line); }
.stat .v { font-family: var(--f-num); font-weight: 700; font-size: 1.4rem; font-variant-numeric: tabular-nums; direction: ltr; line-height: 1.2; }
.stat .v small { font-size: .78rem; color: var(--muted); font-weight: 400; }
.stat .k { font-size: .72rem; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 2px; flex: none; display: inline-block; }
.dot.s { background: var(--accent); } .dot.u { background: var(--uw); } .dot.w { background: var(--weight); }
@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-inline-start: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
}
.charts { width: 100%; display: flex; flex-direction: column; gap: 20px; }
.chart h2 { font-size: .8rem; font-weight: 600; margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.legend { display: flex; gap: 12px; font-weight: 400; color: var(--muted); font-size: .72rem; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.plot { position: relative; height: 140px; display: flex; gap: 3px; align-items: flex-end; padding-inline-start: 30px; }
.grid { position: absolute; inset: 0; pointer-events: none; }
.grid i { position: absolute; inset-inline: 30px 0; border-top: 1px dashed var(--line); }
.grid b { position: absolute; left: 0; font-family: var(--f-num); font-size: .62rem; color: var(--muted); font-weight: 500; transform: translateY(-50%); direction: ltr; width: 25px; text-align: right; }
.grid .target { border-top: 1.5px dashed var(--weight); }
.col { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; z-index: 1; border-radius: 4px 4px 0 0; background: var(--faint); }
.col .seg { width: 100%; }
.col .seg.u { background: var(--uw); border-radius: 4px 4px 0 0; }
.col .seg.s { background: var(--accent); }
.col .seg.u + .seg.s { border-radius: 0; }
.col .seg.s:first-child { border-radius: 4px 4px 0 0; }
.col.sc { background: transparent; }
.col.sc .seg { border-radius: 4px 4px 0 0; background: var(--good); } /* a good score stays green: maroon would read like the red 'low' */
.col.sc .seg.low { background: var(--low); }
.col.sc .seg.mid { background: var(--weight); }
.col .tip { position: absolute; bottom: calc(100% + 3px); left: 50%; transform: translateX(-50%); font-family: var(--f-num); font-size: .6rem; color: var(--muted); direction: ltr; white-space: nowrap; }
.xl { display: flex; gap: 3px; padding-inline-start: 30px; margin-top: 6px; }
.xl span { flex: 1; min-width: 0; font-family: var(--f-num); font-size: .56rem; color: var(--muted); writing-mode: vertical-rl; transform: rotate(180deg); height: 46px; display: flex; align-items: center; letter-spacing: .02em; overflow: hidden; }
.empty { min-height: 120px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: .85rem; border: 1px dashed var(--line); border-radius: 12px; padding: 16px; }

/* ---------- systems */
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.sec-head h2 { font-size: 1.15rem; font-weight: 700; margin: 0; }
.sec-head .hint { font-size: .78rem; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 8px; }
details.sys { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
details.sys[data-complete="1"] { border-color: var(--accent); }
.dragging { box-shadow: var(--shadow); border-color: var(--uw) !important; position: relative; z-index: 5; }
summary { list-style: none; cursor: pointer; padding: 11px 12px; display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 10px; align-items: center; }
summary::-webkit-details-marker { display: none; }
summary:focus-visible { border-radius: 12px; }
.ro summary { grid-template-columns: auto minmax(0, 1fr) auto; }
.handle { width: 28px; height: 34px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); cursor: grab; touch-action: none; border-radius: 6px; padding: 0; flex: none; }
.handle:active { cursor: grabbing; }
.handle svg { width: 10px; height: 16px; fill: currentColor; }
.idx { font-family: var(--f-num); font-size: .78rem; color: var(--muted); width: 2.2ch; text-align: center; font-variant-numeric: tabular-nums; }
.name { min-width: 0; }
.name strong { display: block; font-size: .98rem; font-weight: 600; overflow-wrap: anywhere; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 3px; }
.chip { display: inline-block; font-family: var(--f-num); font-size: .68rem; padding: 0 7px; border-radius: 99px; background: var(--weight-soft); color: var(--weight); }
.chip.uw { background: var(--uw-soft); color: var(--uw); }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; min-width: 70px; }
.cnt { font-family: var(--f-num); font-size: .8rem; color: var(--muted); direction: ltr; font-variant-numeric: tabular-nums; }
details.sys[data-complete="1"] .cnt { color: var(--accent); font-weight: 700; }
.mbar { width: 70px; height: 5px; background: var(--faint); border-radius: 99px; overflow: hidden; display: flex; }
.mbar i { display: block; height: 100%; }
.mbar .s { background: var(--accent); } .mbar .u { background: var(--uw); }
.body { padding: 14px 14px 16px; display: flex; flex-direction: column; gap: 16px; border-top: 1px solid var(--line); }
.phase h3 { font-size: .78rem; color: var(--muted); margin: 0 0 6px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.checks { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }
.checks li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; border-radius: 8px; background: var(--surface); }
.checks label { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 10px; align-items: start; padding: 6px 4px; border-radius: 8px; cursor: pointer; min-width: 0; }
.checks label:hover { background: var(--bg); }
.checks input[type="checkbox"] { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--accent); }
.phase.uwp input[type="checkbox"] { accent-color: var(--uw); }
.checks input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.checks .t { overflow-wrap: anywhere; }
.ltr-auto { unicode-bidi: plaintext; text-align: start; }
.input.ltr-auto { text-align: start; }
.li-tools { display: flex; gap: 2px; align-items: center; }
.icon-btn { width: 32px; height: 32px; border: 0; background: none; border-radius: 8px; display: grid; place-items: center; color: var(--muted); cursor: pointer; padding: 0; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
.icon-btn.del:hover { color: var(--low); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
.li-edit { display: flex; gap: 6px; padding: 4px 0; }
.li-edit .input { padding: 7px 10px; }
.add-row { display: flex; gap: 6px; margin-top: 6px; }
.add-row .input { padding: 8px 11px; flex: 1; min-width: 0; }
.score { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: .86rem; }
.score .input { width: 92px; padding: 7px 10px; direction: ltr; font-family: var(--f-num); }
.tag { font-size: .74rem; padding: 2px 9px; border-radius: 99px; font-weight: 600; }
.tag.ok { background: var(--good-soft); color: var(--good); }
.tag.mid { background: var(--weight-soft); color: var(--weight); }
.tag.low { background: var(--low-soft); color: var(--low); }
.sys-edit { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding-bottom: 14px; border-bottom: 1px dashed var(--line); }
.sys-edit .wide { grid-column: 1 / -1; }
.sys-edit .input { padding: 8px 10px; }
.sys-edit .acts { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
@media (max-width: 480px) { .sys-edit { grid-template-columns: minmax(0, 1fr); } }
.confirm { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .85rem; color: var(--low); }

.editbar { background: var(--uw-soft); color: var(--uw); border-radius: 12px; padding: 10px 14px; font-size: .84rem; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- friends */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel h3 { margin: 0; font-size: .95rem; font-weight: 700; }
.req { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.req:first-of-type { border-top: 0; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .nm { font-weight: 600; }
.person .un { font-size: .78rem; color: var(--muted); direction: ltr; display: block; }
.board { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; cursor: pointer; text-align: start; width: 100%; }
.card.me { border-color: var(--accent); cursor: default; }
.card .rank { font-family: var(--f-num); font-weight: 700; color: var(--muted); width: 2ch; text-align: center; }
.card .meta { font-size: .76rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.card .bar { height: 6px; background: var(--faint); border-radius: 99px; overflow: hidden; display: flex; margin-top: 8px; }
.card .bar i { display: block; height: 100%; }
.card .bar .s { background: var(--accent); } .card .bar .u { background: var(--uw); }
.card .big { font-family: var(--f-num); font-weight: 800; font-size: 1.45rem; direction: ltr; font-variant-numeric: tabular-nums; }
.back { align-self: flex-start; }

/* ---------- admin */
.users { display: flex; flex-direction: column; }
.urow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.urow:first-child { border-top: 0; }
.badge-role { font-size: .68rem; padding: 0 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; margin-inline-start: 6px; }
.badge-off { background: var(--low-soft); color: var(--low); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.note { font-size: .8rem; color: var(--muted); margin: 0; }

/* ---------- sheet + toast */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .38); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: var(--surface); width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; max-height: 88vh; overflow: auto;
  padding: 18px max(18px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 620px) { .sheet { align-items: center; } .sheet-card { border-radius: 20px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-head h3 { margin: 0; font-size: 1.05rem; }
.seg-ctl { display: flex; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }
.seg-ctl button { flex: 1; border: 0; background: none; padding: 9px; cursor: pointer; font-size: .85rem; }
.seg-ctl button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.hr { border: 0; border-top: 1px solid var(--line); margin: 0; width: 100%; }
#toast { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .88rem; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
#toast.bad { background: var(--low); color: #fff; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
span.handle { cursor: default; }
