:root {
  color-scheme: light;
  --orange: #ed812f;
  --paper: #fdf8e8;
  --row: #fcfbf9;
  --ink: #303030;
  --secondary: #909096;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-height: 100dvh;
  --visible-height: 100dvh;
  --visual-top: 0px;
  --panel-body: 294px;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--paper); }
body { color: var(--ink); }
button, input { font: inherit; color: inherit; }
button { -webkit-appearance: none; appearance: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--orange); outline-offset: -2px; }
button { -webkit-tap-highlight-color: transparent; }
.app {
  width: 100%; max-width: 480px; height: var(--app-height); position: fixed;
  top: var(--visual-top); left: 50%; transform: translateX(-50%); overflow: hidden; background: var(--paper);
}
.header {
  height: calc(44px + var(--safe-top)); padding-top: var(--safe-top); display: flex;
  align-items: center; justify-content: center; background: var(--orange); color: white;
}
.kind-switch { display: flex; width: 240px; height: 32px; padding: 2px; gap: 2px; border-radius: 8px; background: #de7f38; }
.kind-switch button { flex: 1; font-size: 14px; color: white; background: none; border-radius: 6px; }
.kind-switch [aria-pressed="true"] { background: white; color: var(--orange); box-shadow: 0 1px 2px #0002; }
.header h1 { margin: 0; font-size: 19px; font-weight: 400; }
.form-scroll {
  height: calc(var(--app-height) - 44px - var(--safe-top)); overflow: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.form-scroll::-webkit-scrollbar, .wheel-options::-webkit-scrollbar { display: none; }
.input-form { padding-bottom: calc(49px + var(--safe-bottom)); }
.top-space { height: 35px; }
.section-space { height: 36px; }
.input-row {
  width: 100%; height: 44px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--row); position: relative; text-align: left;
}
.input-row::after { content: ""; position: absolute; left: 16px; right: 0; bottom: 0; height: 1px; transform: scaleY(.33333); transform-origin: bottom; background: #bdb9b3; }
.amount-row::before, #category-field::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; transform: scaleY(.33333); background: #bdb9b3; }
.amount-row::after, #date-field::after { left: 0; }
.field-value { color: var(--secondary); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-left: 8px; }
.placeholder, #memo::placeholder { color: #bfbfbf; opacity: 1; }
.amount-row { justify-content: flex-start; }
#amount-text { max-width: 100%; min-width: 0; overflow: auto; white-space: nowrap; scrollbar-width: none; font-size: 18px; }
#amount-text::-webkit-scrollbar { display: none; }
.memo-row { gap: 16px; }
.memo-row > span { flex-shrink: 0; }
#memo { width: 100%; min-width: 0; border: 0; border-radius: 0; padding: 0; margin: 0; outline: none; background: transparent; text-align: right; font-size: 17px; height: 100%; caret-color: var(--orange); }
.save-button {
  display: block; width: min(300px, calc(100% - 40px)); height: 44px; margin: 42px auto 0;
  border-radius: 8px; background: var(--orange); color: white; font-weight: 600; box-shadow: 0 2px 4px #0002;
}
.save-button:active { filter: brightness(.93); }
.save-button:disabled { opacity: .7; }
.tab-bar {
  position: absolute; bottom: 0; width: 100%; display: flex; height: calc(49px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom); background: white; border-top: .333px solid #b1ada2;
}
.tab-bar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: #a0a0a0; background: transparent; }
.tab-bar [aria-current] { color: var(--orange); }
.tab-bar svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.8; stroke-linejoin: round; stroke-linecap: round; }
.tab-bar button:first-child svg, .tab-bar button:last-child svg, .tab-bar .pie { fill: currentColor; stroke-width: 1; }
.tab-bar span { font-size: 11px; line-height: 13px; }
.input-panel {
  position: absolute; bottom: 0; width: 100%; height: calc(var(--panel-body) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom); background: #d1d3d6; border-top: .333px solid #b1ada2;
}
.panel-toolbar { height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: #faf8f4; }
.panel-toolbar button { color: var(--orange); background: transparent; font-size: 17px; }
#calculator-toggle[aria-pressed="false"] { color: #a0a0a0; }
.keypad { display: flex; gap: 6px; height: calc(100% - 44px); padding: 6px; align-items: flex-start; }
.number-keys, .operator-keys { display: grid; gap: 6px; grid-auto-rows: min(47.5px, calc((var(--panel-body) - 74px) / 4)); }
.number-keys { grid-template-columns: repeat(3, minmax(0, 1fr)); flex: 1; }
.operator-keys { width: 18%; flex-shrink: 0; }
.keypad button { min-width: 0; background: white; border-radius: 4px; font-size: 23px; box-shadow: 0 1px 0 #0006; }
.keypad button:active { background: #b8bdc5; }
.keypad .delete-key { background: transparent; box-shadow: none; }
.delete-key svg { width: 25px; height: 21px; stroke: currentColor; fill: none; stroke-width: 2; }
.wheel-panel { background: #f4f4f4; height: calc(100% - 44px); }
.wheel { position: relative; height: calc(100% - 34px); background: var(--row); }
.wheel-selection { position: absolute; height: 34px; top: calc(50% - 17px); left: 9px; right: 9px; background: #f1f0ef; border-radius: 8px; pointer-events: none; }
.wheel-options {
  position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; width: 100%; padding-block: calc((var(--wheel-height) - 34px) / 2);
  scroll-snap-type: y mandatory; scrollbar-width: none; overscroll-behavior: contain; touch-action: pan-y;
  mask-image: linear-gradient(transparent 4%, black 33%, black 67%, transparent 96%);
  -webkit-mask-image: linear-gradient(transparent 4%, black 33%, black 67%, transparent 96%);
}
.wheel { --wheel-height: calc(var(--panel-body) - 78px); overflow: hidden; }
.wheel-slot { height: 34px; scroll-snap-align: center; }
.wheel-options button { display: block; height: 34px; width: 100%; background: transparent; font-size: 24px; color: #303030; backface-visibility: hidden; }
.wheel-options, .wheel-slot { min-width: 0; max-width: 100%; overscroll-behavior-x: none; }
.wheel-slot { width: 100%; position: relative; }
.wheel-options button { position: absolute; left: 0; top: 0; margin: 0; transform-origin: 50% 50%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wheel-options button[aria-selected="true"] { color: #303030; }
.wheel-footer { height: 34px; }
.calendar-panel { height: calc(100% - 44px); padding: 8px 16px 0; background: var(--row); }
.month-toolbar { display: flex; align-items: center; height: 56px; color: black; font-weight: 600; }
#calendar-month { flex: 1; padding-left: 12px; width: auto; justify-content: flex-start; display: flex; gap: 8px; font-weight: 600; white-space: nowrap; }
.month-disclosure { color: var(--orange); font-size: 28px; font-weight: 400; }
#calendar-month[aria-expanded="true"] .month-disclosure { transform: rotate(90deg); }
#confirm-month { width: 54px; color: var(--orange); font-weight: 400; }
.month-wheels { height: calc(100% - 56px); display: flex; }
.month-wheels .wheel { width: 50%; height: 100%; --wheel-height: calc(var(--panel-body) - 108px); }
.month-toolbar button { width: 44px; height: 44px; background: transparent; display: grid; place-items: center; }
.month-toolbar button:disabled { opacity: .25; }
.chevron { display: block; width: 13px; height: 13px; border: solid var(--orange); border-width: 3px 3px 0 0; transform: rotate(45deg); }
.chevron.left { transform: rotate(-135deg); }
.weekday-row { height: 28px; display: grid; grid-template-columns: repeat(7, 1fr); align-items: center; text-align: center; color: #bfbfbf; font-size: 13px; font-weight: 600; }
.calendar-days { height: calc(100% - 84px); display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: repeat(var(--calendar-rows, 5), minmax(0, 1fr)); }
.calendar-days button { align-self: center; justify-self: center; width: min(44px, 100%); height: min(44px, 100%); aspect-ratio: 1; background: transparent; color: black; border-radius: 50%; font-size: 21px; }
.calendar-days button[aria-pressed="true"] { background: var(--orange); color: white; font-weight: 600; }
.app[data-panel="category"] { --panel-body: min(294px, calc((var(--app-height) - var(--safe-top)) * .64)); }
.app[data-panel="date"] { --panel-body: min(382px, calc((var(--app-height) - var(--safe-top)) * .72)); }
.app[data-panel="date"] .input-panel { background: var(--row); }
.app[data-panel="date"] .panel-toolbar { background: #f7f7f7; }
.app[data-panel="category"] .input-panel { background: #f4f4f4; }
.app[data-panel="category"] #category-field, .app[data-panel="date"] #date-field { background: #d1d1d6; }
.app[data-panel="amount"] #amount-text::after, .app[data-panel="calculator"] #amount-text::after { content: ""; display: inline-block; width: 2px; height: 21px; background: var(--orange); vertical-align: -4px; margin-left: 1px; animation: amount-caret 1.06s step-end infinite; }
@keyframes amount-caret { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.app[data-panel="amount"] #amount-text.placeholder::after, .app[data-panel="calculator"] #amount-text.placeholder::after { position: absolute; left: 16px; margin-left: 0; }
.app:not([data-panel="none"]) .input-form { padding-bottom: calc(var(--panel-body) + var(--safe-bottom)); }
.app.memo-active .form-scroll { height: calc(var(--visible-height) - 44px - var(--safe-top)); }
.app.memo-active .input-form { padding-bottom: 20px; }
.toast { position: absolute; bottom: calc(64px + var(--safe-bottom)); left: 16px; right: 16px; text-align: center; background: #303030ed; color: white; border-radius: 6px; padding: 12px; font-size: 14px; z-index: 3; pointer-events: none; }
dialog { max-width: min(320px, calc(100% - 40px)); border: 0; border-radius: 10px; padding: 20px; color: var(--ink); background: var(--row); }
dialog::backdrop { background: #0005; }
dialog p { margin-top: 0; font-size: 16px; white-space: pre-line; }
dialog button { display: block; margin-left: auto; color: var(--orange); background: transparent; min-height: 32px; min-width: 44px; }
@media (max-height: 650px) {
  .app[data-panel="amount"], .app[data-panel="calculator"] { --panel-body: min(294px, calc((var(--app-height) - var(--safe-top)) * .56)); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

.category-management { position: absolute; inset: 0; height: min(100%, var(--visible-height)); z-index: 4; background: var(--paper); display: flex; flex-direction: column; }
.manager-header { flex-shrink: 0; height: calc(44px + var(--safe-top)); padding: var(--safe-top) 12px 0; background: var(--orange); color: white; display: grid; grid-template-columns: 88px minmax(0, 1fr) 88px; align-items: center; }
.manager-header h1 { margin: 0; text-align: center; font-size: 18px; font-weight: 400; white-space: nowrap; }
.manager-header button { background: transparent; color: white; height: 44px; font-size: 17px; text-align: left; }
.manager-header #manager-save { text-align: right; }
.manager-list-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.category-instructions { min-height: 44px; padding: 10px 16px; display: flex; justify-content: space-between; gap: 8px; color: #999; font-size: 13px; border-bottom: .333px solid #bdb9b3; }
.category-list-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.category-management-row { height: 44px; display: flex; align-items: center; background: var(--row); position: relative; padding-left: 16px; }
.category-management-row::after { content: ""; position: absolute; bottom: 0; left: 16px; right: 0; height: .333px; background: #bdb9b3; }
.remove-category { flex-shrink: 0; width: 22px; height: 22px; margin-right: 21px; border-radius: 50%; color: white; background: #ff3b30; font-size: 24px; line-height: 18px; }
.edit-category { height: 44px; flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; text-align: left; background: transparent; }
.category-swatch { width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0; display: inline-block; }
.category-management-name { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-chevron { color: #c4c4c4; font-size: 31px; line-height: 1; padding-right: 8px; }
.reorder-category { height: 44px; width: 51px; flex-shrink: 0; color: #c4c4c4; background: transparent; border-left: .333px solid #c4c4c4; font-size: 25px; touch-action: none; user-select: none; -webkit-user-select: none; }
.category-management-row.dragging { z-index: 1; background: #f1f0ef; box-shadow: 0 2px 6px #0002; }
#add-category { height: calc(44px + var(--safe-bottom)); padding-bottom: var(--safe-bottom); flex-shrink: 0; background: var(--row); color: var(--orange); border-top: .333px solid #bdb9b3; }
#manager-form-view, .manager-color-view { overflow-y: auto; min-height: 0; flex: 1; }
#category-name { width: 100%; border: 0; padding: 0; outline: none; background: transparent; font-size: 17px; caret-color: var(--orange); }
#category-name::placeholder { color: #bfbfbf; }
.color-value { display: flex; align-items: center; gap: 8px; }
.color-value .category-swatch { width: 20px; height: 20px; }
.category-palette { display: grid; grid-template-columns: repeat(4, 40px); justify-content: space-around; row-gap: 30px; padding: 36px 16px 0; }
.category-palette button { width: 40px; height: 40px; border-radius: 8px; color: #ffffff70; font-size: 30px; }
.category-palette button[aria-pressed="true"] { color: white; }
.custom-color { display: flex; align-items: center; gap: 12px; margin: 30px 32px; font-size: 16px; }
.custom-color input { width: 40px; height: 40px; padding: 0; border: 0; background: transparent; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; }
.dialog-actions button { margin: 0; }
#confirm-category-delete { color: #ff3b30; }
.recovery-page { overflow: auto; height: auto; }
.recovery-page main { max-width: 480px; margin: 24px auto; padding: 16px; }
.recovery-page h1 { font-size: 22px; }
.recovery-page p { line-height: 1.6; }
.recovery-page button { padding: 12px; border-radius: 8px; background: var(--orange); color: white; }
