:root {
  color-scheme: light;
  --bg: #f4f1eb;
  --surface: #ffffff;
  --surface-soft: #f9f7f3;
  --ink: #20211f;
  --muted: #6d716a;
  --line: #ddd8cf;
  --accent: #18705c;
  --accent-dark: #0f5747;
  --warn: #b64435;
  --shadow: 0 18px 50px rgba(28, 31, 28, 0.1);
}

body[data-theme="sakura"] {
  --bg: #fff2f4;
  --surface: #ffffff;
  --surface-soft: #fff8f9;
  --ink: #2d2025;
  --muted: #7b626a;
  --line: #ecd2d9;
  --accent: #c84d72;
  --accent-dark: #9f3658;
  --warn: #a84332;
}

body[data-theme="sky"] {
  --bg: #eef7fb;
  --surface: #ffffff;
  --surface-soft: #f5fbfd;
  --ink: #17262c;
  --muted: #60757d;
  --line: #cfe1e8;
  --accent: #197a9a;
  --accent-dark: #115d76;
  --warn: #b34a38;
}

body[data-theme="mono"] {
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-soft: #f8f8f6;
  --ink: #1f1f1d;
  --muted: #666660;
  --line: #d8d8d2;
  --accent: #3f4a45;
  --accent-dark: #2c3430;
  --warn: #a44135;
}

body[data-theme="lemon"] {
  --bg: #fff8cf;
  --surface: #ffffff;
  --surface-soft: #fffdf0;
  --ink: #272416;
  --muted: #7a7047;
  --line: #eadf9d;
  --accent: #d6a800;
  --accent-dark: #9b7600;
  --warn: #b44c35;
}

body[data-theme="mint"] {
  --bg: #eafff6;
  --surface: #ffffff;
  --surface-soft: #f4fff9;
  --ink: #173029;
  --muted: #5e7b71;
  --line: #c9eadc;
  --accent: #24a474;
  --accent-dark: #147a55;
  --warn: #b34a38;
}

body[data-theme="peach"] {
  --bg: #fff0e6;
  --surface: #ffffff;
  --surface-soft: #fff8f3;
  --ink: #31231d;
  --muted: #80695d;
  --line: #efd4c4;
  --accent: #e06d45;
  --accent-dark: #b64d2b;
  --warn: #a63f35;
}

body[data-theme="lavender"] {
  --bg: #f5efff;
  --surface: #ffffff;
  --surface-soft: #fbf8ff;
  --ink: #29213a;
  --muted: #6f6385;
  --line: #ddd0f2;
  --accent: #7a5ccf;
  --accent-dark: #5a3da8;
  --warn: #aa4638;
}

body[data-theme="aqua"] {
  --bg: #eafbff;
  --surface: #ffffff;
  --surface-soft: #f4fdff;
  --ink: #152c34;
  --muted: #5b7880;
  --line: #c6e6ee;
  --accent: #19a7bd;
  --accent-dark: #087b8d;
  --warn: #b24b36;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

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

.summary-band {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px;
  background: var(--accent-dark);
  color: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-icon {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.eyebrow {
  margin: 0 0 6px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(32px, 6vw, 56px);
  letter-spacing: 0;
}

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

.budget-editor {
  display: grid;
  gap: 8px;
  min-width: min(280px, 100%);
}

.budget-editor label {
  color: rgba(255, 255, 255, 0.82);
  font-weight: 700;
}

.money-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 14px;
  background: #fff;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
}

.money-input input,
.entry-form input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.money-input input {
  border: 0;
  outline: 0;
  padding: 12px 0;
}

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

.metrics article,
.entry-form,
.history {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(28, 31, 28, 0.06);
}

.metrics article {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.metrics span {
  color: var(--muted);
  font-size: 14px;
}

.metrics strong {
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.1;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 18px 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-button {
  min-width: 88px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.tab-button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.icon-tab {
  min-width: 48px;
  font-size: 20px;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  align-items: start;
}

.entry-form,
.history {
  padding: 22px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.entry-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.entry-form input,
select {
  min-height: 46px;
  padding: 10px 12px;
  font-size: 16px;
  min-width: 0;
  max-width: 100%;
}

.entry-form button,
.secondary,
.theme-grid button {
  min-height: 48px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.entry-form button {
  width: 100%;
  margin-top: 18px;
  border: 0;
  background: var(--accent);
  color: #fff;
}

.entry-form button:hover {
  background: var(--accent-dark);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-action {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent);
  cursor: pointer;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.secondary {
  padding: 0 14px;
  background: var(--surface-soft);
  color: var(--warn);
  border: 1px solid var(--line);
}

.select-label {
  display: grid;
  grid-template-columns: minmax(120px, 180px);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

th,
td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.amount-cell {
  text-align: right;
}

.delete-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--warn);
  cursor: pointer;
}

.empty-state {
  margin: 18px 0 0;
  padding: 18px;
  background: var(--surface-soft);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.year-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.year-summary article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.year-summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.year-summary strong {
  font-size: 22px;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.theme-grid button {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
}

.theme-grid button.is-active {
  outline: 3px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-color: var(--accent);
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line);
}

.swatch.fresh {
  background: linear-gradient(135deg, #18705c 0 50%, #f4f1eb 50%);
}

.swatch.sakura {
  background: linear-gradient(135deg, #c84d72 0 50%, #fff2f4 50%);
}

.swatch.sky {
  background: linear-gradient(135deg, #197a9a 0 50%, #eef7fb 50%);
}

.swatch.mono {
  background: linear-gradient(135deg, #3f4a45 0 50%, #f4f4f2 50%);
}

.swatch.lemon {
  background: linear-gradient(135deg, #d6a800 0 50%, #fff8cf 50%);
}

.swatch.mint {
  background: linear-gradient(135deg, #24a474 0 50%, #eafff6 50%);
}

.swatch.peach {
  background: linear-gradient(135deg, #e06d45 0 50%, #fff0e6 50%);
}

.swatch.lavender {
  background: linear-gradient(135deg, #7a5ccf 0 50%, #f5efff 50%);
}

.swatch.aqua {
  background: linear-gradient(135deg, #19a7bd 0 50%, #eafbff 50%);
}

.is-hidden {
  display: none;
}

.collapsible-content.is-hidden {
  display: none;
}

.over-budget {
  color: var(--warn);
}

@media (max-width: 780px) {
  body {
    background: var(--surface);
  }

  .app-shell {
    width: 100%;
    padding: 0 0 24px;
  }

  .summary-band,
  .workspace {
    grid-template-columns: 1fr;
  }

  .summary-band {
    display: grid;
    align-items: stretch;
    border-radius: 0 0 18px 18px;
    padding: calc(18px + env(safe-area-inset-top)) 16px 18px;
  }

  .brand-block {
    align-items: center;
  }

  .app-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }

  h1 {
    font-size: 30px;
  }

  h2 {
    font-size: 18px;
  }

  .budget-editor {
    min-width: 0;
  }

  .year-summary,
  .theme-grid {
    grid-template-columns: 1fr;
  }

  .year-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .metrics article {
    min-width: 0;
    gap: 4px;
    padding: 10px 8px;
    border-radius: 8px;
  }

  .metrics span {
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
  }

  .metrics strong {
    font-size: clamp(18px, 6vw, 26px);
    overflow-wrap: anywhere;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    justify-content: stretch;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 20px rgba(28, 31, 28, 0.08);
  }

  .tab-button {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    padding: 0 8px;
    font-size: 15px;
  }

  .workspace,
  .tab-panel {
    padding: 0 12px;
  }

  .workspace {
    gap: 12px;
  }

  .entry-form,
  .history {
    width: 100%;
    min-width: 0;
    padding: 16px;
    box-shadow: none;
  }

  .form-grid,
  .entry-form label {
    min-width: 0;
  }

  input[type="date"] {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    appearance: none;
    -webkit-appearance: none;
  }

  input[type="date"]::-webkit-date-and-time-value {
    text-align: center;
  }

  .history-header {
    display: flex;
    align-items: center;
  }

  table {
    min-width: 0;
  }

  th,
  td {
    padding: 12px 6px;
    font-size: 14px;
  }

  .delete-btn {
    width: 42px;
    height: 42px;
  }
}
