:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #101010;
  --panel-soft: #151515;
  --line: #262626;
  --line-strong: #3a3a3a;
  --text: #f4f4f1;
  --muted: #a6a6a0;
  --subtle: #70706a;
  --inverse: #060606;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 560px);
  margin: 0 auto;
  padding: calc(18px + var(--safe-top)) 16px calc(42px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 2px 0 16px;
}

.brand {
  min-width: 0;
}

.brand h1,
.section-heading h2,
.sheet-heading h2 {
  margin: 0;
  color: var(--text);
  font-weight: 620;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", sans-serif;
  font-weight: 800;
  line-height: 1.05;
}

.brand p,
.hero-copy,
.metric-card span,
.setting-note,
.form-message {
  color: var(--muted);
}

.brand p {
  margin: 5px 0 0;
  font-size: 0.88rem;
}

.ghost-button,
.secondary-button,
.danger-button,
.icon-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.ghost-button {
  padding: 0 14px;
  white-space: nowrap;
}

.ghost-button.compact {
  min-height: 42px;
  font-size: 0.86rem;
}

.icon-button {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  color: var(--muted);
  font-size: 1rem;
}

.ghost-button:active,
.secondary-button:active,
.danger-button:active,
.icon-button:active,
.primary-action:active {
  transform: translateY(1px);
}

.hero-panel,
.panel,
.metric-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-panel {
  padding: 24px 20px 22px;
}

.section-kicker {
  margin: 0 0 10px;
  color: var(--subtle);
  font-size: 0.71rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero-value {
  max-width: 100%;
  color: var(--text);
  font-size: clamp(1.85rem, 9.5vw, 4.25rem);
  font-weight: 680;
  letter-spacing: 0;
  line-height: 0.98;
  overflow-wrap: anywhere;
}

.hero-copy {
  max-width: 31rem;
  margin: 16px 0 0;
  font-size: 0.98rem;
  line-height: 1.5;
}

.primary-action-wrap {
  position: sticky;
  z-index: 20;
  bottom: calc(12px + var(--safe-bottom));
  margin: 14px 0 18px;
}

.primary-action {
  display: inline-flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--inverse);
  font-weight: 720;
  letter-spacing: 0;
  box-shadow: 0 18px 44px rgba(255, 255, 255, 0.08), 0 18px 60px rgba(0, 0, 0, 0.42);
  transition: transform 180ms ease, filter 180ms ease;
}

.primary-action.full {
  margin-top: 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0 0 18px;
}

.metric-card {
  min-width: 0;
  padding: 16px;
}

.metric-card p {
  margin: 0 0 13px;
  color: var(--subtle);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  min-height: 2.05rem;
  color: var(--text);
  font-size: clamp(1.55rem, 7vw, 2.25rem);
  font-weight: 650;
  letter-spacing: 0;
  line-height: 1;
  overflow-wrap: anywhere;
}

.metric-card span {
  display: block;
  min-height: 1.15rem;
  margin-top: 10px;
  font-size: 0.84rem;
  line-height: 1.35;
}

.metric-card span:empty {
  display: none;
}

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

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-heading h2,
.sheet-heading h2 {
  font-size: 1.08rem;
  line-height: 1.2;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.2;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-dot {
  display: inline-block;
  width: 18px;
  height: 2px;
  border-radius: 99px;
  background: var(--subtle);
}

.legend-dot.daily {
  background: #626262;
}

.legend-dot.rolling {
  background: #f4f4f1;
}

.legend-dot.weekly {
  border-top: 2px dashed #9a9a94;
  background: transparent;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 260px;
}

canvas {
  display: block;
  width: 100%;
  height: 260px;
}

.empty-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.45;
}

.weekly-list,
.entry-list {
  display: grid;
  gap: 10px;
}

.week-row,
.entry-row,
.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.week-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 15px;
}

.week-title,
.entry-main strong {
  display: block;
  margin: 0;
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 620;
  line-height: 1.25;
}

.week-range,
.entry-main span,
.week-stat span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.week-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.week-stat {
  min-width: 0;
}

.week-stat strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
  font-weight: 620;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.entry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.entry-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.entry-actions button {
  min-height: 38px;
  border-radius: var(--radius);
  padding: 0 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font-size: 0.82rem;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 12px calc(12px + var(--safe-bottom));
  background: rgba(0, 0, 0, 0.62);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  width: min(100%, 528px);
  max-height: calc(100vh - 28px - var(--safe-top));
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px 8px 0 0;
  background: #0b0b0b;
  padding: 10px 16px 18px;
  box-shadow: 0 -28px 80px rgba(0, 0, 0, 0.65);
  transform: translateY(22px);
  transition: transform 180ms ease;
}

.sheet-backdrop.open .sheet {
  transform: translateY(0);
}

.sheet-handle {
  width: 44px;
  height: 4px;
  margin: 2px auto 14px;
  border-radius: 99px;
  background: #393939;
}

.sheet-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #050505;
  color: var(--text);
  padding: 0 14px;
  outline: 0;
}

.field input:focus {
  border-color: #777771;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.06);
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 64px;
}

.input-with-unit em {
  position: absolute;
  right: 14px;
  top: 50%;
  color: var(--subtle);
  font-style: normal;
  transform: translateY(-50%);
}

.form-message,
.setting-note {
  min-height: 1.25rem;
  margin: 0 0 12px;
  font-size: 0.88rem;
  line-height: 1.4;
}

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

.secondary-button,
.danger-button,
.import-button {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
}

.danger-button {
  grid-column: 1 / -1;
  color: #f2f2ef;
  border-color: #565656;
  background: #171717;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  width: min(calc(100% - 32px), 430px);
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #ededeb;
  color: #080808;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 650;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 420px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 700px) {
  .app-shell {
    padding-top: 34px;
  }

  .primary-action-wrap {
    position: static;
  }

  .week-row {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    align-items: center;
  }

  .sheet-backdrop {
    align-items: center;
    padding: 24px;
  }

  .sheet {
    border-radius: var(--radius);
  }
}

@media (hover: hover) {
  .ghost-button:hover,
  .secondary-button:hover,
  .danger-button:hover,
  .icon-button:hover,
  .entry-actions button:hover {
    border-color: var(--line-strong);
    background: rgba(255, 255, 255, 0.06);
  }

  .primary-action:hover {
    filter: brightness(0.96);
  }

}

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