:root {
  --bg-page: #f4f7fb;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;

  --navy-900: #0f2942;
  --navy-800: #163a5f;
  --navy-700: #1e4b7a;
  --navy-100: #e8f0f8;

  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #eff6ff;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border-light: #e2e8f0;
  --border-strong: #cbd5e1;

  --green-700: #047857;
  --green-600: #059669;
  --green-100: #d1fae5;
  --green-50: #ecfdf5;
  --green-border: #a7f3d0;

  --red-700: #b91c1c;
  --red-600: #dc2626;
  --red-100: #fee2e2;
  --red-50: #fef2f2;
  --red-border: #fecaca;

  --amber-700: #b45309;
  --amber-50: #fffbeb;
  --amber-border: #fde68a;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(15, 41, 66, 0.05);
  --shadow-card: 0 4px 18px rgba(15, 41, 66, 0.06), 0 1px 3px rgba(15, 41, 66, 0.04);
  --shadow-float: 0 -6px 24px rgba(15, 41, 66, 0.14);

  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, sans-serif;
  --font-num: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --transition-fast: 150ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-page);
  min-height: 100vh;
  padding-bottom: 84px;
}

.tabular-nums,
.num-input {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

/* Header */
.site-header {
  background: linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 100%);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.header-wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px 18px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.84);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.back-link:hover {
  color: #ffffff;
  text-decoration: underline;
}

.back-link:focus-visible {
  outline: 2px solid #93c5fd;
  outline-offset: 3px;
  border-radius: 4px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #34d399;
  display: grid;
  place-items: center;
}

.site-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.site-subtitle {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.35;
}

.btn-ghost {
  flex-shrink: 0;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.45);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.82rem;
}

/* Main Layout */
.main-container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.calculator-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Card Surface */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px 16px;
}

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

.section-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--navy-900);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-caption {
  margin: 3px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.live-indicator {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--navy-800);
  background: var(--navy-100);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

/* Form Elements */
.calc-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.compact-group {
  gap: 4px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-label {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-label-sm {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.label-optional {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 1px 7px;
  border-radius: var(--radius-pill);
}

.form-input,
.form-select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  background: #ffffff;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  -webkit-appearance: none;
  appearance: none;
}

.form-input:hover,
.form-select:hover {
  border-color: #94a3b8;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.14);
}

.form-input::placeholder {
  color: #94a3b8;
}

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

.input-unit-wrap .form-input {
  padding-right: 36px;
  font-weight: 600;
}

.input-unit {
  position: absolute;
  right: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

/* Remove default number spin buttons for cleaner mobile UX */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

.form-hint {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Quick Select Chips */
.quick-chips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 2px;
}

.chip-btn {
  min-height: 40px;
  padding: 6px 4px;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-btn:hover {
  border-color: var(--navy-700);
  color: var(--navy-900);
  background: var(--navy-100);
}

.chip-btn.is-active {
  background: var(--navy-900);
  border-color: var(--navy-900);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(15, 41, 66, 0.22);
}

/* Select Dropdown */
.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.form-select {
  padding-right: 36px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

.broker-group {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 13px 12px;
}

.broker-params {
  margin-top: 4px;
}

.broker-note {
  margin: 4px 0 0;
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Lending Days & Slider */
.days-group {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 13px 12px;
}

.days-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.days-input-wrap {
  width: 112px;
}

.days-input-wrap .form-input {
  min-height: 42px;
  text-align: right;
  padding-right: 30px;
}

.slider-wrap {
  padding: 6px 2px 2px;
}

.range-slider {
  --slider-pct: 15.25%;
  width: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: linear-gradient(
    to right,
    var(--navy-800) 0%,
    var(--navy-800) var(--slider-pct),
    #cbd5e1 var(--slider-pct),
    #cbd5e1 100%
  );
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  margin: 8px 0 6px;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--navy-900);
  box-shadow: 0 2px 8px rgba(15, 41, 66, 0.25);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.range-slider::-webkit-slider-thumb:active {
  transform: scale(1.12);
  box-shadow: 0 0 0 6px rgba(29, 78, 216, 0.16);
}

.range-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid var(--navy-900);
  box-shadow: 0 2px 8px rgba(15, 41, 66, 0.25);
  transition: transform var(--transition-fast);
}

.range-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px rgba(29, 78, 216, 0.25);
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.term-warning {
  margin: 4px 0 0;
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--amber-700);
  background: var(--amber-50);
  border: 1px solid var(--amber-border);
  border-radius: var(--radius-sm);
}

/* Date Helper Sub-Accordion */
.sub-accordion {
  margin-top: 6px;
  border-top: 1px dashed var(--border-strong);
  padding-top: 8px;
}

.sub-accordion-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 4px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--navy-800);
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
}

.sub-accordion-summary::-webkit-details-marker {
  display: none;
}

.sub-accordion-summary:hover {
  color: var(--accent);
}

.accordion-chevron {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 200ms ease;
  margin-right: 4px;
}

details[open] > summary .accordion-chevron {
  transform: rotate(-135deg);
}

.sub-accordion-body {
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.date-input {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  min-height: 42px;
  padding: 8px 10px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1.45;
}

.checkbox-row input[type="checkbox"] {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  accent-color: var(--navy-900);
  flex-shrink: 0;
}

.date-calc-feedback {
  margin: 0;
  padding: 8px 10px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  line-height: 1.45;
}

.date-calc-feedback.is-success {
  color: var(--green-700);
  background: var(--green-50);
  border-color: var(--green-border);
  font-weight: 600;
}

.date-calc-feedback.is-error {
  color: var(--red-700);
  background: var(--red-50);
  border-color: var(--red-border);
  font-weight: 600;
}

/* Result Card */
.broker-badge {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--navy-900);
  background: var(--bg-muted);
  border: 1px solid var(--border-light);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.profit-hero {
  border-radius: var(--radius-md);
  padding: 18px 16px;
  border: 1.5px solid var(--border-light);
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.profit-hero.is-positive {
  background: var(--green-50);
  border-color: var(--green-border);
}

.profit-hero.is-negative {
  background: var(--red-50);
  border-color: var(--red-border);
}

.profit-hero.is-neutral {
  background: var(--bg-subtle);
  border-color: var(--border-strong);
}

.profit-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.profit-label {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.status-pill {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
}

.profit-hero.is-positive .status-pill {
  background: var(--green-100);
  color: var(--green-700);
}

.profit-hero.is-negative .status-pill {
  background: var(--red-100);
  color: var(--red-700);
}

.profit-hero.is-neutral .status-pill {
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.profit-amount {
  margin: 6px 0 14px;
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.profit-hero.is-positive .profit-amount {
  color: var(--green-600);
}

.profit-hero.is-negative .profit-amount {
  color: var(--red-600);
}

.profit-hero.is-neutral .profit-amount {
  color: var(--text-primary);
}

.unit-sm {
  font-size: 1.1rem;
  font-weight: 700;
  margin-left: 3px;
}

.profit-submetrics {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(15, 41, 66, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.submetric {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.submetric-divider {
  width: 1px;
  align-self: stretch;
  background: var(--border-light);
  margin: 0 12px;
}

.submetric-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

.submetric-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--navy-900);
}

.profit-hero.is-negative .submetric-value {
  color: var(--red-700);
}

/* Break-even Banner */
.breakeven-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
}

.breakeven-box.is-safe {
  background: #f0f6fc;
  border-color: #c7dcf3;
}

.breakeven-box.is-danger {
  background: var(--red-50);
  border-color: var(--red-border);
}

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

.breakeven-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--navy-900);
}

.breakeven-days {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--navy-900);
}

.breakeven-box.is-danger .breakeven-days {
  color: var(--red-600);
}

.breakeven-message {
  margin: 4px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.45;
}

.breakeven-box.is-danger .breakeven-message {
  color: var(--red-700);
}

/* Metrics Grid */
.metrics-grid {
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-tile {
  margin: 0;
  padding: 11px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}

.metric-tile-emphasis {
  background: var(--navy-100);
  border-color: #c7dcf3;
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.metric-note {
  font-weight: 500;
}

.metric-value {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 800;
  color: var(--text-primary);
}

.metric-tile-emphasis .metric-value {
  color: var(--navy-900);
}

/* Action Button */
.result-actions {
  margin-top: 16px;
}

.btn-primary {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--navy-900);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(15, 41, 66, 0.2);
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.btn-primary:hover {
  background: var(--navy-800);
}

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

.btn-danger-ghost {
  appearance: none;
  border: 1px solid var(--red-border);
  background: var(--red-50);
  color: var(--red-700);
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.btn-danger-ghost:hover {
  background: var(--red-100);
}

/* Comparison Table */
.comparison-header {
  margin-bottom: 12px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x pan-y;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
}

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 340px;
}

.comparison-table thead th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.76rem;
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}

.comparison-table thead th.num-col,
.comparison-table tbody td.num-col {
  text-align: right;
  white-space: nowrap;
}

.comparison-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.comparison-table tbody tr:last-child {
  border-bottom: none;
}

.comparison-table tbody tr:hover {
  background: #f8fafc;
}

.comparison-table tbody tr.is-cheapest {
  background: var(--green-50);
}

.comparison-table tbody tr.is-cheapest:hover {
  background: #dff8ec;
}

.comparison-table tbody tr.is-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--navy-900);
}

.comparison-table tbody td {
  padding: 11px 10px;
  vertical-align: middle;
}

.broker-cell-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.broker-name-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.broker-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.badge-cheapest {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--green-700);
  background: var(--green-100);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
}

.badge-selected {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--navy-900);
  background: var(--navy-100);
  padding: 1px 6px;
  border-radius: var(--radius-pill);
}

.badge-limit-over {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--amber-700);
  background: var(--amber-50);
  border: 1px solid var(--amber-border);
  padding: 0 5px;
  border-radius: 4px;
}

.val-positive {
  color: var(--green-600);
  font-weight: 700;
}

.val-negative {
  color: var(--red-600);
  font-weight: 700;
}

.val-neutral {
  color: var(--text-primary);
  font-weight: 700;
}

.table-footnote {
  margin: 10px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Ad Slot Placeholder (collapses cleanly when empty; add height/margin when ad script is inserted) */
.ad-slot {
  width: 100%;
  min-height: 0;
}

.ad-slot:not(:empty) {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

/* History Section */
.count-badge {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
}

.history-empty {
  padding: 20px 14px;
  text-align: center;
  font-size: 0.84rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

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

.history-item {
  display: flex;
  align-items: stretch;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.history-item:hover {
  border-color: var(--navy-700);
  background: #ffffff;
}

.history-restore-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: none;
  padding: 12px 12px;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.history-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--navy-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.history-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.history-stats {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.history-delete-btn {
  flex-shrink: 0;
  width: 44px;
  border: none;
  border-left: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.history-delete-btn:hover {
  background: var(--red-50);
  color: var(--red-600);
}

/* Guide Accordion */
.accordion-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-accordion {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  overflow: hidden;
}

.guide-accordion[open] {
  background: #ffffff;
  border-color: #cbd5e1;
}

.guide-summary {
  list-style: none;
  padding: 13px 14px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--navy-900);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.guide-summary::-webkit-details-marker {
  display: none;
}

.guide-summary:hover {
  color: var(--accent);
}

.guide-body {
  padding: 0 14px 14px;
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.65;
  border-top: 1px solid var(--border-light);
}

.guide-body p {
  margin: 10px 0 8px;
}

.guide-body ul {
  margin: 8px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.formula-box {
  margin: 10px 0;
  padding: 10px 12px;
  background: var(--navy-100);
  border-radius: var(--radius-sm);
  color: var(--navy-900);
  font-weight: 700;
  font-size: 0.82rem;
  line-height: 1.5;
}

/* Footer */
.site-footer {
  max-width: 1080px;
  margin: 4px auto 0;
  padding: 0 16px 24px;
}

.footer-inner {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer-inner p {
  margin: 2px 0;
}

/* Mobile Sticky Summary Bar */
.mobile-sticky-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: rgba(15, 41, 66, 0.96);
  backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow-float);
  transform: translateY(110%);
  opacity: 0;
  pointer-events: none;
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 220ms ease;
}

.mobile-sticky-bar.is-visible {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.sticky-item {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sticky-label {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.2;
}

.sticky-value {
  font-size: 0.96rem;
  font-weight: 800;
  line-height: 1.25;
  white-space: nowrap;
}

.sticky-value.is-positive {
  color: #34d399;
}

.sticky-value.is-negative {
  color: #fca5a5;
}

.sticky-jump-btn {
  flex-shrink: 0;
  min-height: 36px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--navy-900);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

/* Toast Notification */
.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--navy-900);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 24px rgba(15, 41, 66, 0.28);
  white-space: nowrap;
}

/* Focus Accessibility */
button:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Tablet & Desktop Breakpoints */
@media (min-width: 640px) {
  .header-wrap {
    padding: 14px 24px 20px;
  }

  .site-title {
    font-size: 1.35rem;
  }

  .site-subtitle {
    font-size: 0.84rem;
  }

  .main-container {
    padding: 24px 24px 36px;
    gap: 20px;
  }

  .card {
    padding: 22px 24px;
  }

  .profit-amount {
    font-size: 2.5rem;
  }

  .comparison-table {
    font-size: 0.9rem;
  }

  .comparison-table thead th,
  .comparison-table tbody td {
    padding: 12px 14px;
  }
}

@media (min-width: 960px) {
  body {
    padding-bottom: 24px;
  }

  .calculator-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    align-items: start;
    gap: 20px;
  }

  .result-column {
    position: sticky;
    top: 20px;
  }

  .mobile-sticky-bar {
    display: none;
  }

  .toast {
    bottom: 28px;
  }
}

@media (max-width: 380px) {
  .form-grid-2 {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .profit-amount {
    font-size: 1.95rem;
  }
}
