:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  --bg: #050a18;
  --surface: rgba(9, 18, 42, 0.72);
  --surface-2: rgba(255, 215, 83, 0.11);
  --field: rgba(0, 0, 0, 0.23);
  --text: #f7f2dd;
  --muted: #9aa7c6;
  --line: rgba(255, 215, 83, 0.18);
  --accent: #ffd753;
  --accent-dark: #ffe997;
  --danger: #ff755f;
  --copper: #ff9f43;
  --navy: #07122b;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.58);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 14%, rgba(255, 215, 83, 0.24), transparent 28%),
    radial-gradient(circle at 82% 74%, rgba(30, 77, 170, 0.34), transparent 36%),
    linear-gradient(145deg, #020613, #071432 54%, #020613);
}

.ambient-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.82;
  mix-blend-mode: screen;
}

.auth-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 42% 22%, rgba(255, 215, 83, 0.22), transparent 26%),
    rgba(2, 6, 19, 0.84);
  backdrop-filter: blur(18px);
}

.auth-panel[hidden] {
  display: none;
}

.auth-card {
  width: min(100%, 360px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(5, 10, 24, 0.92);
  box-shadow: var(--shadow);
}

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

.auth-form[hidden] {
  display: none;
}

.auth-pair {
  display: grid;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.auth-pair:last-of-type {
  border-bottom: 0;
}

.auth-card input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0 12px;
  color: var(--text);
  background: var(--field);
  outline: none;
}

.auth-card input:focus {
  border-color: rgba(255, 215, 83, 0.72);
  box-shadow: 0 0 0 3px rgba(255, 215, 83, 0.14);
}

.auth-error {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.auth-switch {
  margin-top: 8px;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.phone-shell {
  position: relative;
  width: min(100%, 390px);
  height: min(844px, calc(100vh - 64px));
  min-height: 720px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 215, 83, 0.2);
  border-radius: 30px;
  padding: 14px;
  background:
    linear-gradient(160deg, rgba(255, 215, 83, 0.13), rgba(255, 255, 255, 0.035)),
    rgba(5, 10, 24, 0.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(26px) saturate(132%);
  animation: shellFloat 7s ease-in-out infinite;
}

.app-header {
  z-index: 3;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: 4px 0 14px;
}

.tab-content {
  flex: 1 1 auto;
  min-height: 0;
}

.tab-panel {
  height: 100%;
  overflow-y: auto;
  padding-bottom: 4px;
}

.tab-panel[hidden] {
  display: none;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--text);
  background: transparent;
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.month-button {
  height: 38px;
  border-radius: 9px;
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  background: transparent;
}

.summary,
.entry,
.history,
.category-manager {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.summary {
  padding: 18px;
}

.summary-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.caption,
.summary h1,
.section-title h2 {
  margin: 0;
}

.caption {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.summary h1 {
  margin-top: 6px;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.trend {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.summary-grid article {
  min-width: 0;
  padding: 10px;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.035);
}

.summary-grid span,
.summary-grid strong {
  display: block;
}

.summary-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-grid strong {
  margin-top: 5px;
  font-size: 15px;
}

.entry,
.history,
.category-manager {
  margin-top: 12px;
  padding: 14px;
}

.tab-panel > .entry,
.tab-panel > .summary,
.tab-panel > .category-manager {
  margin-top: 0;
}

#panel-add {
  overflow: hidden;
}

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

.section-title h2 {
  font-size: 18px;
  line-height: 1.2;
}

.ghost-button {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  background: transparent;
}

.mini-note {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.user-toggle,
.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
}

.user-toggle button,
.type-toggle button {
  height: 36px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  background: transparent;
}

.user-toggle button:disabled {
  cursor: default;
  opacity: 0.54;
}

.user-toggle .selected,
.type-toggle .selected {
  color: var(--text);
  background: rgba(255, 215, 83, 0.2);
}

.type-toggle {
  margin-top: 10px;
}

.type-toggle button {
  height: 34px;
}

.amount-field,
.memo-field {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.amount-field span,
.memo-field span,
.settlement-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.amount-field input,
.memo-field input,
.settlement-box input,
.category-form input,
.expense-actions input {
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  background: var(--field);
  outline: none;
}

.amount-field input,
.memo-field input {
  width: 100%;
  height: 48px;
  padding: 0 13px;
}

.amount-field input {
  font-size: 30px;
  font-weight: 750;
}

.amount-field input:focus,
.memo-field input:focus,
.settlement-box input:focus,
.category-form input:focus,
.expense-actions input:focus {
  border-color: rgba(255, 215, 83, 0.72);
  box-shadow: 0 0 0 3px rgba(255, 215, 83, 0.14);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
}

.category-grid button {
  min-width: 0;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  background: transparent;
}

.category-grid button:nth-child(2n) {
  border-right: 0;
}

.category-grid button:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.category-grid button.fixed {
  order: 0;
}

.category-grid button.custom {
  order: 1;
}

.category-grid .selected {
  color: var(--accent-dark);
  background: rgba(255, 215, 83, 0.14);
}

.category-icon,
.list-icon {
  display: block;
  border-radius: 999px;
}

.category-icon {
  width: 11px;
  height: 11px;
}

.food { background: var(--accent); box-shadow: 0 0 14px rgba(255, 215, 83, 0.58); }
.goods { background: #9ca6a2; }
.train { background: #6d85d8; }
.dine { background: var(--copper); box-shadow: 0 0 14px rgba(255, 159, 67, 0.42); }
.other { background: #b2bbb7; }

.primary-button {
  width: 100%;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  border-radius: 10px;
  color: #09112a;
  font-weight: 800;
  background: linear-gradient(135deg, #ffe997, #ffd753 46%, #ffb627);
  box-shadow: 0 12px 34px rgba(255, 215, 83, 0.24);
  animation: pulseGlow 2.8s ease-in-out infinite;
}

.settlement-box {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
  align-items: end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.settlement-box label {
  display: grid;
  gap: 6px;
}

.settlement-box input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
}

.settlement-box button {
  height: 40px;
  border-radius: 9px;
  color: var(--accent-dark);
  font-weight: 800;
  background: rgba(255, 215, 83, 0.14);
}

.category-form {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 8px;
}

.category-form input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
}

.add-category-button {
  width: 40px;
  height: 40px;
  color: #03110c;
  border-color: var(--accent);
  background: var(--accent);
}

.category-list {
  display: grid;
  gap: 0;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
}

.category-list li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.category-list li:last-child {
  border-bottom: 0;
}

.category-list strong {
  font-size: 13px;
}

.category-list small {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.category-actions {
  display: inline-flex;
  gap: 4px;
}

.category-actions button {
  min-width: 36px;
  height: 30px;
  border-radius: 8px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 750;
  background: rgba(255, 215, 83, 0.13);
}

.category-actions button:last-child {
  color: var(--danger);
  background: rgba(255, 117, 95, 0.13);
}

.expense-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
}

.expense-list li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.expense-list li:last-child {
  border-bottom: 0;
}

.list-icon {
  width: 10px;
  height: 10px;
}

.expense-list strong,
.expense-list small {
  display: block;
}

.expense-list strong {
  font-size: 14px;
}

.expense-list small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.expense-list b {
  font-size: 14px;
}

.expense-actions {
  display: grid;
  justify-items: end;
  gap: 4px;
}

.expense-actions button {
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 750;
  background: transparent;
}

.expense-actions input {
  width: 88px;
  height: 32px;
  padding: 0 8px;
  text-align: right;
  font-size: 14px;
  font-weight: 750;
}

.expense-edit-buttons {
  display: inline-flex;
  gap: 8px;
}

.tab-bar {
  flex: 0 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 12px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.tab-bar button {
  min-width: 0;
  height: 52px;
  display: grid;
  place-items: center;
  gap: 3px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  background: transparent;
}

.tab-bar .active {
  color: var(--accent-dark);
  background: rgba(255, 215, 83, 0.13);
}

.tab-bar svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 860px) {
  body {
    padding: 0;
    background: #050a18;
  }

  .phone-shell {
    width: 100%;
    height: 100vh;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background:
      linear-gradient(160deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03)),
      rgba(5, 10, 24, 0.72);
  }

  .tab-bar {
    margin-bottom: max(0px, env(safe-area-inset-bottom));
  }
}

@keyframes pulseGlow {
  0%, 100% {
    transform: translateY(0);
    box-shadow: 0 12px 34px rgba(255, 215, 83, 0.22);
  }
  50% {
    transform: translateY(-1px);
    box-shadow: 0 18px 42px rgba(255, 215, 83, 0.34);
  }
}

@keyframes shellFloat {
  0%, 100% {
    transform: translateY(0) rotateX(0deg);
  }
  50% {
    transform: translateY(-5px) rotateX(1.4deg);
  }
}
