:root {
  --navy: #0e2744;
  --navy-2: #16375c;
  --ink: #1b2430;
  --muted: #5c6570;
  --paper: #f4efe6;
  --card: #fffdf8;
  --line: #e0d6c6;
  --gold: #c4a35a;
  --gold-2: #a8883e;
  --good: #2f6f4e;
  --warn: #9a4b2f;
  --english: #7c4a3a;
  --maths1: #2c5f8a;
  --maths2: #1b3a5f;
  --economics: #3d6b4f;
  --physics: #6b4c9a;
  --shadow: 0 10px 30px rgba(14, 39, 68, 0.08);
  --radius: 18px;
  --tap: 52px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; max-width: 100%; }
body {
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, #e9d9b3 0%, transparent 50%),
    var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  overflow-x: hidden;
  max-width: 100%;
}
button, a, input, select { touch-action: manipulation; }
button { -webkit-tap-highlight-color: rgba(14, 39, 68, 0.12); }

.hidden { display: none !important; }

.shell {
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
  overflow-x: hidden;
}

.top {
  padding: 14px 16px 8px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.mark {
  width: 48px; height: 48px; border-radius: 14px; flex: 0 0 auto;
  background: var(--navy); color: var(--gold);
  display: grid; place-items: center;
  font-family: Fraunces, Georgia, serif;
  font-weight: 700; letter-spacing: 0.04em;
}
.brand h1 {
  font-family: Fraunces, Georgia, serif;
  font-size: 1.35rem; margin: 0; letter-spacing: -0.02em;
}
.brand > div { min-width: 0; }
.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.3;
}

.chip {
  margin: 4px 0 0;
  background: var(--navy);
  color: #f4efe6;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px;
}
.tab {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  padding: 12px 8px;
  min-height: var(--tap);
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.tab.on {
  background: var(--navy);
  border-color: var(--navy);
  color: #fffdf8;
}

main { padding: 12px 16px 24px; min-width: 0; }
.panel { display: block; min-width: 0; }

.log-card, .history, .mix-card, .analysis-card, .progress-card, .horizon-card, .settings-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
  min-width: 0;
  max-width: 100%;
}

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field span { color: var(--muted); font-size: 0.95rem; }
input[type="date"], input[type="number"], select {
  font: inherit;
  font-size: 18px;
  padding: 14px 12px;
  border-radius: 14px;
  border: 2px solid var(--navy);
  background: #fff;
  min-height: var(--tap);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  color: var(--ink);
}
select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--navy) 50%),
    linear-gradient(135deg, var(--navy) 50%, transparent 50%);
  background-position: calc(100% - 18px) 22px, calc(100% - 12px) 22px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

.hint, .muted, .sources { color: var(--muted); }
.hint { margin: 10px 0 4px; }
.sources { font-size: 0.9rem; line-height: 1.45; margin-top: 18px; }

.subject-rows { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.subject-row {
  display: grid;
  grid-template-columns: 40px 40px minmax(0, 1fr) 3.1rem 3.1rem;
  gap: 4px;
  align-items: center;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  min-width: 0;
}
.subject-name {
  font-weight: 700;
  font-size: 0.98rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.subject-row select.hours,
.subject-row select.mins {
  width: 3.1rem;
  max-width: 3.1rem;
  min-width: 0;
  min-height: 40px;
  padding: 4px 16px 4px 4px;
  font-size: 16px;
  border-radius: 10px;
  background-position: calc(100% - 7px) 16px, calc(100% - 3px) 16px;
}
.step {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--navy);
  background: var(--navy);
  color: #f7e7b8;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}
.step:active { transform: scale(0.96); }

.log-total {
  display: flex; justify-content: space-between; align-items: center;
  margin: 4px 0 10px; font-size: 1.05rem;
}
.log-total strong { font-size: 1.4rem; }

.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border-radius: 16px; border: 2px solid var(--navy);
  padding: 12px 16px; background: #fff; color: var(--navy);
  min-height: var(--tap);
}
.btn.primary { background: var(--navy); color: #f7e7b8; }
.btn.wide { width: 100%; }
.btn.huge { min-height: 56px; font-size: 1.15rem; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 10px 12px; border-radius: 12px; font-size: 0.95rem; min-height: var(--tap); }
.btn.danger { border-color: var(--warn); color: var(--warn); }

.flash { margin: 10px 0 0; color: var(--good); font-weight: 600; }
.error { color: var(--warn); font-weight: 600; }

.section-head h2 {
  font-family: Fraunces, Georgia, serif;
  margin: 0 0 4px;
  font-size: 1.25rem;
}
.section-head p { margin: 0 0 14px; color: var(--muted); }
.section-head.tight { margin-top: 22px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
tbody tr { cursor: pointer; }

.history-cards, .horizon-cards { display: none; }
.card-day {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  background: #fff;
}
.card-day header { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; align-items: center; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; font-size: 1.02rem; }

.countdown {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.exam-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.exam-card .days {
  font-family: Fraunces, Georgia, serif;
  font-size: 2.1rem;
  margin: 6px 0 0;
}
.exam-card .sub { color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.exam-card .status { display: inline-block; margin-top: 8px; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.02em; }
.status.on_track { color: var(--good); }
.status.behind { color: var(--warn); }
.status.ahead { color: var(--maths1); }
.status.done { color: var(--muted); }

.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 0.98rem;
}
.bar-track {
  position: relative;
  height: 18px;
  background: #efe8dc;
  border-radius: 99px;
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  max-width: 100%;
}
.bar-fill.on_track { background: var(--good); }
.bar-fill.ahead { background: var(--maths1); }
.bar-fill.behind { background: var(--warn); }
.bar-fill.done { background: #cfc6b6; }
.bar-mark {
  position: absolute;
  top: -5px;
  height: 28px;
  width: 3px;
  margin-left: -1.5px;
  background: var(--navy);
  border-radius: 2px;
  box-shadow: 0 0 0 2px #fffdf8;
}
.bar-meta { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.sliders { display: flex; flex-direction: column; gap: 16px; }
.slider-row { display: grid; grid-template-columns: 1fr 64px; gap: 8px 12px; align-items: center; }
.slider-row .name { grid-column: 1 / -1; font-weight: 700; }
input[type="range"] {
  width: 100%;
  height: 44px;
  accent-color: var(--navy);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--navy);
  border: 3px solid #f7e7b8;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 99px;
  background: var(--line);
}
.pct { font-weight: 700; text-align: right; font-size: 1.1rem; }
.row-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 10px; flex-wrap: wrap; }

.learned-grid, .today-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat, .today-cell {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
}
.stat .n { color: var(--muted); font-size: 0.85rem; }
.stat strong, .today-cell strong {
  display: block;
  font-size: 1.35rem;
  margin-top: 4px;
  font-family: Fraunces, Georgia, serif;
}

.hour-defaults {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.pin-screen {
  position: fixed; inset: 0; background: var(--navy);
  display: grid; place-items: center; z-index: 20;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.pin-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 24px;
  padding: 24px 20px 16px;
}
.pin-card h1 { font-family: Fraunces, Georgia, serif; margin: 0 0 8px; }
.eyebrow { letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-2); font-size: 0.78rem; font-weight: 700; }
.lede { color: var(--muted); margin-top: 0; }
.pin-hidden {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  height: 0;
  width: 0;
}
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 16px;
}
.pin-dots span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--navy);
  background: transparent;
}
.pin-dots span.on { background: var(--navy); }
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.keypad button {
  min-height: 56px;
  font-size: 1.4rem;
  font-weight: 700;
  border-radius: 16px;
  border: 2px solid var(--navy);
  background: #fff;
  color: var(--navy);
  font-family: inherit;
}
.keypad button:active { background: #f4efe6; }
.keypad .key-go { background: var(--navy); color: #f7e7b8; }
.keypad .key-muted { font-size: 1.2rem; }
.install-hint { color: var(--muted); font-size: 0.88rem; line-height: 1.4; margin: 16px 0 0; }

.empty { text-align: center; color: var(--muted); padding: 12px; }

.desktop-only { display: none; }

/* Phone: bottom tab bar, thumb-reach */
@media (max-width: 860px) {
  .shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    max-width: none;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  .top { grid-row: 1; flex-direction: column; }
  main {
    grid-row: 2;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 16px;
  }
  .tabs {
    grid-row: 3;
    margin: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: var(--card);
    border-top: 1px solid var(--line);
    z-index: 12;
    flex-direction: row;
    gap: 6px;
    width: 100%;
  }
  .tab { border-radius: 14px; font-size: 0.92rem; padding: 10px 4px; }
  .history-cards, .horizon-cards { display: block; }
  .log-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to bottom, transparent, var(--card) 18px);
    padding-top: 12px;
  }
}

@media (min-width: 861px) {
  .top { padding: 22px 20px 8px; flex-direction: row; }
  .tabs { padding: 0 20px; margin-top: 8px; }
  main { padding: 16px 20px 64px; }
  .desktop-only { display: block; }
  .history-cards, .horizon-cards { display: none; }
  .countdown { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .learned-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .today-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .hour-defaults { grid-template-columns: 1fr 1fr; }
  .slider-row { grid-template-columns: 140px 1fr 64px; }
  .slider-row .name { grid-column: auto; }
  .subject-row {
    grid-template-columns: 40px 40px minmax(0, 1fr) 3.2rem 3.2rem;
  }
  tbody tr:hover { background: #f8f1e3; }
}

@media (min-width: 520px) and (max-width: 860px) {
  .countdown { grid-template-columns: 1fr 1fr; }
}
