:root {
  --bg: #ffffff;
  --text: #171717;
  --muted: #667085;
  --line: #d9dee7;
  --soft: #f8fafc;
  --chip: #eef1f5;
  --surface: #ffffff;
  --surface-muted: #f9fafb;
  --topbar: rgba(255, 255, 255, 0.94);
  --input-bg: #ffffff;
  --blue: #2563ff;
  --blue-soft: #9db8fb;
  --blue-active: #2563ff;
  --danger: #e00000;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

:root[data-theme="dark"] {
  --bg: #0b1020;
  --text: #f8fafc;
  --muted: #9aa7bd;
  --line: #263247;
  --soft: #121a2c;
  --chip: #1c2638;
  --surface: #111827;
  --surface-muted: #151f31;
  --topbar: rgba(13, 19, 33, 0.94);
  --input-bg: #0d1526;
  --blue: #7da2ff;
  --blue-soft: #315fcb;
  --blue-active: #4f7cff;
  --danger: #ff6b6b;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--soft);
}

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 28px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.auth-card h1 {
  font-size: 32px;
  line-height: 1.1;
}

.muted,
label span,
.message {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 600;
}

label small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

input,
select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
  padding: 0 12px;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.primary,
.secondary {
  height: 48px;
  border-radius: 7px;
  border: 1px solid var(--line);
  padding: 0 18px;
  font-weight: 650;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease, opacity 120ms ease;
}

.primary {
  border-color: var(--blue-active);
  background: var(--blue-active);
  color: #fff;
}

.primary:hover:not(:disabled) {
  background: #174ee6;
  border-color: #174ee6;
  transform: translateY(-1px);
}

.primary:disabled {
  border-color: var(--line);
  background: var(--chip);
  color: var(--muted);
  cursor: not-allowed;
}

.secondary {
  background: var(--surface);
  color: var(--text);
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 4px;
}

.message {
  min-height: 20px;
  font-size: 14px;
}

.message.error {
  color: var(--danger);
}

.form-hints {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
}

.form-hints span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-hints span::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.55;
}

.form-hints span.ok {
  color: var(--blue);
}

.form-hints span.ok::before {
  background: var(--blue);
  opacity: 1;
}

.tracker-app {
  min-height: 100vh;
  position: relative;
  padding-top: 74px;
}

.topbar {
  position: fixed;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  backdrop-filter: blur(12px);
}

.topbar-spacer {
  flex: 1;
}

.icon-nav {
  display: flex;
  gap: 8px;
}

.icon-button,
.square-button {
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 22px;
}

.icon-button.active,
.square-button:hover {
  border-color: #74a0ff;
  background: color-mix(in srgb, var(--blue) 14%, transparent);
  color: var(--blue);
}

.year-view {
  width: min(900px, calc(100vw - 32px));
  margin: 28px auto 0;
  text-align: center;
}

.year-control {
  display: inline-flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}

.year-control h1 {
  min-width: 86px;
  font-size: 26px;
  line-height: 1;
}

.heatmap-area {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  overflow-x: auto;
  padding: 0 4px 8px;
}

.month-row {
  display: grid;
  grid-template-rows: 18px;
  grid-auto-flow: column;
  gap: 4px;
  margin-left: 54px;
  min-height: 18px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
}

.month-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  grid-row: 1;
  align-self: end;
  justify-self: start;
  padding-left: 2px;
}

.heatmap-line {
  display: flex;
  gap: 12px;
  align-items: start;
}

.weekday-labels {
  width: 42px;
  display: grid;
  grid-template-rows: repeat(7, 14px);
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 14px;
  text-align: right;
}

.heatmap-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 14px);
  gap: 4px;
}

.day,
.legend i {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 3px;
  display: block;
}

.day.today {
  outline: 2px solid #111;
  outline-offset: 1px;
}

.heatmap-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: min(320px, calc(100vw - 16px));
  padding: 8px 11px;
  border-radius: 7px;
  background: #3f4652;
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 90ms ease, transform 90ms ease;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.28);
}

.heatmap-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.day.outside {
  visibility: hidden;
}

.level-0 {
  background: color-mix(in srgb, var(--muted) 22%, transparent);
}

.level-1 {
  background: #dbeafe;
}

.level-2 {
  background: #bfdbfe;
}

.level-3 {
  background: #93c5fd;
}

.level-4 {
  background: #3b82f6;
}

.level-5 {
  background: #1d4ed8;
}

.legend {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.legend.labels {
  gap: 18px;
  margin-top: 8px;
  font-size: 12px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  width: min(540px, 100%);
  margin: 30px auto 28px;
}

.stats-row article {
  min-height: 100px;
  display: grid;
  align-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.stats-row strong {
  color: var(--blue);
  font-size: 26px;
  line-height: 1;
}

.stats-row span {
  color: var(--muted);
  font-size: 14px;
}

.today-section {
  width: min(540px, calc(100vw - 32px));
  margin: 0 auto;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.today-heading {
  margin-bottom: 20px;
}

.today-heading h2 {
  font-size: 23px;
  margin-bottom: 4px;
}

.today-heading p {
  color: var(--muted);
  font-size: 17px;
}

.add-session {
  width: 100%;
  height: 56px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 17px;
}

.add-session.compact {
  margin-top: 12px;
}

.session-form {
  display: grid;
  gap: 22px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 12px;
  color: var(--text);
  font-weight: 700;
}

.duration-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.duration-grid button,
.pill-row button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.duration-grid button.active,
.pill-row button.active {
  border-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 14%, transparent);
  color: var(--blue);
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill-row button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
}

.today-list {
  display: grid;
  gap: 10px;
}

.today-list article {
  display: grid;
  grid-template-columns: 1fr 1fr auto 32px;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.today-list span,
.today-list em {
  color: var(--muted);
  font-style: normal;
}

.today-list button {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 20px;
}

.settings-panel {
  position: fixed;
  top: 66px;
  right: 14px;
  z-index: 20;
  width: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-panel section {
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.settings-panel h3 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chips span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  font-size: 14px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr 50px;
  gap: 6px;
}

.inline-form input {
  height: 32px;
}

.inline-form button {
  height: 32px;
  border: 0;
  border-radius: 5px;
  background: var(--blue-active);
  color: #fff;
}

.theme-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.theme-buttons button {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 20px;
}

.theme-buttons button.active {
  border-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 14%, transparent);
  color: var(--blue);
}

.menu-line {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border: 0;
  background: var(--surface);
  padding: 0 20px;
  color: var(--text);
  font-size: 16px;
}

.menu-line.split {
  justify-content: space-between;
}

.menu-line.split span:last-child {
  color: var(--muted);
  font-size: 14px;
}

.logout {
  min-height: 44px;
  border: 0;
  background: var(--surface);
  padding: 0 20px 12px;
  color: var(--danger);
  font-size: 16px;
  text-align: left;
}

@media (max-width: 920px) {
  .settings-panel {
    position: static;
    width: min(540px, calc(100vw - 32px));
    margin: 24px auto;
  }

  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 620px) {
  .year-view {
    margin-top: 20px;
  }

  .duration-grid,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .legend.labels {
    flex-wrap: wrap;
  }
}
