/* PMG Companion Study - styles
   Light and dark follow the phone setting. Sizes are tuned for 360-412px wide phones. */

:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1c2530;
  --ink-2: #4a5663;
  --ink-3: #6b7682;
  --line: #ddd6c8;
  --brand: #1d3b5c;
  --brand-ink: #ffffff;
  --accent: #b5651d;
  --accent-soft: #f6e7d6;
  --ok: #2e7d4f;
  --ok-soft: #e1f1e7;
  --warn: #9b2c2c;
  --warn-soft: #fbe6e3;
  --quote: #efe9dc;
  --focus: #2f6db3;
  --shadow: 0 1px 2px rgba(20, 30, 40, .08), 0 2px 8px rgba(20, 30, 40, .06);
  --radius: 14px;
  --tap: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c;
    --surface: #18212b;
    --surface-2: #1d2833;
    --ink: #e9edf1;
    --ink-2: #bcc6d0;
    --ink-3: #93a0ad;
    --line: #2d3a47;
    --brand: #9cc3ea;
    --brand-ink: #0f151c;
    --accent: #e8a867;
    --accent-soft: #3a2a1b;
    --ok: #6fcf97;
    --ok-soft: #173325;
    --warn: #f19a8f;
    --warn-soft: #3b1f1c;
    --quote: #222d38;
    --focus: #8ab8ee;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  min-height: 56px; padding: 4px 8px;
  padding-top: max(4px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.topbar-title {
  flex: 1; margin: 0 8px; font-size: 18px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.15); }
.icon-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

main { max-width: 640px; margin: 0 auto; padding: 16px 16px 120px; outline: none; }
.loading { color: var(--ink-3); text-align: center; margin-top: 30vh; }

/* ---------- basic blocks ---------- */
h2 { font-size: 22px; line-height: 1.25; margin: 0 0 8px; }
h3 { font-size: 19px; line-height: 1.3; margin: 0 0 6px; }
p { margin: 0 0 12px; }
.muted { color: var(--ink-2); }
.small { font-size: 15px; }
.eyebrow {
  font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent); margin: 0 0 4px;
}
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; background: var(--surface-2); }
.stack > * + * { margin-top: 10px; }
ul.bullets { margin: 0 0 8px; padding-left: 22px; }
ul.bullets li { margin: 4px 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px;
  border: 1.5px solid var(--brand); border-radius: 999px;
  background: var(--brand); color: var(--brand-ink);
  font-weight: 650; cursor: pointer; text-decoration: none; text-align: center;
}
.btn.secondary { background: transparent; color: var(--brand); }
.btn.quiet { background: transparent; border-color: var(--line); color: var(--ink); font-weight: 550; }
.btn.block { display: flex; width: 100%; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; }
.linklist { list-style: none; margin: 0; padding: 0; }
.linklist a, .linklist button {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  min-height: 52px; padding: 12px 4px; border: 0; border-bottom: 1px solid var(--line);
  background: none; color: var(--ink); text-decoration: none; text-align: left; cursor: pointer;
}
.linklist li:last-child a, .linklist li:last-child button { border-bottom: 0; }
.linklist a::after, .linklist button::after { content: "›"; font-size: 24px; color: var(--ink-3); margin-left: 8px; }

/* ---------- forms ---------- */
label.field { display: block; margin: 0 0 16px; }
.field-label { display: block; font-weight: 650; margin-bottom: 6px; }
.field-help { display: block; font-size: 15px; color: var(--ink-2); margin-top: 4px; }
input[type=text], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
  font-size: 17px;
}
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; }
.name-row { display: flex; gap: 8px; }
.name-row select { width: 7.2em; flex: none; }
.name-row input { flex: 1; min-width: 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.switch { position: relative; width: 56px; height: 32px; flex: none; }
.switch input { position: absolute; top: 0; right: 0; bottom: 0; left: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.switch span { position: absolute; top: 0; right: 0; bottom: 0; left: 0; border-radius: 999px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(24px); }
.switch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.error { color: var(--warn); font-weight: 600; }

/* area picker */
.area-results { list-style: none; margin: 6px 0 0; padding: 0; max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.area-results:empty { display: none; }
.area-results button { display: block; width: 100%; min-height: var(--tap); padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.area-results li:last-child button { border-bottom: 0; }
.area-results button:active { background: var(--surface-2); }
.area-results .sub { display: block; font-size: 14px; color: var(--ink-3); }
.area-chosen { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1.5px solid var(--ok); border-radius: 10px; background: var(--ok-soft); }
.area-chosen strong { display: block; }

/* ---------- home ---------- */
.hello { margin-bottom: 14px; }
.hello h2 { margin-bottom: 2px; }
.current-week { border-left: 6px solid var(--accent); }
.week-list { list-style: none; margin: 0; padding: 0; }
.week-list a {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 10px 4px;
  border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none;
}
.week-list li:last-child a { border-bottom: 0; }
.week-list .wk-num { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); font-weight: 700; }
.week-list .wk-text { flex: 1; min-width: 0; }
.week-list .wk-title { display: block; font-weight: 600; line-height: 1.3; }
.week-list .wk-sub { display: block; font-size: 14px; color: var(--ink-3); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--ok); }

/* ---------- week ---------- */
.week-head h2 { font-size: 24px; }
.section { scroll-margin-top: 64px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.section-head .titles { flex: 1; min-width: 0; }
.section-head h3 { margin: 0; }
.badge { display: inline-block; font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; margin-top: 4px; }
.badge.own { background: var(--accent-soft); color: var(--accent); }
.badge.together { background: var(--ok-soft); color: var(--ok); }
.time-label { font-size: 14px; color: var(--ink-3); display: block; }
.ring { width: 48px; height: 48px; flex: none; position: relative; }
.ring svg { width: 48px; height: 48px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--line); }
.ring .fill { stroke: var(--ok); stroke-linecap: round; transition: stroke-dashoffset .3s; }
.ring span { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.intro { font-style: italic; color: var(--ink-2); }

/* checkable items */
.check {
  display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line);
}
.check:first-of-type { border-top: 0; }
.check input[type=checkbox] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 30px; height: 30px; margin: 0; border: 2px solid var(--ink-3); border-radius: 8px; background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
}
.check input[type=checkbox]::after { content: ""; width: 9px; height: 16px; border: solid var(--brand-ink); border-width: 0 3.5px 3.5px 0; transform: rotate(45deg) translate(-1px, -2px); opacity: 0; }
.check input[type=checkbox]:checked { background: var(--ok); border-color: var(--ok); }
.check input[type=checkbox]:checked::after { opacity: 1; border-color: #fff; }
.check .check-body { flex: 1; min-width: 0; }
.check label.check-text { display: block; cursor: pointer; padding-top: 2px; }
.check input:checked ~ .check-body label.check-text { color: var(--ink-2); }
.hit { position: relative; }
.hit::before { content: ""; position: absolute; top: -9px; right: -9px; bottom: -9px; left: -9px; } /* larger tap area for small boxes */

textarea.answer { min-height: 96px; margin-top: 8px; resize: vertical; line-height: 1.45; }
.note { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--ink-3); margin-top: 4px; }
.saved { color: var(--ok); font-weight: 600; opacity: 0; transition: opacity .3s; }
.saved.show { opacity: 1; }

.choose { font-size: 15px; font-weight: 600; padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); margin-bottom: 6px; }
.choose.met { background: var(--ok-soft); color: var(--ok); }

/* timers */
.timer {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); margin: 4px 0 12px;
}
.timer .t-time { font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700; min-width: 4.2ch; }
.timer .t-label { font-size: 14px; color: var(--ink-3); flex-basis: 100%; margin-top: -4px; }
.timer .btn { min-height: 44px; padding: 8px 16px; }
.timer.running { border-color: var(--accent); background: var(--accent-soft); }
.timer.finished { border-color: var(--warn); background: var(--warn-soft); }

/* case studies */
.case { border-top: 3px solid var(--line); padding-top: 14px; margin-top: 18px; }
.case:first-of-type { border-top: 0; margin-top: 4px; padding-top: 0; }
.case-tag { font-size: 13px; font-weight: 700; letter-spacing: .05em; color: var(--accent); margin: 0 0 8px; }
blockquote { margin: 0 0 12px; padding: 12px 14px; border-left: 4px solid var(--accent); background: var(--quote); border-radius: 0 10px 10px 0; font-style: italic; }
.talk { margin: 4px 0 12px; }
.talk h4, .box h4 { font-size: 15px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; margin: 0 0 6px; color: var(--ink-2); }
.roleplay { padding: 12px 14px; border-radius: 12px; border: 1px dashed var(--ink-3); margin-bottom: 8px; }
.box { padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); margin: 8px 0 10px; }
.box.weigh { border-color: var(--brand); }
.box.gethelp { background: var(--warn-soft); border-color: var(--warn); }
.box.gethelp h4 { color: var(--warn); }
.box.lang { border-color: var(--accent); }

/* tracker grid */
.tracker { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: 6px; }
.tracker th { font-size: 12px; font-weight: 700; color: var(--ink-3); padding: 4px 0; }
.tracker th.row-label { text-align: left; font-size: 14px; color: var(--ink); font-weight: 600; width: 100%; padding: 10px 0 2px; }
.tracker td { text-align: center; padding: 4px 0 8px; }
.tracker input[type=checkbox] {
  appearance: none; -webkit-appearance: none; width: 34px; height: 34px; margin: 0;
  border: 2px solid var(--ink-3); border-radius: 8px; background: var(--surface); cursor: pointer;
}
.tracker input[type=checkbox]:checked { background: var(--ok); border-color: var(--ok); box-shadow: inset 0 0 0 4px var(--surface); }

.last-goal { border-left: 6px solid var(--brand); }

/* get-help button */
.help-fab {
  position: fixed; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 30;
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 10px 16px;
  border: 0; border-radius: 999px; background: var(--warn); color: #fff; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
@media (prefers-color-scheme: dark) { .help-fab { color: #1a0f0e; } }
.help-fab svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }

/* dialog + toast */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 48px); padding: 0;
  border: 0; border-radius: 16px; background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(10, 15, 20, .55); }
.dialog-body { padding: 20px; }
.dialog-body h2 { margin-bottom: 10px; }
.dialog-body .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.dialog-body textarea { min-height: 200px; font-size: 14px; }
.alarm h2 { color: var(--warn); font-size: 26px; }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 40;
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}

table.budget { width: 100%; border-collapse: collapse; font-size: 15px; }
table.budget td { padding: 8px 4px; border-top: 1px solid var(--line); vertical-align: top; }
table.budget td:last-child { white-space: nowrap; text-align: right; font-weight: 600; }
.privacy h3 { margin-top: 16px; }

div.field { margin: 0 0 16px; }
/* section jump list on the week screen */
.jump { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.jump-btn {
  display: flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); text-align: left; cursor: pointer;
  font-size: 15px; line-height: 1.2;
}
.jump-num { width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--line); font-weight: 700; font-size: 14px; }
.jump-btn.complete .jump-num { background: var(--ok); color: #fff; }
.jump-btn .jump-name { overflow-wrap: normal; word-break: normal; hyphens: auto; }

/* locked weeks and the version button */
.week-list .locked { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 10px 4px; border-bottom: 1px solid var(--line); color: var(--ink-3); }
.week-list li:last-child .locked { border-bottom: 0; }
.week-list .locked .wk-title { font-weight: 550; }
.week-list .locked .wk-num { background: transparent; }
svg.lock { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.version-tap { border: 0; background: none; color: inherit; font: inherit; min-height: 44px; padding: 8px 12px; cursor: default; }

/* reporting */
.report-ok { color: var(--ok); font-weight: 700; margin-bottom: 4px; }
.report-wait { color: var(--accent); font-weight: 700; margin-bottom: 4px; }
.rates .rate-line p { margin: 6px 0 4px; font-weight: 600; }
.rates .bar { height: 10px; border-radius: 5px; }

.btn.danger { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.quiet.danger { background: transparent; color: var(--warn); border-color: var(--warn); }
@media (prefers-color-scheme: dark) { .btn.danger { color: #1a0f0e; } .btn.quiet.danger { color: var(--warn); } }
