:root {
  color-scheme: light;
  --bg: #f4f7f3;
  --surface: #ffffff;
  --surface-soft: #edf3ea;
  --ink: #1d2a23;
  --muted: #66746b;
  --line: #d9e2d5;
  --green: #247a51;
  --teal: #16707a;
  --gold: #b77816;
  --red: #c53b32;
  --shadow: 0 18px 48px rgba(30, 56, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(36, 122, 81, 0.1), transparent 34%),
    linear-gradient(315deg, rgba(22, 112, 122, 0.12), transparent 38%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
}

button,
input,
select {
  font: inherit;
  max-width: 100%;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  max-width: 100%;
  margin: 0 auto;
  padding: 32px 0;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 18px;
  font-size: 1.12rem;
}

.week-control {
  display: grid;
  grid-template-columns: 44px minmax(190px, auto) 44px;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.week-range {
  min-width: 0;
  min-height: 44px;
  display: grid;
  place-items: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.icon-button,
.ghost-button,
form button {
  border-radius: 8px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.icon-button {
  width: 44px;
  height: 44px;
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 8px 22px rgba(36, 122, 81, 0.12);
  font-size: 1.9rem;
  line-height: 1;
}

.icon-button:hover,
.ghost-button:hover,
form button:hover {
  transform: translateY(-1px);
}

.budget-panel,
.entry-form,
.ledger {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(217, 226, 213, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.budget-panel {
  padding: 22px;
  margin-bottom: 18px;
}

.budget-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(180px, 260px) auto;
  gap: 12px;
  align-items: end;
}

label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.money-input {
  display: flex;
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.money-input span {
  padding-left: 14px;
  color: var(--muted);
  font-weight: 800;
}

input,
select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 16px;
  padding: 0 12px;
}

.money-input input {
  min-height: 44px;
  border: 0;
  outline: 0;
}

form button {
  min-height: 46px;
  padding: 0 18px;
  background: var(--green);
  color: white;
  font-weight: 800;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.metric {
  padding: 16px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.metric span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.metric strong {
  font-size: clamp(1.35rem, 2.7vw, 2rem);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.progress-track {
  height: 14px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe8dc;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.2s ease, background 0.2s ease;
}

.alert-box {
  display: none;
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  font-weight: 800;
  line-height: 1.5;
}

.alert-box.is-visible {
  display: block;
}

.alert-box.warn {
  background: #fff4df;
  color: #734500;
}

.alert-box.danger {
  background: #ffe7e3;
  color: #8f2019;
}

.notification-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
  min-width: 0;
}

.notification-panel strong {
  display: block;
  margin-bottom: 4px;
}

.notification-panel p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.install-guide {
  margin-top: 6px;
  line-height: 1.45;
}

.notification-actions {
  display: grid;
  grid-template-columns: auto 132px auto auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.entry-form,
.ledger {
  padding: 20px;
}

.entry-form {
  display: grid;
  gap: 10px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title h2 {
  margin-bottom: 0;
}

.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
}

.day-list {
  display: grid;
  gap: 12px;
}

.day-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.day-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: #f8faf7;
  font-weight: 800;
  min-width: 0;
}

.day-head span {
  min-width: 0;
}

.day-head span:last-child {
  color: var(--teal);
}

.expense-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.empty-day {
  margin: 0;
  padding: 13px 14px;
  color: var(--muted);
}

.expense-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  min-width: 0;
}

.expense-row > div:first-child {
  min-width: 0;
}

.expense-title {
  display: block;
  overflow-wrap: anywhere;
}

.expense-memo {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.expense-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 0;
}

.expense-amount {
  font-weight: 900;
}

.delete-button {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #f1f4ef;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.delete-button:hover {
  background: #ffe7e3;
  color: var(--red);
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding: 18px 0 calc(24px + env(safe-area-inset-bottom));
  }

  .topbar,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar > div:first-child {
    min-width: 0;
  }

  .week-control,
  .budget-form,
  .summary-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

  .week-control {
    grid-template-columns: 44px 1fr 44px;
  }

  .budget-panel,
  .entry-form,
  .ledger {
    padding: 16px;
  }

  form button,
  .ghost-button {
    width: 100%;
    min-height: 48px;
  }

  .notification-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .notification-actions {
    grid-template-columns: 1fr;
  }

  .icon-button {
    width: 48px;
    height: 48px;
  }

  .week-control {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
  }

  .week-range {
    min-width: 0;
    min-height: 48px;
    padding: 0 8px;
    font-size: 0.95rem;
  }

  .money-input,
  input,
  select {
    min-height: 48px;
  }

  .money-input input {
    min-height: 46px;
  }

  .metric {
    padding: 14px;
  }

  .metric strong {
    font-size: 1.55rem;
  }

  .progress-meta {
    flex-wrap: wrap;
  }

  .day-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 520px) {
  body {
    background: var(--bg);
  }

  .app-shell {
    width: 100%;
    padding: calc(12px + env(safe-area-inset-top)) 10px calc(18px + env(safe-area-inset-bottom));
  }

  .topbar {
    gap: 14px;
    margin-bottom: 12px;
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  h1 {
    font-size: 1.7rem;
    line-height: 1.2;
  }

  h2 {
    font-size: 1.05rem;
  }

  .budget-panel {
    margin-bottom: 12px;
  }

  .budget-panel,
  .entry-form,
  .ledger {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .summary-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 14px 0;
  }

  .metric:last-child {
    grid-column: auto;
  }

  .workspace {
    gap: 12px;
  }

  .entry-form {
    gap: 8px;
  }

  .ledger {
    padding-left: 10px;
    padding-right: 10px;
  }

  .section-title {
    gap: 10px;
  }

  .day-list {
    gap: 10px;
  }

  .day-head {
    padding: 11px 12px;
    font-size: 0.94rem;
  }

  .expense-row {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .expense-actions {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  .delete-button {
    width: 36px;
    height: 36px;
  }
}
