*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --bg2: #f7f7f6;
  --border: #e8e8e6;
  --text: #0f0f0e;
  --text2: #888885;
  --text3: #b8b8b5;
  --red: #c93737;
  --shadow: 0 1px 4px rgba(0,0,0,.06);
}

[data-theme="dark"] {
  --bg: #0f0f0e;
  --bg2: #1a1a19;
  --border: #2a2a28;
  --text: #f0f0ee;
  --text2: #888885;
  --text3: #444442;
  --red: #f87171;
  --shadow: 0 1px 4px rgba(0,0,0,.3);
}

html { font-size: 16px; }

body {
  font-family: 'Geist', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  transition: background .15s, color .15s;
}

.theme-toggle {
  position: fixed;
  top: 20px; right: 20px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s;
  z-index: 10;
}
.theme-toggle:hover { background: var(--bg2); }
.sun, .moon { position: absolute; transition: opacity .15s; line-height: 1; font-size: .9rem; }
[data-theme="light"] .moon { opacity: 0; }
[data-theme="dark"]  .sun  { opacity: 0; }

.app {
  max-width: 420px;
  margin: 0 auto;
  padding: 56px 24px 120px;
}

.total-display {
  font-family: 'Geist Mono', monospace;
  font-size: clamp(2.8rem, 16vw, 5rem);
  font-weight: 200;
  letter-spacing: -.03em;
  color: var(--text);
  line-height: 1;
  margin-top: 16px;
}

.total-label-main {
  font-family: 'Geist Mono', monospace;
  font-size: .72rem;
  color: var(--text3);
  margin-top: 8px;
  letter-spacing: .05em;
}

.controls { margin-top: 28px; }

.btn-main {
  width: 100%;
  padding: 14px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  font-family: 'Geist', sans-serif;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-main:hover { opacity: .85; }

.sub-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.btn-reset {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-family: 'Geist', sans-serif;
  font-size: .76rem;
  color: var(--text2);
  cursor: pointer;
  transition: all .15s;
}
.btn-reset:hover { color: var(--red); border-color: var(--red); }

.records { margin-top: 28px; }

.records-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.records-title {
  font-size: .76rem;
  color: var(--text3);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.records-count {
  font-family: 'Geist Mono', monospace;
  font-size: .72rem;
  color: var(--text3);
}

.empty {
  font-size: .82rem;
  color: var(--text3);
  padding: 24px 0;
  text-align: center;
}

.record-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.record-num {
  font-family: 'Geist Mono', monospace;
  font-size: .65rem;
  color: var(--text3);
  min-width: 18px;
}

.record-info { flex: 1; min-width: 0; }

.record-amount {
  font-family: 'Geist Mono', monospace;
  font-size: .95rem;
  color: var(--text);
  display: block;
}

.record-meta {
  font-size: .68rem;
  color: var(--text3);
  margin-top: 1px;
  display: block;
}

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

.btn-rec {
  background: none;
  border: none;
  width: 36px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: .75rem;
  color: var(--text3);
  border-radius: 4px;
  transition: all .12s;
  font-family: 'Geist', sans-serif;
}
.btn-rec:hover { background: var(--bg2); color: var(--text); }
.btn-rec.del:hover { color: var(--red); }

/* ── Bottom sheet ── */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  z-index: 50;
}
.sheet-overlay.open { opacity: 1; pointer-events: all; }

.input-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 24px 24px env(safe-area-inset-bottom, 24px);
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.32,1,.18,1);
  z-index: 60;
  box-shadow: 0 -4px 24px rgba(0,0,0,.08);
}
.input-sheet.open { transform: none; }

.input-preview {
  font-family: 'Geist Mono', monospace;
  font-size: 2.6rem;
  font-weight: 200;
  color: var(--text);
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: -.02em;
  pointer-events: none;
}

/* inputは見えるが小さく、previewの後ろで動く */
.input-sheet input[type="number"] {
  width: 100%;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Geist Mono', monospace;
  font-size: 1.1rem;
  color: var(--text);
  outline: none;
  text-align: center;
  -moz-appearance: textfield;
  transition: border-color .12s;
}
.input-sheet input[type="number"]:focus { border-color: var(--text3); }
.input-sheet input[type="number"]::-webkit-outer-spin-button,
.input-sheet input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

.input-actions {
  display: flex;
  gap: 10px;
}

.input-actions button {
  flex: 1;
  padding: 14px;
  border-radius: 8px;
  font-family: 'Geist', sans-serif;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .12s;
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  -webkit-tap-highlight-color: transparent;
}
.input-actions button.save {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
  flex: 2;
}
.input-actions button:hover { opacity: .75; }

/* ── Edit modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
  z-index: 100;
  backdrop-filter: blur(3px);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: 100%; max-width: 300px;
  box-shadow: var(--shadow);
  transform: scale(.97);
  transition: transform .15s;
}
.modal-overlay.open .modal { transform: none; }

.modal-label {
  font-size: .68rem;
  color: var(--text3);
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.amount-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 12px;
  transition: border-color .12s;
}
.amount-input-wrap:focus-within { border-color: var(--text3); }

.yen-sign {
  font-family: 'Geist Mono', monospace;
  font-size: 1.1rem;
  color: var(--text2);
  flex-shrink: 0;
}

.amount-input-wrap input[type="number"] {
  flex: 1;
  padding: 12px 0;
  background: none;
  border: none;
  font-family: 'Geist Mono', monospace;
  font-size: 1.4rem;
  font-weight: 300;
  color: var(--text);
  outline: none;
  width: 100%;
  -moz-appearance: textfield;
}
.amount-input-wrap input[type="number"]::-webkit-outer-spin-button,
.amount-input-wrap input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

.modal-actions {
  display: flex; gap: 8px;
  margin-top: 16px; justify-content: flex-end;
}

.modal-actions button {
  padding: 8px 16px;
  border-radius: 6px;
  font-family: 'Geist', sans-serif;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .12s;
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
}
.modal-actions button.save {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.modal-actions button:hover { opacity: .75; }
