:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #6b7672;
  --line: #d9dfdc;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --error: #b3261e;
  --toast-bg: #1c2321;
  --toast-text: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121514;
    --surface: #1c2120;
    --text: #e8eeeb;
    --muted: #9aa6a1;
    --line: #333b38;
    --accent: #4fb39a;
    --accent-text: #0b1512;
    --error: #ff8a80;
    --toast-bg: #e8eeeb;
    --toast-text: #121514;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 96px;
}

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

.header__title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}

.sync-status {
  margin: 4px 2px 0;
  min-height: 1.4em;
  font-size: 13px;
  color: var(--muted);
}

.sync-status--error { color: var(--error); }

.settings {
  width: min(440px, calc(100% - 32px));
  padding: 20px 16px 12px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}

.settings::backdrop { background: rgba(0, 0, 0, 0.45); }

.settings__title {
  margin: 0 0 4px;
  font-size: 17px;
}

.settings__message {
  margin: 0;
  min-height: 1.4em;
  font-size: 14px;
  color: var(--muted);
}

.settings__buttons {
  display: flex;
  gap: 10px;
}

.button {
  flex: 1;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.settings__close {
  margin-top: 4px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 18px; /* 16px 未満だとズームされる端末があるため大きめ */
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.field--date input { font-size: 16px; }

.amount {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.amount:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.amount__yen {
  font-size: 28px;
  color: var(--muted);
}

.amount input {
  border: 0;
  outline: 0;
  padding-left: 0;
  min-height: 64px;
  font-size: 34px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: transparent;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

input[hidden] { display: none; }

.error {
  margin: 0;
  color: var(--error);
  font-size: 14px;
}

.save {
  margin-top: 6px;
  min-height: 56px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.save:active { transform: scale(0.98); }

.status {
  display: flex;
  justify-content: space-between;
  margin: 14px 2px 0;
  font-size: 14px;
  color: var(--muted);
}

.status b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.recent { margin-top: 20px; }

.recent__title {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.recent__list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.recent__list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.recent__time {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.recent__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent__amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.recent__pending {
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted);
}

.recent__empty {
  margin: 10px 2px;
  color: var(--muted);
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 448px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 15px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.toast[hidden] { display: none; }

.toast__undo {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  padding: 6px;
  cursor: pointer;
}
