:root {
  --bg: #0b1222;
  --surface: #131c2f;
  --surface-2: #1b2640;
  --line: #26324b;
  --text: #eef3fb;
  --muted: #8d99b1;
  --intake: #3b82f6;
  --output: #f59e0b;
  --good: #22c55e;
  --bad: #f87171;
  --danger: #ef4444;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

h1 {
  font-size: 22px;
}

h2 {
  font-size: 17px;
}

h3 {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 6px;
}

button,
input {
  font: inherit;
  color: inherit;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 16px 96px;
}

.icon {
  width: 20px;
  height: 20px;
  vertical-align: -4px;
  flex-shrink: 0;
}

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

.good {
  color: var(--good) !important;
}

.bad {
  color: var(--bad) !important;
}

.center {
  text-align: center;
}

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

.loading {
  color: var(--muted);
  text-align: center;
  padding: 48px 0;
}

/* ---- Top bar ---- */

.topbar {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  padding: 18px 0 10px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 700;
}

.brand-mark {
  width: 24px;
  height: 24px;
  color: var(--intake);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.page-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 8px;
}

.page-lead {
  margin: 4px 0 18px;
}

/* ---- Cards and panels ---- */

.card {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius);
  padding: 14px;
}

.panel {
  margin-top: 14px;
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

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

.stat {
  padding: 12px;
  display: grid;
  gap: 6px;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat strong {
  font-size: 24px;
  font-weight: 700;
  white-space: nowrap;
}

.stat strong small {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

.stat.in .stat-label .icon {
  color: var(--intake);
}

.stat.out .stat-label .icon {
  color: var(--output);
}

.stat.good strong {
  color: var(--good);
}

.stat.bad strong {
  color: var(--bad);
}

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

.legend span::before,
.legend-inline span::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  background: var(--muted);
}

.legend .intake::before,
.legend-inline .intake::before {
  background: var(--intake);
}

.legend .output::before,
.legend-inline .output::before {
  background: var(--output);
}

.legend .net::before {
  background: var(--intake);
  border-radius: 0;
  height: 2px;
  margin-bottom: 3px;
}

.legend-inline {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
}

.callout {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface-2);
  text-align: center;
}

.callout strong {
  font-size: 18px;
}

.callout.good strong {
  color: var(--good);
}

.callout.bad strong {
  color: var(--bad);
}

.callout p {
  color: var(--muted);
  margin-top: 4px;
  font-size: 14px;
}

.notice {
  background: var(--surface-2);
  border-left: 3px solid var(--output);
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.45;
}

.notice.error {
  border-left-color: var(--bad);
}

.notice .link {
  padding: 0;
}

.banner {
  width: 100%;
  display: block;
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--output);
  background: rgba(245, 158, 11, 0.12);
  text-align: center;
  font-weight: 600;
  cursor: pointer;
}

/* ---- Balance chart and clock ring ---- */

.balance-chart,
.bars {
  width: 100%;
  height: auto;
  display: block;
}

.axis {
  fill: var(--muted);
  font-size: 11px;
}

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

.grid.zero {
  stroke: #4a5673;
  stroke-dasharray: 4 4;
}

.area {
  fill: rgba(59, 130, 246, 0.16);
}

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

.marker {
  cursor: pointer;
}

.marker .hit {
  fill: transparent;
}

.marker .dot {
  stroke: var(--surface);
  stroke-width: 2.5;
}

.marker.intake .dot {
  fill: var(--intake);
}

.marker.output .dot {
  fill: var(--output);
}

.marker:focus {
  outline: none;
}

.marker:focus .dot {
  stroke: var(--text);
}

.badge rect {
  fill: var(--good);
}

.badge.bad rect {
  fill: var(--danger);
}

.badge text {
  fill: #fff;
  font-size: 13px;
  font-weight: 700;
}

.bar.intake {
  fill: var(--intake);
}

.bar.output {
  fill: var(--output);
}

.clock-ring {
  width: 100%;
  max-width: 320px;
  height: auto;
  display: block;
  margin: 0 auto;
}

.ring-track {
  fill: none;
  stroke: var(--line);
  stroke-width: 14;
}

.ring-label {
  fill: var(--muted);
  font-size: 11px;
}

.ring-dot {
  cursor: pointer;
  stroke: var(--surface);
  stroke-width: 2;
}

.ring-dot.intake {
  fill: var(--intake);
}

.ring-dot.output {
  fill: var(--output);
}

.ring-now {
  fill: var(--text);
}

.ring-net {
  font-size: 30px;
  font-weight: 700;
  fill: var(--good);
}

.ring-net.bad {
  fill: var(--bad);
}

.ring-caption {
  fill: var(--muted);
  font-size: 13px;
}

/* ---- Lists ---- */

.list {
  display: grid;
}

.row {
  display: grid;
  grid-template-columns: 30px 72px auto 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 2px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}

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

.row-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.05);
}

.row-icon .icon {
  width: 17px;
  height: 17px;
}

.row-icon.intake {
  color: var(--intake);
}

.row-icon.output {
  color: var(--output);
}

.row-time {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.row-amount {
  font-weight: 700;
  white-space: nowrap;
}

.row-amount.intake {
  color: var(--intake);
}

.row-amount.output {
  color: var(--output);
}

.row-detail {
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row.day-row {
  grid-template-columns: 1fr;
  gap: 2px;
}

.day-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.day-head span {
  font-weight: 700;
  font-size: 14px;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn.primary {
  background: var(--intake);
  border-color: var(--intake);
  color: #fff;
}

.btn.primary.output {
  background: var(--output);
  border-color: var(--output);
  color: #1a1204;
}

.btn.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn.danger.huge {
  background: var(--danger);
  color: #fff;
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.inline-form input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 16px;
  color: var(--text);
}

.fluid-list {
  margin-top: 12px;
}

.fluid-list .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chip-x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  padding: 0 0 0 4px;
  cursor: pointer;
}

.btn.sign-out {
  margin-top: 14px;
}

.btn.ghost {
  background: transparent;
}

#older {
  margin-top: 18px;
}

.btn.big {
  width: 100%;
  padding: 16px;
}

.btn.huge {
  width: 100%;
  padding: 30px 18px;
  font-size: 24px;
  border-radius: 24px;
}

.link {
  background: none;
  border: none;
  color: var(--intake);
  font-size: 14px;
  font-weight: 600;
  padding: 6px;
  cursor: pointer;
}

.link:disabled {
  opacity: 0.5;
}

.link.center {
  display: block;
  margin: 12px auto 0;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  margin: 8px 0 14px;
  background: var(--surface);
  border-radius: 14px;
}

.segmented button {
  padding: 10px 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.segmented button.active {
  background: var(--intake);
  color: #fff;
}

/* ---- Forms ---- */

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

.form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.form input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 16px;
  color: var(--text);
  color-scheme: dark;
}

.form input:focus {
  outline: 2px solid var(--intake);
  outline-offset: 1px;
}

.hint {
  font-size: 12px;
}

.form-error {
  color: var(--bad);
  font-size: 14px;
  min-height: 0;
}

.form-error:empty {
  display: none;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-line {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.amount-field {
  display: flex !important;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.amount-field input {
  width: 160px;
  text-align: center;
  font-size: 44px !important;
  font-weight: 700;
  background: transparent !important;
  border: none !important;
  padding: 0;
}

.amount-field input:focus {
  outline: none;
}

.amount-field span {
  color: var(--muted);
  font-size: 18px;
  font-weight: 600;
}

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

.chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
}

.chip.active {
  background: var(--intake);
  border-color: var(--intake);
  color: #fff;
}

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

.flow-btn {
  display: grid;
  gap: 4px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.flow-btn strong {
  font-size: 16px;
}

.flow-btn small {
  color: var(--muted);
  font-size: 13px;
}

.flow-btn.active {
  border-color: var(--output);
  box-shadow: inset 0 0 0 1px var(--output);
}

.flow-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.flow-grid .flow-btn:last-child:nth-child(odd) {
  grid-column: span 2;
}

.result {
  background: var(--surface-2);
  padding: 12px;
  border-radius: 12px;
  font-size: 15px;
}

.steps {
  margin: 0;
  padding-left: 20px;
  line-height: 1.65;
  color: var(--muted);
}

/* ---- Record chooser ---- */

.choice-grid {
  display: grid;
  gap: 14px;
}

.choice {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 30px 16px;
  border: none;
  border-radius: 22px;
  color: #fff;
  cursor: pointer;
  text-align: center;
}

.choice.intake {
  background: linear-gradient(160deg, #3b82f6, #1d4ed8);
}

.choice.output {
  background: linear-gradient(160deg, #fbbf24, #d97706);
  color: #1a1204;
}

.choice strong {
  font-size: 24px;
}

.choice span {
  font-size: 14px;
  opacity: 0.85;
}

.choice-icon {
  width: 46px !important;
  height: 46px !important;
  margin-bottom: 4px;
}

/* ---- Timer ---- */

.timer-face {
  text-align: center;
  padding: 30px 0 22px;
}

.timer {
  font-size: 76px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.timer-face.running .timer {
  color: var(--output);
}

/* ---- Settings ---- */

.list-card {
  padding: 0 14px;
}

.setting-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 16px 2px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}

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

.setting-row small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.setting-row .icon {
  color: var(--muted);
}

.rate-row {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 16px !important;
  color: var(--text) !important;
}

.rate-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rate-input input {
  width: 130px;
  text-align: right;
}

.rate-input small {
  color: var(--muted);
  font-size: 13px;
  width: 52px;
}

.email {
  color: var(--text);
  word-break: break-all;
}

/* ---- Auth ---- */

.auth {
  padding-top: 36px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 22px;
}

.auth-brand h1 {
  font-size: 30px;
  margin-top: 8px;
}

.auth-brand p {
  margin-top: 4px;
}

.brand-icon {
  width: 46px !important;
  height: 46px !important;
  color: var(--intake);
}

.auth-card h2 {
  margin-bottom: 16px;
}

.auth-card {
  padding: 20px;
}

.auth-links {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* ---- Bottom tabs ---- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: end;
  padding: 4px max(16px, calc(50% - 224px)) calc(4px + env(safe-area-inset-bottom));
  background: rgba(19, 28, 47, 0.8);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
  z-index: 20;
}

.tabbar button {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 2px 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.tabbar button .icon {
  width: 30px;
  height: 30px;
  vertical-align: 0;
}

.tabbar button.active {
  color: var(--text);
}

.tabbar button.active:not(.record-btn) .icon {
  color: var(--intake);
}


.record-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--intake);
  color: #fff;
}

.tabbar .record-circle .icon {
  width: 16px;
  height: 16px;
  vertical-align: 0;
}

/* ---- Toasts and sheets ---- */

.toasts {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(440px, calc(100% - 32px));
  z-index: 60;
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  text-align: center;
  font-weight: 600;
}

.toast.error {
  border-color: var(--danger);
  color: var(--bad);
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 15, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}

.sheet {
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
  animation: rise 0.2s ease-out;
}

@keyframes rise {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}

.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 0 auto 14px;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sheet-head .row-icon {
  width: 42px;
  height: 42px;
}

.sheet-head .row-icon .icon {
  width: 22px;
  height: 22px;
}

.sheet-head .row-icon.intake {
  color: var(--intake);
}

.sheet-head .row-icon.output {
  color: var(--output);
}

.sheet-amount {
  font-size: 28px;
  font-weight: 700;
  margin-top: 2px;
}

.sheet-amount.intake {
  color: var(--intake);
}

.sheet-amount.output {
  color: var(--output);
}

.details {
  display: grid;
  gap: 10px;
  margin: 18px 0 0;
}

.details div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  font-weight: 600;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

@media (min-width: 520px) {
  .app {
    padding-top: 8px;
  }
}
