@font-face {
  font-family: "Nunito";
  src: url("fonts/nunito.woff2") format("woff2");
  font-weight: 500 800;
  font-display: swap;
}

:root {
  /* light-dark(): the first for a light theme, the second for dark. Auto follows the system. */
  color-scheme: light dark;
  --bg: light-dark(#fbf6ee, #1c1814);
  --surface: light-dark(#f1e7da, #2b241e);
  --text: light-dark(#3b2f26, #f7eee2);
  --muted: light-dark(#8b7a6b, #a8998a);
  --accent: light-dark(#f0ab45, #f2b75b);
  --accent-ink: light-dark(#3b2610, #2e1f0d);
  --accent-text: light-dark(#b0680c, #f2b75b);
  --track: light-dark(#efe4d5, #2f2822);
  --ok: light-dark(#5fa83a, #9fd27a);
  --warn: light-dark(#df7a45, #f29a6b);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

/* The page is the widget: it fills the window, whatever size that is, and never scrolls. */
html, body { height: 100%; margin: 0; overflow: hidden; }

body {
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text);
  font: 600 15px/1.4 "Nunito", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app { width: min(100% - 24px, 420px); }

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s, transform 0.05s;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* before sharing: one button, as big as the window allows */
.intro { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.start {
  height: clamp(18px, 62vh, 46px);
  padding: 0 1.4em;
  border-radius: 999px;
  font-size: clamp(11px, 30vh, 16px);
  font-weight: 800;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 0.18em 0 color-mix(in srgb, var(--accent) 55%, #000);
}
.start:hover { background: color-mix(in srgb, var(--accent) 90%, #fff); }
.start:active { transform: translateY(0.12em); box-shadow: 0 0.06em 0 color-mix(in srgb, var(--accent) 55%, #000); }
.note { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }

/* while tracking */
.board { display: flex; flex-direction: column; align-items: center; text-align: center; }

.rate {
  font-size: clamp(12px, min(17vw, 32vh), 96px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  transition: opacity 0.3s;
}
.unit { margin-left: 0.1em; font-size: clamp(0.36em, 14px, 0.5em); font-weight: 700; letter-spacing: 0; color: var(--muted); }
.board[data-state="searching"] .rate,
.board[data-state="lost"] .rate { opacity: 0.5; }

.line {
  display: flex; align-items: center; gap: 7px; max-width: 100%; margin-top: 0.6em;
  color: var(--muted); font-size: 14px; white-space: nowrap;
}
.line span:last-child { overflow: hidden; text-overflow: ellipsis; }
.recent { margin-top: 2px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.board[data-state="reading"] .dot { background: var(--ok); }
.board[data-state="searching"] .dot { background: var(--warn); animation: pulse 1.4s ease-in-out infinite; }
.board[data-state="lost"] .dot { background: var(--warn); }
.board[data-state="idle"] .dot,
.board[data-state="paused"] .dot { background: var(--muted); }
@keyframes pulse { 50% { opacity: 0.3; } }

.level { width: 100%; margin-top: 18px; }
.bar { height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.fill {
  height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 70%, #fff), var(--accent));
  transition: width 0.6s ease;
}
.row {
  display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; min-height: 1.4em;
  color: var(--muted); font-size: 13px; white-space: nowrap;
}

.actions { display: flex; gap: 4px; margin-top: 18px; opacity: 0.7; }
.board:hover .actions, .actions:focus-within { opacity: 1; }
.actions button {
  padding: 2px 10px; border-radius: 999px; background: none;
  color: var(--muted); font-size: 13px; font-weight: 700;
}
.actions button:hover { background: var(--surface); color: var(--text); }
.actions button.primary { color: var(--accent-text); }

/* settings: a sheet over the whole window */
.settings {
  width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  overflow: auto; background: var(--bg); color: var(--text);
}
.settings::backdrop { background: var(--bg); }
.sheet {
  width: min(100% - 32px, 340px); min-height: 100%; margin: 0 auto; padding: 20px 0;
  display: flex; flex-direction: column; justify-content: center; gap: 18px;
}
.sheet h2 { margin: 0; font-size: 18px; font-weight: 800; }
.sheet fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.sheet legend { padding: 0; margin-bottom: 8px; font-size: 13px; color: var(--muted); }
.field { display: block; }
.head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
  font-size: 13px; color: var(--muted);
}
.head output { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }

input[type="range"] {
  display: block; width: 100%; height: 22px; margin: 0; background: none; cursor: pointer;
  -webkit-appearance: none; appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--surface); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; margin-top: -6px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 55%, #000);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 999px; background: var(--surface); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: var(--accent); }
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 999px; }

.text {
  display: block; width: 100%; height: 34px; padding: 0 12px; border: 0; border-radius: 10px;
  font: inherit; font-size: 14px; background: var(--surface); color: var(--text);
}
.text::placeholder { color: var(--muted); }
.text:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.switch {
  position: relative; width: 34px; height: 20px; margin: 0; border-radius: 999px; cursor: pointer;
  -webkit-appearance: none; appearance: none; background: var(--surface); transition: background-color 0.15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s, background-color 0.15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(14px); background: var(--accent-ink); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.log { margin: 0; padding: 0; list-style: none; font-size: 13px; font-variant-numeric: tabular-nums; }
.log li { display: grid; grid-template-columns: 1fr auto 5.5em; gap: 12px; padding: 5px 0; border-top: 1px solid var(--surface); }
.log li:first-child { border-top: 0; }
.log li span:not(:first-child) { text-align: right; }
.log li span:first-child { color: var(--muted); }
.log .empty { display: block; color: var(--muted); }
.log-actions { display: flex; gap: 4px; margin: 6px 0 0 -10px; }
.log-actions button {
  padding: 2px 10px; border-radius: 999px; background: none;
  color: var(--muted); font-size: 13px; font-weight: 700;
}
.log-actions button:hover { background: var(--surface); color: var(--text); }
.log-note { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface); }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; padding: 5px 0; border-radius: 999px; text-align: center; cursor: pointer;
  font-size: 13px; font-weight: 700; color: var(--muted); transition: background-color 0.15s, color 0.15s;
}
.seg span:hover { color: var(--text); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.done {
  align-self: flex-start; height: 34px; padding: 0 18px; border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 800;
}
.done:hover { background: color-mix(in srgb, var(--surface) 85%, var(--text)); }

[hidden] { display: none !important; }

/* Shorter windows keep fewer things, biggest first: the buttons tuck into the corner (shown on hover),
   then the level bar goes, then everything but the EXP per hour. */
@media (max-height: 299px) {
  .actions { position: fixed; top: 4px; right: 4px; margin: 0; opacity: 0; }
  .actions button { background: var(--surface); padding: 0 8px; font-size: 12px; }
  body:hover .actions, .actions:focus-within { opacity: 1; }
}
@media (max-height: 219px) {
  .level { display: none; }
  .rate { font-size: clamp(12px, min(17vw, 45vh), 96px); }
}
@media (max-height: 119px) {
  .line, .recent { display: none; }
  .rate { font-size: clamp(10px, min(17vw, 72vh), 96px); }
}
