:root {
  --bg: #163a68;
  --bg-2: #1c4a7c;
  --card: rgba(16, 42, 74, 0.62);
  --card-2: rgba(22, 54, 92, 0.78);
  --line: rgba(186, 214, 240, 0.14);
  --text: #eef5fb;
  --muted: #9cb4c9;
  --green: #5ec4a4;
  --green-dim: rgba(94, 196, 164, 0.18);
  --gold: #c4a36a;
  --expense: #e07a72;
  --income: #5ec4a4;
  --shadow: 0 18px 40px rgba(6, 18, 40, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #163a68;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(1.2px 1.2px at 8% 12%, rgba(255,255,255,.75) 50%, transparent 52%),
    radial-gradient(1px 1px at 22% 28%, rgba(255,255,255,.55) 50%, transparent 52%),
    radial-gradient(1.4px 1.4px at 41% 8%, rgba(255,255,255,.7) 50%, transparent 52%),
    radial-gradient(1px 1px at 63% 18%, rgba(255,255,255,.45) 50%, transparent 52%),
    radial-gradient(1.2px 1.2px at 78% 6%, rgba(255,255,255,.8) 50%, transparent 52%),
    radial-gradient(1px 1px at 91% 22%, rgba(255,255,255,.5) 50%, transparent 52%),
    radial-gradient(1px 1px at 14% 48%, rgba(210,230,255,.45) 50%, transparent 52%),
    radial-gradient(1.3px 1.3px at 34% 62%, rgba(255,255,255,.55) 50%, transparent 52%),
    radial-gradient(1px 1px at 52% 41%, rgba(255,255,255,.4) 50%, transparent 52%),
    radial-gradient(1.2px 1.2px at 71% 55%, rgba(255,255,255,.65) 50%, transparent 52%),
    radial-gradient(1px 1px at 88% 47%, rgba(210,230,255,.5) 50%, transparent 52%),
    radial-gradient(1px 1px at 6% 78%, rgba(255,255,255,.4) 50%, transparent 52%),
    radial-gradient(1.2px 1.2px at 27% 86%, rgba(255,255,255,.55) 50%, transparent 52%),
    radial-gradient(1px 1px at 49% 74%, rgba(255,255,255,.35) 50%, transparent 52%),
    radial-gradient(1.4px 1.4px at 68% 82%, rgba(255,255,255,.7) 50%, transparent 52%),
    radial-gradient(1px 1px at 84% 91%, rgba(210,230,255,.45) 50%, transparent 52%),
    radial-gradient(900px 420px at 50% -80px, rgba(120, 178, 230, 0.42), transparent 62%),
    radial-gradient(700px 380px at 110% 20%, rgba(70, 130, 200, 0.28), transparent 58%),
    linear-gradient(180deg, #1e5a96 0%, #3a7ab8 38%, #5aa0d0 68%, #2468a0 100%);
}

#app { position: relative; z-index: 1; }

button, input {
  font: inherit;
  color: inherit;
  color-scheme: dark;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 20px calc(108px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.ghost, .month {
  background: none;
  border: 0;
  padding: 8px 12px;
}

.ghost {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 22px;
  line-height: 1;
}

.month {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.month-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.today-jump {
  position: relative;
  z-index: 2;
  border: 0;
  min-width: 64px;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--green-dim);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.today-jump.here {
  opacity: 0.4;
}

.hero {
  position: relative;
  overflow: hidden;
  padding: 22px 22px 18px;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(140, 196, 255, 0.22), transparent 46%),
    var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--green), transparent);
  opacity: 0.7;
}

.hero-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.hero-balance {
  margin: 8px 0 18px;
  font-size: 36px;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.hero-flow {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  gap: 12px;
  align-items: center;
}

.hero-flow span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.hero-flow strong {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.hero-flow .divider { height: 28px; background: var(--line); }
.hero-flow div:first-child strong { color: var(--income); }
.hero-flow div:last-child strong { color: var(--expense); }

.views {
  display: flex;
  gap: 4px;
  margin: 22px 0 14px;
}

.view-tab {
  flex: 1;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 0 2px;
}

.view-tab.active {
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.view { display: none; }
.view.active { display: block; }

.goal {
  margin-top: 14px;
  padding: 16px 18px 14px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.goal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
}

.goal-actions {
  display: flex;
  gap: 6px;
  letter-spacing: 0;
}

.goal-head button {
  border: 0;
  background: rgba(140, 196, 255, 0.12);
  color: var(--muted);
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  letter-spacing: 0;
}

.goal-head button.on {
  background: var(--green-dim);
  color: var(--green);
}

.goal-amt {
  margin: 10px 0 12px;
  font-variant-numeric: tabular-nums;
}

.goal-amt b {
  font-size: 22px;
  font-weight: 650;
}

.goal-amt span { color: var(--muted); font-size: 13px; }

.goal-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(8, 24, 48, 0.42);
  overflow: hidden;
}

.goal-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #3d7ec4, #8ecbff);
  transition: width 0.25s ease;
}

.goal-meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.plan-pace {
  margin: 8px 0 0;
  color: #cfe6ff;
  font-size: 13px;
  line-height: 1.45;
}

.plan-months {
  margin-top: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.plan-month {
  padding: 12px 0 10px;
  border-bottom: 1px solid var(--line);
}

.plan-month:last-child { border-bottom: 0; }

.plan-month header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 6px;
}

.plan-month .amt {
  margin: 0 0 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.tag {
  flex-shrink: 0;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0;
  display: grid;
  place-items: center;
}

.tag.ok { background: var(--green-dim); color: var(--green); }
.tag.over { background: rgba(196, 163, 106, 0.22); color: #e6c98a; }
.tag.miss { background: rgba(224, 122, 114, 0.18); color: #ff8b8b; }
.tag.wait { background: rgba(140, 196, 255, 0.12); color: var(--muted); }

.year-row {
  width: 100%;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  text-align: left;
}

.year-row b { font-size: 15px; }
.year-row .flow { min-width: 0; }
.year-row .flow span {
  display: block;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.year-row .income { color: var(--income); }
.year-row .expense { color: var(--expense); }
.year-row .net {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 14px;
}
.year-row .net.up { color: #7dffb6; }
.year-row .net.down { color: #ff8b8b; }
.year-row.now {
  border-color: rgba(142, 203, 255, 0.45);
}

.year-sum {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.year-sum div {
  padding: 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}

.year-sum span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.year-sum strong { font-variant-numeric: tabular-nums; }
.year-sum .expense { color: var(--expense); }
.year-sum .income { color: var(--income); }

.goal-sheet-title {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 600;
}

.cal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px 10px 12px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px 0;
}

.cal-cell {
  min-height: 52px;
  border: 0;
  background: none;
  padding: 4px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text);
}

.cal-cell .num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 600;
}

.cal-cell .spend {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 12px;
}

.cal-cell .spend.up { color: #7dffb6; font-weight: 700; }
.cal-cell .spend.down { color: #ff8b8b; font-weight: 700; }

.cal-cell.out { color: rgba(186, 214, 240, 0.38); }
.cal-cell.out .spend { color: rgba(186, 214, 240, 0.32); }
.cal-cell.out .spend.up { color: rgba(125, 255, 182, 0.55); }
.cal-cell.out .spend.down { color: rgba(255, 139, 139, 0.55); }
.cal-cell.selected .num {
  background: #2a6aa8;
  color: #f4f9ff;
}
.cal-cell.today:not(.selected) .num {
  box-shadow: inset 0 0 0 1px #8ecbff;
}

.day-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.day-nav b { font-size: 16px; }

.day-sum {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.day-sum div {
  padding: 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
}

.day-sum span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.day-sum strong { font-variant-numeric: tabular-nums; }
.day-sum .expense { color: var(--expense); }
.day-sum .income { color: var(--income); }

.day-label {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  cursor: pointer;
}

.tx-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--green-dim);
  font-size: 18px;
}

.tx-body { flex: 1; min-width: 0; }
.tx-body b { display: block; font-weight: 600; }
.tx-body span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tx-amt {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.tx-amt.expense { color: var(--expense); }
.tx-amt.income { color: var(--income); }

.empty {
  margin-top: 48px;
  text-align: center;
  color: var(--muted);
}

.empty p { margin: 8px 0 0; font-size: 13px; }

.bar-row { margin: 0 0 14px; }
.bar-row header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}
.bar-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(8, 24, 48, 0.42);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #3d7ec4, #8ecbff);
}

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(22px + var(--safe-bottom));
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 20px;
  background: linear-gradient(180deg, #6bb4ee, #2a6aa8);
  color: #f4f9ff;
  font-size: 30px;
  box-shadow: 0 12px 28px rgba(42, 106, 168, 0.42);
  z-index: 20;
}

.sheet-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 30;
  pointer-events: none;
}

.sheet-mask:not([hidden]) {
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 18px calc(16px + var(--safe-bottom));
  background: linear-gradient(180deg, #164878, #0f355c);
  border: 1px solid rgba(180, 214, 255, 0.18);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  transform: translateY(110%);
  transition: transform 0.28s ease, visibility 0.28s ease;
  z-index: 31;
  visibility: hidden;
  pointer-events: none;
}

.sheet.open {
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(180, 214, 255, 0.28);
  margin: 4px auto 14px;
}

.sheet-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 10px;
}

.sheet-tab {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
}

.sheet-tab.active {
  background: var(--green-dim);
  color: var(--green);
  border-color: transparent;
}

.amount-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0 12px;
}

.yen { color: var(--gold); font-size: 22px; }
.amount {
  display: flex;
  align-items: center;
  min-height: 48px;
  min-width: 28px;
  flex: 1;
  font-size: 40px;
  font-weight: 650;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  cursor: text;
}

.amount .ch {
  display: inline-block;
  padding: 4px 1px;
  min-width: 0.52em;
  text-align: center;
}

.amount .caret {
  width: 2px;
  height: 36px;
  margin: 0 1px;
  border-radius: 1px;
  background: #d7ecff;
  flex-shrink: 0;
  animation: caret-blink 1.1s steps(1) infinite;
}

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

.caret-nav {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.caret-nav button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--card-2);
  font-size: 20px;
  line-height: 1;
}

.plan-hint {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(140, 196, 255, 0.12);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.sheet.plan-mode .cats,
.sheet.plan-mode #tx-meta {
  display: none;
}

.plan-dates {
  grid-template-columns: 1fr 1fr;
}

.cats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.cat {
  border: 0;
  background: var(--card);
  border-radius: 14px;
  padding: 8px 0;
  color: var(--muted);
}

.cat small { display: block; font-size: 11px; margin-top: 2px; }
.cat.active {
  background: var(--green-dim);
  color: var(--text);
}

.meta {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.meta label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.meta input {
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 10px;
  font-size: 16px;
}

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

.keypad button {
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--card-2);
  font-size: 20px;
}

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

.save {
  width: 100%;
  margin-top: 10px;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #6bb4ee, #2a6aa8);
  font-weight: 650;
}

.danger {
  width: 100%;
  margin-top: 8px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: rgba(224, 122, 114, 0.16);
  color: #ff8b8b;
  font-weight: 650;
}

.sheet.edit-mode .sheet-tabs {
  grid-template-columns: 1fr 1fr;
}

.sheet.edit-mode .sheet-tab[data-type="plan"] {
  display: none;
}

#fixed-sheet .sheet-tabs {
  grid-template-columns: 1fr 1fr 1fr;
}

.fixed-days {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.fixed-days-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fixed-days-ctrl button {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: var(--card-2);
  font-size: 20px;
  line-height: 1;
}

.fixed-days-ctrl input {
  width: 56px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  text-align: center;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.install {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(92px + var(--safe-bottom));
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 18px;
  background: linear-gradient(180deg, #164878, #0f355c);
  border: 1px solid rgba(180, 214, 255, 0.2);
  box-shadow: var(--shadow);
  z-index: 25;
}

.install img { border-radius: 10px; }
.install p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.install button {
  border: 0;
  background: none;
  font-size: 22px;
  color: var(--muted);
}

.fixed-name {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.fixed-name input {
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 10px;
  font-size: 16px;
}

.fixed-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 0;
  border-radius: 14px;
  background: rgba(8, 24, 48, 0.28);
  color: inherit;
  text-align: left;
}

.fixed-item b { display: block; font-size: 14px; }
.fixed-item small { color: var(--muted); font-size: 12px; }
.fixed-item .amt {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--expense);
}

[hidden] { display: none !important; }
