:root {
  --bg: #100f0f;
  --bg-2: #1c1b1a;
  --ui: #282726;
  --ui-2: #343331;
  --ui-3: #403e3c;
  --tx-3: #575653;
  --tx-2: #878580;
  --tx: #cecdc3;

  --red: #d14d41;
  --orange: #da702c;
  --yellow: #d0a215;
  --green: #879a39;
  --cyan: #3aa99f;
  --blue: #4385be;
  --purple: #8b7ec8;
  --magenta: #ce5d97;

  --skin: #e0a878;
  --hair: #403e3c;
  --leather: #6b4423;
  --series: var(--blue);

  --radius: 2px;
  --nav-h: 42px;
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #fffcf0;
  --bg-2: #f2f0e5;
  --ui: #e6e4d9;
  --ui-2: #dad8ce;
  --ui-3: #cecdc3;
  --tx-3: #b7b5ac;
  --tx-2: #6f6e69;
  --tx: #100f0f;

  --red: #af3029;
  --orange: #bc5215;
  --yellow: #ad8301;
  --green: #66800b;
  --cyan: #24837b;
  --blue: #205ea6;
  --purple: #5e409d;
  --magenta: #a02f6f;

  --skin: #d39a6a;
  --hair: #575653;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background-color: var(--bg);
  color: var(--tx);
  font-family: ui-monospace, 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.3;
}

h1 {
  font-size: 1.4rem;
  margin-bottom: 16px;
}

h1::before {
  content: '$ ';
  color: var(--green);
}

h2 {
  font-size: 1.05rem;
  margin-bottom: 12px;
}

h2::before {
  content: '# ';
  color: var(--tx-3);
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  color: var(--cyan);
}

::selection {
  background: var(--blue);
  color: var(--bg);
}

input,
textarea,
select,
button {
  background-color: var(--bg-2);
  border: 1px solid var(--ui-2);
  border-radius: var(--radius);
  color: var(--tx);
  font-family: inherit;
  font-size: 16px;
  padding: 8px 10px;
  min-height: 42px;
}

input::placeholder,
textarea::placeholder {
  color: var(--tx-3);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--blue);
  outline: none;
  box-shadow: 0 0 0 1px var(--blue);
}

textarea {
  min-height: 90px;
  resize: vertical;
  width: 100%;
}

label {
  color: var(--tx-2);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

button {
  cursor: pointer;
  transition:
    background-color 0.1s ease,
    border-color 0.1s ease,
    color 0.1s ease;
}

button:hover {
  background-color: var(--ui);
  border-color: var(--ui-3);
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.btn-create {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green) 55%, var(--ui-2));
}

.btn-create:hover {
  background: color-mix(in srgb, var(--green) 14%, var(--bg-2));
  border-color: var(--green);
}

.btn-danger {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 50%, var(--ui-2));
}

.btn-danger:hover {
  background: color-mix(in srgb, var(--red) 14%, var(--bg-2));
  border-color: var(--red);
}

.btn-big {
  width: 100%;
  min-height: 52px;
  font-weight: 600;
  font-size: 1.05rem;
  background: color-mix(in srgb, var(--green) 10%, var(--bg-2));
}

.btn-small {
  min-height: 32px;
  padding: 2px 10px;
  font-size: 0.9rem;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--ui-3) var(--bg-2);
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

@keyframes pop {
  0% {
    transform: translateY(-6px);
    opacity: 0;
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

@keyframes flicker {
  0%,
  100% {
    opacity: 0.85;
  }
  50% {
    opacity: 1;
  }
}

.muted {
  color: var(--tx-2);
}

.faint {
  color: var(--tx-3);
}

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

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

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

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

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

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

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

.panel {
  border: 1px solid var(--ui);
  border-radius: var(--radius);
  background: var(--bg-2);
  padding: 12px;
  margin-bottom: 16px;
}

.panel p + p,
.panel form + p,
.panel p + form {
  margin-top: 8px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.page-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 12px 56px;
}

.cursor {
  color: var(--green);
  animation: blink 1.1s step-end infinite;
}

.status-badge {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  font-size: 0.75em;
  margin-left: 6px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-2);
  border-bottom: 1px solid var(--ui);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  min-height: var(--nav-h);
}

.brand {
  color: var(--yellow);
  font-weight: 700;
  padding: 8px 0;
}

.brand:hover {
  color: var(--yellow);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.theme-toggle {
  min-height: 32px;
  padding: 2px 10px;
}

.nav {
  display: flex;
  width: 100%;
  overflow-x: auto;
  gap: 2px;
  border-top: 1px solid var(--ui);
  padding: 4px 0;
}

.nav-link {
  color: var(--tx-2);
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--ui);
  color: var(--tx);
}

.nav-link[aria-current='page'] {
  color: var(--cyan);
  border-color: color-mix(in srgb, var(--cyan) 40%, var(--ui-2));
  background: color-mix(in srgb, var(--cyan) 8%, var(--bg));
}

.flashes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  --accent: var(--blue);
  border: 1px solid color-mix(in srgb, var(--accent) 60%, var(--ui-2));
  border-left: 4px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-2));
  padding: 10px 12px;
  border-radius: var(--radius);
  animation: pop 0.25s ease-out;
}

.flash-error {
  --accent: var(--red);
}

.flash-pr {
  --accent: var(--yellow);
  font-weight: 600;
}

.flash-achievement {
  --accent: var(--magenta);
  font-weight: 600;
}

.flash-level {
  --accent: var(--purple);
  font-weight: 600;
}

.flash-quest {
  --accent: var(--cyan);
  font-weight: 600;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.inline-form input:not([type='hidden']) {
  flex: 1 1 120px;
  min-width: 0;
}

.inline-form input[type='date'] {
  flex-basis: 160px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 16px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  border-color: color-mix(in srgb, var(--purple) 35%, var(--ui));
  background:
    linear-gradient(
      160deg,
      color-mix(in srgb, var(--purple) 10%, var(--bg-2)),
      var(--bg-2) 60%
    );
}

.hero-avatar {
  display: flex;
  justify-content: center;
}

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

.level-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.level-badge {
  color: var(--bg);
  background: var(--purple);
  padding: 1px 8px;
  border-radius: var(--radius);
  font-weight: 700;
}

.level-title {
  font-size: 1.2rem;
  font-weight: 600;
}

.xp-numbers {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.mood {
  color: var(--tx);
}

.bar {
  --accent: var(--blue);
  height: 12px;
  background: var(--bg);
  border: 1px solid var(--ui-2);
  border-radius: var(--radius);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.6s ease-out;
}

.bar-xp {
  --accent: var(--purple);
  height: 14px;
}

.bar-xp .bar-fill {
  background: linear-gradient(90deg, var(--blue), var(--purple), var(--magenta));
}

.bar-quest {
  --accent: var(--cyan);
}

.streak-panel {
  border-color: color-mix(in srgb, var(--orange) 35%, var(--ui));
}

.streak-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.streak-flame {
  font-size: 1.8rem;
  animation: flicker 1.6s ease-in-out infinite;
}

.streak-count {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--orange);
  line-height: 1;
}

.week-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0;
}

.dot {
  width: 14px;
  height: 14px;
  border: 1px solid var(--orange);
  border-radius: 50%;
}

.dot-on {
  background: var(--orange);
}

.stat-grid,
.day-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
}

.stat-label {
  color: var(--tx-2);
  font-size: 0.85rem;
}

.rows {
  list-style: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--ui);
}

.row:last-child {
  border-bottom: none;
}

.row-link {
  padding: 0;
}

.row-link a {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  width: 100%;
  padding: 8px 0;
  color: var(--tx);
}

.row-link a::before {
  content: '>';
  color: var(--tx-3);
}

.row-link a:hover::before {
  color: var(--cyan);
}

.row-date {
  color: var(--blue);
}

.row-main {
  flex: 1 1 auto;
}

.row-meta {
  margin-left: auto;
  font-size: 0.85rem;
}

.quest,
.quest-mini {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
}

.quest + .quest {
  border-top: 1px solid var(--ui);
}

.quest-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.quest-name {
  color: var(--tx);
}

.set-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.set-exercise select {
  width: 100%;
}

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

.stepper {
  display: flex;
}

.stepper input {
  width: 100%;
  min-width: 0;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  border-radius: 0;
  font-variant-numeric: tabular-nums;
}

.step {
  min-width: 46px;
  font-size: 1.3rem;
  color: var(--cyan);
}

.step:first-child {
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
}

.step:last-child {
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.set-list {
  list-style: none;
  counter-reset: set;
}

.set-row {
  counter-increment: set;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px solid var(--ui);
}

.set-row:last-child {
  border-bottom: none;
}

.set-index::after {
  content: counter(set);
}

.set-value {
  flex: 1;
  font-variant-numeric: tabular-nums;
}

.pr-badge {
  color: var(--yellow);
  border: 1px solid color-mix(in srgb, var(--yellow) 60%, var(--ui-2));
  background: color-mix(in srgb, var(--yellow) 12%, var(--bg-2));
  padding: 0 6px;
  border-radius: var(--radius);
  font-size: 0.8rem;
}

.set-delete {
  margin-left: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.data-table th {
  text-align: left;
  color: var(--tx-2);
  font-weight: 400;
  background: var(--bg);
  padding: 4px 6px;
}

.data-table td {
  padding: 4px 6px;
  border-top: 1px solid var(--ui-2);
  vertical-align: middle;
}

.data-table .num {
  text-align: right;
}

.data-table .nowrap {
  white-space: nowrap;
}

.data-table .total td {
  font-weight: 700;
  color: var(--purple);
}

.trophy-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.trophy {
  border: 1px dashed var(--ui-2);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
  color: var(--tx-2);
}

.trophy .trophy-desc {
  color: var(--tx-2);
}

.trophy .trophy-icon {
  filter: grayscale(1);
  opacity: 0.5;
  font-size: 1.8rem;
}

.trophy-on {
  color: var(--tx);
  border: 1px solid color-mix(in srgb, var(--magenta) 50%, var(--ui-2));
  background: color-mix(in srgb, var(--magenta) 8%, var(--bg-2));
}

.trophy-on .trophy-icon {
  filter: none;
  opacity: 1;
}

.trophy-name {
  font-weight: 600;
}

.trophy-desc {
  font-size: 0.8rem;
}

.trophy-date {
  color: var(--magenta);
  font-size: 0.8rem;
  margin-top: 4px;
}

.auth-card {
  max-width: 420px;
  margin: 10vh auto 0;
}

.avatar {
  width: 100%;
  max-width: 220px;
  height: auto;
}

.av-skin,
.av-limb {
  fill: var(--skin);
  stroke: var(--skin);
}

.av-skin {
  stroke: none;
}

.av-limb {
  stroke-linecap: round;
}

.av-hair {
  fill: var(--hair);
}

.av-shadow {
  fill: var(--ui);
}

.av-shorts {
  fill: var(--ui-3);
}

.av-shoe {
  fill: var(--tx-2);
}

.av-shirt-0 {
  fill: var(--tx-2);
  stroke: var(--tx-2);
}

.av-shirt-1 {
  fill: var(--blue);
  stroke: var(--blue);
}

.av-shirt-2 {
  fill: var(--cyan);
  stroke: var(--cyan);
}

.av-shirt-3 {
  fill: var(--green);
  stroke: var(--green);
}

.av-shirt-4 {
  fill: var(--orange);
  stroke: var(--orange);
}

.av-shirt-5 {
  fill: var(--red);
  stroke: var(--red);
}

.av-shirt-6 {
  fill: var(--yellow);
  stroke: var(--yellow);
}

.av-sleeve {
  fill: none;
  stroke-linecap: round;
}

.av-cape {
  fill: var(--purple);
}

.av-belt {
  fill: var(--leather);
}

.av-buckle,
.av-crown {
  fill: var(--yellow);
}

.av-band {
  fill: var(--red);
}

.av-wrist {
  fill: var(--magenta);
}

.av-eye {
  fill: var(--bg);
}

.av-line {
  fill: none;
  stroke: var(--bg);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.av-mouth {
  fill: var(--bg);
}

.av-tear {
  fill: var(--blue);
}

.av-zzz {
  fill: var(--tx-2);
  font-family: inherit;
  font-weight: 700;
}

.av-sparkle {
  fill: var(--yellow);
}

.av-aura-fire {
  --aura: var(--orange);
  animation: flicker 2s ease-in-out infinite;
}

.av-aura-gold {
  --aura: var(--yellow);
  animation: flicker 2s ease-in-out infinite;
}

.av-aura-stop-in {
  stop-color: var(--aura, var(--orange));
  stop-opacity: 0.45;
}

.av-aura-stop-out {
  stop-color: var(--aura, var(--orange));
  stop-opacity: 0;
}

.chart,
.heatmap-wrap {
  position: relative;
}

.chart {
  max-width: 640px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-grid {
  stroke: var(--ui);
  stroke-width: 1;
}

.chart-baseline {
  stroke: var(--ui-3);
  stroke-width: 1;
}

.chart-axis {
  fill: var(--tx-2);
  font-size: 13px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.chart-end {
  fill: var(--tx);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
}

.chart-line {
  fill: none;
  stroke: var(--series);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-dot,
.chart-focus {
  fill: var(--series);
  stroke: var(--bg-2);
  stroke-width: 2;
}

.chart-crosshair {
  stroke: var(--tx-3);
  stroke-width: 1;
}

.chart-crosshair,
.chart-focus {
  visibility: hidden;
}

.chart.is-active .chart-crosshair,
.chart.is-active .chart-focus {
  visibility: visible;
}

.chart-hit {
  fill: transparent;
  cursor: crosshair;
}

.chart-tip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  display: none;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--ui-3);
  border-radius: 3px;
  padding: 4px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
  font-size: 0.85rem;
  z-index: 5;
}

.chart-tip.is-visible {
  display: flex;
}

.chart-tip-value {
  color: var(--tx);
}

.chart-tip-label {
  color: var(--tx-2);
}

.heatmap {
  max-width: 560px;
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
}

.heat {
  aspect-ratio: 1;
  border-radius: 1px;
  display: block;
}

.heat-0 {
  background: var(--ui);
}

.heat-1 {
  background: color-mix(in srgb, var(--green) 35%, var(--bg-2));
}

.heat-2 {
  background: color-mix(in srgb, var(--green) 60%, var(--bg-2));
}

.heat-3 {
  background: color-mix(in srgb, var(--green) 82%, var(--bg-2));
}

.heat-4 {
  background: var(--green);
}

.heat-future {
  background: transparent;
}

.heatmap .heat[data-tip]:hover {
  outline: 1px solid var(--tx);
}

.heat-legend {
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  margin-top: 6px;
  font-size: 0.8rem;
}

.heat-legend .heat {
  width: 11px;
}

#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

@media (min-width: 820px) {
  html,
  body {
    font-size: 14px;
  }

  input,
  textarea,
  select,
  button {
    font-size: 14px;
  }

  .topbar {
    flex-wrap: nowrap;
    padding: 0 20px;
    gap: 16px;
  }

  .nav {
    order: 0;
    width: auto;
    flex: 1;
    border-top: none;
  }

  .brand {
    order: -1;
  }

  .topbar-actions {
    order: 1;
  }

  .page-shell {
    padding: 28px 20px 72px;
  }

  .panel {
    padding: 16px;
  }

  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }

  .hero {
    grid-template-columns: 220px 1fr;
    align-items: center;
  }

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

  .day-summary {
    grid-template-columns: repeat(4, 1fr);
  }

  .trophy-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .btn-big {
    width: auto;
    align-self: flex-start;
    padding: 8px 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
