:root {
  --background: #000000;
  --surface: #0a1a17;
  --surface-2: #0f2521;
  --foreground: #e6fffa;
  --primary: #2dd4bf;
  --primary-hover: #5eead4;
  --secondary: #8ba8a3;
  --accent: #6ee7b7;
  --border: #173832;
  --danger: #f87171;
  --positive: #34d399;
  --negative: #fb7185;

  --gradient-hero: linear-gradient(135deg, #a7f3d0 0%, #34d399 25%, #14b8a6 55%, #0891b2 100%);
  --gradient-cta: linear-gradient(135deg, #10b981 0%, #0d9488 50%, #0e7490 100%);
  --gradient-deep: linear-gradient(135deg, #022c22 0%, #0f3d35 35%, #134e4a 70%, #083344 100%);

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 4px 24px rgba(20, 184, 166, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(ellipse at top, rgba(45, 212, 191, 0.08), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(8, 145, 178, 0.06), transparent 60%),
    var(--background);
  background-attachment: fixed;
}

.hero {
  padding: 28px 20px 18px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.hero__title {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero__sub {
  margin: 0;
  color: var(--secondary);
  font-size: 13px;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
}

.card__title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.field {
  display: block;
  margin-bottom: 12px;
}
.field:last-child { margin-bottom: 0; }

.field__label {
  display: block;
  font-size: 13px;
  color: var(--secondary);
  margin-bottom: 6px;
}

.field__hint {
  color: var(--accent);
  font-size: 11px;
  margin-left: 4px;
  letter-spacing: 0;
}

.field__tax-line {
  margin-top: 5px;
  padding-right: 4px;
  font-size: 11px;
  color: var(--accent);
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.field__tax-line span:first-of-type {
  font-weight: 700;
  margin-left: 2px;
}

.field__tax-hint {
  color: var(--secondary);
  margin-left: 4px;
  font-weight: 400;
  font-size: 10px;
}

.field__input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.field input {
  flex: 1;
  width: 100%;
  min-height: 48px;
  padding: 12px 44px 12px 14px;
  background: var(--surface-2);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 17px;
  font-weight: 500;
  text-align: right;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input::placeholder {
  color: #4a6661;
  font-weight: 400;
}

.field input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.18);
}

.field__suffix {
  position: absolute;
  right: 14px;
  color: var(--secondary);
  font-size: 13px;
  pointer-events: none;
}

.seg {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  gap: 4px;
}
.seg input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.seg label {
  flex: 1;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--secondary);
  cursor: pointer;
  text-align: center;
  letter-spacing: 0.02em;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.seg label:hover {
  color: var(--foreground);
}
.seg input:checked + label {
  background: var(--gradient-cta);
  color: #001613;
}
.seg input:focus-visible + label {
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.25);
}

.field__hint--auto {
  color: var(--accent);
}
.field__hint--manual {
  color: var(--secondary);
}

.subtotal {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.subtotal--inner {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 0;
}

.subtotal__label {
  color: var(--secondary);
  font-size: 13px;
}

.subtotal__value {
  font-size: 20px;
  font-weight: 700;
  color: var(--foreground);
  font-variant-numeric: tabular-nums;
}

.subtotal__value--small {
  font-size: 15px;
  color: var(--accent);
  font-weight: 600;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
}

.toggle__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle__box {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}

.toggle__box::after {
  content: "";
  position: absolute;
  inset: 3px 6px;
  border-right: 2px solid #001613;
  border-bottom: 2px solid #001613;
  transform: rotate(45deg) scale(0);
  transition: transform 0.12s ease-out;
  transform-origin: center;
}

.toggle__input:checked ~ .toggle__box {
  background: var(--primary);
  border-color: var(--primary);
}

.toggle__input:checked ~ .toggle__box::after {
  transform: rotate(45deg) scale(1);
}

.toggle__input:focus-visible ~ .toggle__box {
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.25);
}

.toggle__text {
  font-size: 14px;
  font-weight: 600;
  color: var(--foreground);
}

.toggle__hint {
  color: var(--secondary);
  font-weight: 400;
  font-size: 12px;
  margin-left: 4px;
}

.parts {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  animation: parts-slide 0.18s ease-out;
}

.parts[hidden] {
  display: none;
}

.parts__hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--accent);
}

@keyframes parts-slide {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result {
  background:
    linear-gradient(135deg, rgba(167, 243, 208, 0.06), rgba(8, 145, 178, 0.06)),
    var(--surface);
  border-color: rgba(45, 212, 191, 0.35);
}

.result__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.result__row:last-child { border-bottom: 0; }

.result__label {
  color: var(--secondary);
  font-size: 14px;
}

.result__value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--gradient-hero);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.result__value--negative {
  background: none;
  color: var(--negative);
  -webkit-text-fill-color: var(--negative);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.btn {
  flex: 1;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform 0.05s, filter 0.15s, background 0.15s;
  user-select: none;
}

.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--gradient-cta);
  color: #001613;
}
.btn--primary:hover { filter: brightness(1.08); }

.btn--ghost {
  background: transparent;
  color: var(--foreground);
  border-color: var(--border);
}
.btn--ghost:hover { background: var(--surface-2); }

.btn--small {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
  background: var(--surface-2);
  color: var(--foreground);
  border-color: var(--border);
}
.btn--small:hover { background: var(--muted, #0a1a17); border-color: var(--primary); }

.btn--danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.4);
}
.btn--danger:hover { background: rgba(248, 113, 113, 0.08); }

.history__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.history__head .card__title { margin: 0; }

.history__actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history__item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history__item-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.history__item-memo {
  font-weight: 700;
  color: var(--foreground);
  font-size: 14px;
  word-break: break-word;
}

.history__item-date {
  color: var(--secondary);
  font-size: 11px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.history__item-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 13px;
  color: var(--secondary);
  font-variant-numeric: tabular-nums;
}

.history__item-grid b {
  color: var(--foreground);
  font-weight: 600;
}

.history__item-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.history__item-actions .btn {
  min-height: 32px;
  font-size: 12px;
  padding: 0 10px;
}

.history__empty {
  color: var(--secondary);
  font-size: 13px;
  text-align: center;
  padding: 12px 0 4px;
  margin: 0;
}

.footer {
  text-align: center;
  padding: 20px 16px 32px;
  color: var(--secondary);
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--surface-2);
  border: 1px solid var(--primary);
  color: var(--foreground);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 720px) {
  .hero { padding: 36px 24px 22px; }
  .hero__title { font-size: 32px; }
  .container { padding: 24px 24px 96px; gap: 16px; }
  .card { padding: 20px; }
  .result__value { font-size: 30px; }
}
