:root {
  color-scheme: dark;
  font: 16px/1.5 system-ui, sans-serif;
  background: #141817;
  color: #ecf1ed;
  --surface: #1d2321;
  --line: #343e39;
  --muted: #aebdb5;
  --accent: #9adac3;
  --warning: #edd1a1;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px));
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px));
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 300px; }
button, input, select { font: inherit; }
button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .85rem;
  min-height: 44px;
  color: inherit;
  background: #252d2a;
  cursor: pointer;
}
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { opacity: .55; cursor: wait; }
button.primary { background: var(--accent); color: #14251f; border-color: transparent; font-weight: 650; }
button.quiet { background: transparent; color: var(--accent); }
button.danger { color: #ffd6c5; }
h1, h2, h3, p { margin: 0; overflow-wrap: anywhere; }
h1 { font-size: clamp(1.65rem, 7vw, 2.5rem); line-height: 1.1; letter-spacing: -.04em; }
h2 { font-size: 1.18rem; letter-spacing: -.02em; }
h3 { font-size: 1rem; }
small, .muted { color: var(--muted); }
.shell { max-width: 750px; margin: auto; }
.top {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: calc(.85rem + var(--safe-top)) 1rem .85rem;
  border-bottom: 1px solid var(--line);
  font-weight: 650;
}
.top img { border-radius: 13px; }
main { padding: 1.25rem 1rem calc(6rem + var(--safe-bottom)); }
.hero {
  padding: 1.15rem;
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  background: linear-gradient(135deg, #273733, #1b2522 75%);
  border: 1px solid #43574d;
  border-radius: 18px;
}
.hero img { width: clamp(62px, 22vw, 104px); height: auto; border-radius: 25%; }
.hero p { color: #b5c9bf; margin-top: .4rem; }
.group { margin-top: 1.3rem; }
.group > h2, .group > h3 { margin-bottom: .6rem; }
.cards { display: grid; gap: .65rem; }
.grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card, .setting {
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}
.stock { display: flex; justify-content: space-between; gap: .65rem; text-align: left; width: 100%; }
.stock:has(.warning) { border-left: 3px solid #8b7755; }
.stock span:last-child { text-align: right; flex-shrink: 0; }
.stock small, .stock strong, .expense small { display: block; }
.expense p { font-weight: 650; color: var(--accent); font-variant-numeric: tabular-nums; }
.warning { color: var(--warning); }
.actions, .head { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; }
.head { justify-content: space-between; margin-bottom: .7rem; }
.segment { display: grid; gap: .4rem; grid-template-columns: 1fr 1fr; margin: 1rem 0; }
.segment button[aria-pressed="true"] { background: #30473e; color: #c4f4df; border-color: #56776a; font-weight: 650; }
#nav {
  position: fixed;
  z-index: 1;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(750px, 100%);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .15rem;
  padding: .45rem .35rem calc(.5rem + var(--safe-bottom));
  background: #1a201ef5;
  border-top: 1px solid var(--line);
}
#nav button { background: transparent; border-color: transparent; color: var(--muted); padding: .2rem 0; font-size: .69rem; }
#nav button span { display: block; font-size: 1.18rem; line-height: 1.25; }
#nav button[aria-current="page"] { background: #2b3b34; color: #c2f1dc; border-color: #394e44; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: .7rem; min-height: 59px; }
.setting input { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); flex-shrink: 0; }
.history { display: grid; gap: .55rem; }
.history article p { white-space: pre-line; }
dialog {
  background: var(--surface);
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 1.1rem;
  width: min(430px, calc(100% - 1.5rem));
  max-height: 88dvh;
}
dialog::backdrop { background: #000a; }
dialog form { display: grid; gap: .65rem; }
dialog label { display: grid; gap: .2rem; color: var(--muted); }
dialog input, dialog select { width: 100%; padding: .55rem; background: #141918; border: 1px solid var(--line); border-radius: 8px; color: #ecf1ed; }
dialog .actions { justify-content: flex-end; }
.toast {
  position: fixed;
  z-index: 2;
  bottom: calc(4.85rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 2rem);
  width: max-content;
  border: 1px solid #526b60;
  border-radius: 11px;
  padding: .6rem .9rem;
  background: #2c3d35;
}
@media (min-width: 640px) {
  .top { padding-left: 1.5rem; }
  main { padding-inline: 1.5rem; }
  .hero { padding: 1.5rem; }
  #nav button { font-size: .86rem; }
}
