/* Study Tracker
 *
 * Visual direction: a desk lamp at night. Deep ink-blue surfaces, one warm amber
 * accent, and a monospaced timer that reads like an instrument rather than a
 * web page. The signature element is the hour bar: the daily goal drawn as
 * discrete hour blocks that fill, so progress is countable at a glance instead
 * of being an abstract percentage.
 */

:root {
  --ink: #101822;
  --surface: #18222f;
  --surface-2: #22303f;
  --line: #2c3b4d;
  --text: #eef3f8;
  --muted: #93a6bd;
  --accent: #ffb02e;
  --accent-ink: #1a1206;
  --accent-soft: rgba(255, 176, 46, 0.14);
  --good: #3fc97a;
  --bad: #ff6b5f;

  --radius: 14px;
  --radius-sm: 8px;
  --gap: 14px;
  --page: 18px;
  --tabbar-h: 62px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --ink: #f6f2ea;
    --surface: #fffdf9;
    --surface-2: #ece5d8;
    --line: #ddd3c2;
    --text: #16202c;
    --muted: #5b6a7b;
    --accent: #c97f06;
    --accent-ink: #fffdf9;
    --accent-soft: rgba(201, 127, 6, 0.12);
    --good: #1d8f4e;
    --bad: #cf3a2c;
  }
}

* { box-sizing: border-box; }

/* Elements with several `display` values below (flex, grid) would otherwise
 * override the UA stylesheet's [hidden]{display:none} at equal specificity;
 * this rule must win regardless of what else targets the element. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, p, dl, dd, ul { margin: 0; }
ul { padding: 0; list-style: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* --- layout ----------------------------------------------------------- */

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px) var(--page)
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.view--center {
  min-height: 100dvh;
  justify-content: center;
  padding-bottom: calc(env(safe-area-inset-bottom) + 28px);
}

.stack { display: flex; flex-direction: column; gap: var(--gap); }

.row { display: flex; gap: 10px; }
.row--links { justify-content: center; gap: 22px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
}

.topbar__title { font-size: 1.5rem; font-weight: 650; letter-spacing: -0.02em; }

.topbar__date {
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* --- the hour bar: the signature element ------------------------------- */

.hourbar {
  display: flex;
  gap: 4px;
  width: 100%;
}

.hourbar__seg {
  flex: 1 1 0;
  height: 26px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
}

.hourbar__fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 5px;
}

.hourbar--done .hourbar__fill { background: var(--good); }

/* --- goal block -------------------------------------------------------- */

.goal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.goal__head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }

.goal__value {
  font-family: var(--mono);
  font-size: clamp(2.4rem, 12vw, 3.1rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.goal__of { color: var(--muted); font-size: 0.95rem; }

.goal__note { color: var(--muted); font-size: 0.85rem; }

/* --- buttons ----------------------------------------------------------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 650;
  color: var(--text);
  background: var(--surface-2);
  padding: 14px 18px;
  min-height: 52px;
  cursor: pointer;
  transition: filter 0.12s ease;
}

.btn:active { filter: brightness(0.9); }

.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--ghost { background: var(--surface); border-color: var(--line); }
.btn--danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn--block { width: 100%; }
.btn--grow { flex: 1; }
.btn--big { flex: 1; min-height: 62px; font-size: 1.05rem; }

.btn--hero {
  background: var(--accent);
  color: var(--accent-ink);
  min-height: 128px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 18px;
}

.btn--hero__label {
  font-size: 1.6rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.btn--hero__hint { font-size: 0.85rem; font-weight: 500; opacity: 0.72; }

.linkbtn {
  appearance: none;
  background: none;
  border: 0;
  padding: 6px 2px;
  color: var(--accent);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.linkbtn--add { align-self: flex-start; }

/* --- running session --------------------------------------------------- */

.session {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  text-align: center;
}

.session__status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  animation: pulse 2.4s ease-in-out infinite;
}

.dot--paused { background: var(--muted); animation: none; }

@keyframes pulse { 50% { opacity: 0.35; } }

.timer {
  font-family: var(--mono);
  font-size: clamp(3rem, 17vw, 4.4rem);
  font-weight: 600;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 2px 0 4px;
}

.session__what { font-size: 1.05rem; font-weight: 620; }
.session__sep { color: var(--muted); margin: 0 4px; }
.session__subject { color: var(--accent); }
.session__meta { color: var(--muted); font-size: 0.85rem; }

.session__notes {
  color: var(--muted);
  font-size: 0.9rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  width: 100%;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.session .hourbar { margin-top: 6px; }

/* --- stat tiles -------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tiles--flush { margin-top: 4px; }

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
}

.tile--wide { grid-column: 1 / -1; }

.tile__label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

.tile__value {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.tile__value--lg { font-size: 2.1rem; }

/* --- streak chip ------------------------------------------------------- */

.chip--streak {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 5px 12px;
}

.chip__value {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}

.chip__label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

/* --- panels, charts ---------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel__title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel__note { color: var(--muted); font-size: 0.85rem; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 132px;
  overflow-x: auto;
  padding-bottom: 18px;
}

.chart__col {
  flex: 1 0 14px;
  min-width: 10px;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
}

.chart__bar {
  width: 100%;
  min-height: 2px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
}

.chart__bar--empty { background: var(--surface-2); }

.chart__tick {
  position: absolute;
  bottom: -17px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.6rem;
  color: var(--muted);
  white-space: nowrap;
}

.bars { display: flex; flex-direction: column; gap: 10px; }

.bar__head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.9rem;
  margin-bottom: 5px;
}

.bar__value {
  font-family: var(--mono);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.bar__track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.bar__fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; }

/* --- segmented control -------------------------------------------------- */

.segmented {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.segmented__btn {
  appearance: none;
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 620;
  padding: 9px 15px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented__btn[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* --- history list ------------------------------------------------------- */

.listnote {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 650;
}

.sessions { display: flex; flex-direction: column; gap: 8px; }

.srow {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.srow__main { flex: 1; min-width: 0; }

.srow__top {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-weight: 620;
}

.srow__topic {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.srow__sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

.srow__dur {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.srow__live { color: var(--accent); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 12px;
  font-size: 0.95rem;
}

/* --- forms -------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 6px; }

.field__label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.field__hint { font-weight: 600; letter-spacing: 0.04em; }

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  padding: 12px;
  min-height: 48px;
}

.field textarea { resize: vertical; min-height: 60px; }

.field input[type="color"] { padding: 4px; min-height: 48px; }

.filters {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filters--tight { padding: 12px; }

.filters__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.inline-form { display: flex; gap: 8px; align-items: stretch; }

.inline-form input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  padding: 12px;
}

.inline-form input[type="color"] {
  width: 52px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.form-error {
  color: var(--bad);
  font-size: 0.9rem;
  background: rgba(255, 107, 95, 0.1);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* --- login -------------------------------------------------------------- */

.login {
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0 var(--page);
}

.login__mark {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 68px;
  margin-bottom: 6px;
}

.login__mark span {
  height: 11px;
  border-radius: 3px;
  background: var(--surface-2);
}

.login__mark span:nth-child(1),
.login__mark span:nth-child(2) { background: var(--accent); }

.login__mark span:nth-child(3) {
  background: linear-gradient(to right, var(--accent) 55%, var(--surface-2) 55%);
}

.login__title { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.03em; }
.login__sub { color: var(--muted); margin-bottom: 8px; }

/* --- chips -------------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chipbtn {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 11px 16px;
  min-height: 44px;
  cursor: pointer;
}

.chipbtn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chipbtn__dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: 1px;
}

.chipbtn[aria-pressed="true"] .chipbtn__dot { display: none; }

/* --- catalog ------------------------------------------------------------ */

.cat { display: flex; flex-direction: column; gap: 8px; }

.cat__subject {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.cat__head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 640;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
}

.cat__swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.cat__count { margin-left: auto; color: var(--muted); font-size: 0.8rem; }

.cat__body {
  padding: 0 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cat__topic {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--muted);
}

.cat__topic span { flex: 1; }

/* --- sheets, backdrop, toast -------------------------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 13, 0.62);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 10px var(--page) calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  animation: rise 0.18s ease-out;
}

@keyframes rise { from { transform: translateY(14px); } }

.sheet__grip {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 2px auto 6px;
}

.sheet__title { font-size: 1.25rem; font-weight: 680; letter-spacing: -0.02em; }
.sheet__text { color: var(--muted); }

.sheet__label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 4px;
}

.detail { display: flex; flex-direction: column; gap: 10px; }

.detail__row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 9px;
}

.detail__key {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding-top: 2px;
}

.detail__val { text-align: right; overflow-wrap: anywhere; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 60;
  background: var(--text);
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 620;
  padding: 11px 18px;
  border-radius: 999px;
  max-width: calc(100% - 32px);
  text-align: center;
}

/* --- offline banner ------------------------------------------------------ */

.banner {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.82rem;
  font-weight: 650;
  padding: calc(env(safe-area-inset-top) + 7px) 14px 7px;
}

.banner__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-ink);
}

/* --- tab bar -------------------------------------------------------------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--tabbar-h);
  cursor: pointer;
}

.tab[aria-current="page"] { color: var(--accent); }

.tab__label {
  font-size: 0.66rem;
  font-weight: 680;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* --- wider screens -------------------------------------------------------- */

@media (min-width: 620px) {
  .tabbar {
    max-width: 560px;
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
