:root {
  --ink: #10241D;
  --mist: #EAF2EE;
  --card: #FFFFFF;
  --line: #D9E5DF;
  --deep: #0B4A3A;
  --green: #138A66;
  --green-dark: #0E6F52;
  --coin: #F5B82E;
  --muted: #5F7A6F;
  --danger: #C8372D;
  --radius: 18px;
  --shadow: 0 6px 22px rgba(11, 74, 58, 0.10);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--mist);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.02em; }
button { font-family: inherit; font-size: 15px; cursor: pointer; transition: transform .12s, background .15s, opacity .15s; }
button:active { transform: scale(0.97); }
:focus-visible { outline: 3px solid var(--coin); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- sign in ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: calc(24px + env(safe-area-inset-top, 0px)) 20px 24px;
  background: radial-gradient(circle at 20% 0%, #14705A 0%, var(--deep) 55%, #07372B 100%);
}
.auth-wrap[hidden] { display: none; }
.logo-mark {
  width: 64px; height: 64px; border-radius: 20px;
  background: var(--coin);
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.14), 0 10px 24px rgba(0,0,0,.25);
  position: relative; margin-bottom: 18px;
  animation: pop .6s cubic-bezier(.2,1.4,.4,1) both;
}
.logo-mark::before { /* coin slot of the box */
  content: ""; position: absolute; left: 16px; right: 16px; top: 22px; height: 8px;
  border-radius: 4px; background: var(--deep);
}
.logo-mark::after { /* coin dropping in */
  content: ""; position: absolute; left: 25px; top: -12px; width: 14px; height: 14px;
  border-radius: 50%; background: #fff; box-shadow: inset 0 -3px 0 #E2E8E4;
  animation: drop 2.4s ease-in .6s infinite;
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
@keyframes drop {
  0% { transform: translateY(-6px); opacity: 0; }
  15% { opacity: 1; }
  60% { transform: translateY(22px); opacity: 1; }
  70%, 100% { transform: translateY(26px); opacity: 0; }
}
.auth-title { color: #fff; font-size: 32px; text-align: center; }
.auth-sub { color: #B9D8CC; margin: 6px 0 26px; text-align: center; }
.auth-form {
  width: 100%; max-width: 360px;
  background: var(--card); border-radius: 24px; padding: 24px 22px 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.28);
}
.auth-form[hidden] { display: none; }
.auth-form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; font-weight: 600; }
.auth-form .primary-btn { width: 100%; padding: 14px; margin-top: 4px; }
.link-btn { background: none; border: none; color: var(--green-dark); font-weight: 700; padding: 0; font-size: inherit; }

/* ---------- top / hero ---------- */
.topbar {
  background: linear-gradient(160deg, #14705A 0%, var(--deep) 70%);
  color: #fff;
  padding: calc(26px + env(safe-area-inset-top, 0px)) 22px 64px;
  border-radius: 0 0 32px 32px;
  display: flex; justify-content: space-between; align-items: flex-start;
}
.topbar > div:first-child { max-width: 480px; }
.eyebrow { margin: 0 0 4px; font-size: 14px; color: #A9D3C3; }
.topbar h1 { font-size: 40px; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar .text-btn { color: #CFE8DD; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255,255,255,.14); border: none; color: #fff; font-size: 19px;
}
.icon-btn:hover { background: rgba(255,255,255,.24); }

main { max-width: 520px; margin: -40px auto 0; padding: 0 16px 110px; }
.box-list { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }

.box-card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); border-left: 6px solid var(--coin);
}
.box-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.box-card h3 { font-size: 19px; }
.box-balance { font-size: 21px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.box-purpose { margin: 4px 0 2px; font-size: 14px; color: var(--muted); }
.box-purpose strong { color: var(--ink); font-weight: 600; }
.box-target { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
.progress-track { height: 10px; background: #E5EFEA; border-radius: 6px; overflow: hidden; margin-bottom: 12px; }
.progress-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, var(--green), var(--coin));
  animation: fill 1s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes fill { from { width: 0; } }
.box-meta { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.dva-box {
  background: #F2F8F5; border: 1px dashed #BBD3C8; border-radius: 12px;
  padding: 10px 12px; margin-bottom: 12px; font-size: 13px;
}
.dva-box p { margin: 0 0 4px; }
.box-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty-state { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty-state p:first-child { font-size: 18px; font-weight: 700; color: var(--ink); margin: 0 0 4px; }

/* ---------- buttons ---------- */
.primary-btn {
  background: var(--green); color: #fff; border: none; border-radius: 14px;
  padding: 11px 18px; font-weight: 700; box-shadow: 0 4px 0 var(--green-dark);
}
.primary-btn:hover { background: #17996F; }
.primary-btn:active { box-shadow: 0 1px 0 var(--green-dark); transform: translateY(3px); }
.primary-btn:disabled { background: #A9C2B8; box-shadow: none; cursor: not-allowed; }
.secondary-btn {
  background: #fff; color: var(--green-dark); border: 2px solid var(--green);
  border-radius: 14px; padding: 8px 14px; font-weight: 700;
}
.secondary-btn:hover { background: #F2F8F5; }
.text-btn { background: none; border: none; color: var(--muted); padding: 8px 4px; font-weight: 600; }
.danger-btn {
  background: #fff; color: var(--danger); border: 2px solid var(--danger);
  border-radius: 14px; padding: 8px 14px; font-weight: 700;
}
#newBoxBtn {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: min(488px, calc(100% - 32px)); padding: 16px; font-size: 17px; border-radius: 18px;
  box-shadow: 0 4px 0 var(--green-dark), 0 14px 30px rgba(11,74,58,.3);
}
#newBoxBtn:active { transform: translate(-50%, 3px); }

/* ---------- forms + sheets ---------- */
form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; font-weight: 600; }
form input, form select {
  display: block; width: 100%; margin-top: 5px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 12px; font-size: 16px;
  color: var(--ink); background: #fff; font-family: inherit;
}
form input:focus, form select:focus { outline: none; border-color: var(--green); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

dialog {
  border: none; border-radius: 26px; padding: 24px 22px;
  max-width: 420px; width: calc(100% - 28px); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
}
dialog[open] { animation: sheet .28s cubic-bezier(.2,.9,.3,1); }
dialog::backdrop { background: rgba(7, 55, 43, 0.55); }
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
dialog h2 { font-size: 22px; margin-bottom: 14px; }
dialog section { margin-bottom: 22px; }
dialog h3 { font-size: 15px; color: var(--green-dark); margin-bottom: 8px; }
@media (max-width: 600px) {
  dialog { margin: auto auto 0; border-radius: 26px 26px 0 0; width: 100%; max-width: none; }
}

.item-list { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex; justify-content: space-between; align-items: center;
  background: #F2F8F5; border-radius: 12px; padding: 10px 12px; font-size: 14px;
}
.item-row button { background: none; border: none; color: var(--danger); font-size: 13px; font-weight: 700; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px;
  font-size: 14px; max-width: calc(100% - 32px); z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: toast .25s ease-out;
}
@keyframes toast { from { opacity: 0; transform: translate(-50%, 12px); } }

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