:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1a1d24;
  --muted: #6b7280;
  --border: #e2e5ea;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #dbe6fe;
  --accent-bg: #eef2ff;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #991b1b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card-bg: #1e2128;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2d3138;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: #1e3a6b;
    --accent-bg: #1e2540;
    --success-bg: #062f24;
    --success-border: #10513f;
    --success-text: #6ee7b7;
    --error-bg: #3a1414;
    --error-border: #6b1f1f;
    --error-text: #fca5a5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 120px;
}

header {
  margin-bottom: 16px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  margin-bottom: 8px;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  box-shadow: var(--shadow-lg);
  font-size: 1.9rem;
  line-height: 1;
  flex-shrink: 0;
  margin-bottom: 4px;
}

header h1 {
  font-size: 1.5rem;
  margin: 0;
}

.subtitle {
  color: var(--muted);
  margin: 0 auto;
  font-size: 0.92rem;
  max-width: 380px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.05rem;
  margin-top: 0;
  margin-bottom: 0;
}

.accordion-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  margin: 0 0 16px;
  font: inherit;
  color: inherit;
  text-align: inherit;
  cursor: pointer;
}

.card.collapsed .accordion-toggle {
  margin-bottom: 0;
}

.accordion-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.accordion-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 0;
}

.accordion-summary {
  display: none;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card.collapsed .accordion-summary {
  display: inline-block;
}

.chevron {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: rotate(180deg);
  transition: transform 0.2s ease;
}

.card.collapsed .chevron {
  transform: rotate(0deg);
}

.accordion-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.25s ease;
}

.card.collapsed .accordion-body {
  grid-template-rows: 0fr;
}

.accordion-inner {
  overflow: hidden;
  min-height: 0;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
}

.step-badge .icon {
  width: 17px;
  height: 17px;
  stroke: #fff;
}

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: -6px;
  margin-bottom: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 14px;
}

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

input[type="text"],
input[type="number"],
select {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  min-height: 46px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

input:disabled, select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input.invalid {
  border-color: var(--error-border);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--error-border) 35%, transparent);
}

select:not(:disabled), .btn, .toggle-btn {
  cursor: pointer;
}

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

.grid4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.grid2 > *, .grid4 > * {
  min-width: 0;
}

@media (max-width: 640px) {
  .grid2, .grid4 { grid-template-columns: 1fr; }
}

.toggle-group {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 18px;
}

.toggle-btn {
  flex: 1;
  padding: 11px 8px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 0.87rem;
  font-weight: 600;
  min-height: 44px;
  transition: background 0.15s ease, color 0.15s ease;
}

.toggle-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
}

.mode-panel {
  animation: fadeIn 0.18s ease;
}

.mode-panel.hidden { display: none; }

.btn {
  padding: 12px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  min-height: 46px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:active { transform: scale(0.98); }

.btn.is-loading .btn-label::after {
  content: "";
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-inline-start: 8px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-size: 1rem;
}

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

.calc-card { padding-top: 4px; padding-bottom: 4px; box-shadow: none; background: transparent; border: none; }
.calc-card:empty { display: none; }

.calc-bar {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

@media (max-width: 640px) {
  .calc-bar {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    max-width: none;
  }
}

.info-box {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--accent-bg);
  border-radius: 10px;
  font-size: 0.88rem;
  line-height: 1.7;
  animation: fadeIn 0.2s ease;
}

.info-box div { display: flex; justify-content: space-between; gap: 12px; }
.info-box strong { color: var(--muted); font-weight: 500; }

select[aria-busy="true"] { color: var(--muted); }

.result-box {
  padding: 20px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: 14px;
  color: var(--success-text);
  animation: fadeIn 0.25s ease;
}

.result-box .result-icon {
  font-size: 1.6rem;
  margin-bottom: 4px;
}

.result-box .big {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.result-box .sub {
  font-size: 0.92rem;
  opacity: 0.85;
  margin-top: 2px;
}

.error-box {
  margin-top: 16px;
  padding: 13px 16px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 10px;
  color: var(--error-text);
  font-size: 0.9rem;
  animation: fadeIn 0.18s ease;
}

.hidden { display: none !important; }

.breakdown {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--success-border);
  font-size: 0.85rem;
  opacity: 0.9;
}

.breakdown div {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.breakdown .note {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  opacity: 0.75;
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}
