:root {
  --bg-start: #efedf1;
  --bg-end: #e8e7ec;
  --card: #f5f3f7;
  --card-bg: rgba(245, 243, 247, 0.96);
  --card-border: rgba(29, 36, 48, 0.06);
  --panel: #ffffff;
  --panel-soft: rgba(255, 255, 255, 0.8);
  --panel-muted: rgba(255, 255, 255, 0.7);
  --panel-row: rgba(255, 255, 255, 0.5);
  --input: rgba(255, 255, 255, 0.9);
  --line: rgba(90, 103, 128, 0.18);
  --text: #1d2430;
  --muted: #677487;
  --accent: #2f5df5;
  --accent-strong: #1d3ed8;
  --accent-soft: #edf2ff;
  --success: #5ddbb0;
  --switch-bg: #d8dce8;
  --switch-bg-active: #c7d5ff;
  --error-bg: #fff1f1;
  --error-text: #b21d1d;
  --error-border: #ffd7d7;
  --shadow: 0 24px 50px rgba(22, 32, 49, 0.1);
}

:root[data-theme="dark"] {
  --bg-start: #12161f;
  --bg-end: #0e121a;
  --card: #1b2230;
  --card-bg: rgba(27, 34, 48, 0.95);
  --card-border: rgba(148, 163, 184, 0.2);
  --panel: #212a3a;
  --panel-soft: rgba(33, 42, 58, 0.85);
  --panel-muted: rgba(33, 42, 58, 0.9);
  --panel-row: rgba(33, 42, 58, 0.82);
  --input: rgba(18, 24, 34, 0.92);
  --line: rgba(148, 163, 184, 0.24);
  --text: #e7edf7;
  --muted: #b3c0d4;
  --accent: #5f88ff;
  --accent-strong: #4a73f1;
  --accent-soft: #1e2a48;
  --success: #7de7bb;
  --switch-bg: #2f3a4e;
  --switch-bg-active: #3d5ebf;
  --error-bg: #4b1e25;
  --error-text: #ffd9df;
  --error-border: #7c303b;
  --shadow: 0 24px 50px rgba(4, 8, 15, 0.5);
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: linear-gradient(180deg, var(--bg-start) 0%, var(--bg-end) 100%);
  color: var(--text);
  transition: background 0.2s ease, color 0.2s ease;
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(560px, calc(100% - 26px));
  padding: 18px 0 34px;
}

.app-card {
  padding: 18px 18px 20px;
  border-radius: 28px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.header-actions {
  display: inline-flex;
  flex-direction: column;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6vw, 4rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.status-badge {
  width: 74px;
  height: 42px;
  border: 0;
  border-radius: 24px;
  background: linear-gradient(180deg, #2d2d34 0%, #4a4f58 100%);
  box-shadow: inset 0 3px 8px rgba(255, 255, 255, 0.1), inset 0 -3px 10px rgba(0, 0, 0, 0.18);
  position: relative;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  color: #dce3ef;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-badge span {
  position: absolute;
  top: 50%;
  left: 18px;
  width: 18px;
  height: 18px;
  background: linear-gradient(180deg, #7ef0bc 0%, #5fdb9f 100%);
  border-radius: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 0 5px rgba(92, 220, 167, 0.18);
  transition: transform 0.2s ease, background 0.2s ease;
}

.status-badge small {
  pointer-events: none;
}

.settings-badge {
  width: 92px;
}

.settings-badge span {
  width: 12px;
  height: 12px;
  left: 12px;
}

.settings-badge small {
  font-size: 0.62rem;
}

:root[data-theme="dark"] .status-badge span {
  transform: translate(32px, -50%);
  background: linear-gradient(180deg, #78a1ff 0%, #5f88ff 100%);
  box-shadow: 0 0 0 5px rgba(95, 136, 255, 0.2);
}

.calculator-form {
  display: grid;
  gap: 18px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 1rem 0.95rem;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: var(--input);
  color: var(--text);
  font-size: 1.05rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
input[type="range"]:focus-visible {
  outline: none;
  border-color: rgba(47, 93, 245, 0.5);
  box-shadow: 0 0 0 4px rgba(47, 93, 245, 0.08);
}

.type-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.type-pill {
  position: relative;
  display: block;
}

.type-pill input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.type-pill span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  border-radius: 14px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
  transition: all 0.2s ease;
}

.type-pill input:checked + span {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 10px 20px rgba(47, 93, 245, 0.18);
}

.range-group {
  display: grid;
  gap: 8px;
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #dfe5ff 0%, #dfe5ff var(--range-value, 50%), #e8e9ee var(--range-value, 50%), #e8e9ee 100%);
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 999px;
  background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 4px solid var(--accent);
  margin-top: -6px;
  box-shadow: 0 5px 12px rgba(47, 93, 245, 0.22);
}

input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 4px solid var(--accent);
  box-shadow: 0 5px 12px rgba(47, 93, 245, 0.22);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.quick-steps {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.quick-btn {
  border: 0;
  border-radius: 12px;
  min-height: 48px;
  background: linear-gradient(180deg, #2f5df5 0%, #2349d2 100%);
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(47, 93, 245, 0.18);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 2px;
  font-size: 1.1rem;
  font-weight: 600;
}

.switch {
  position: relative;
  display: inline-block;
  width: 64px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--switch-bg);
  transition: all 0.2s ease;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  left: 4px;
  top: 4px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 4px 8px rgba(20, 29, 42, 0.12);
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
  background: var(--switch-bg-active);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(30px);
  background: var(--accent);
}

.summary {
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: var(--panel-muted);
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 16px;
  background: var(--panel-row);
}

.summary-row + .summary-row {
  border-top: 1px solid var(--line);
}

.summary-row span {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--muted);
}

.summary-row strong {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  line-height: 1;
  letter-spacing: -0.05em;
}

.summary-row.highlight {
  background: linear-gradient(135deg, #2f5df5 0%, #2349d2 100%);
}

.summary-row.highlight span,
.summary-row.highlight strong {
  color: #ffffff;
}

.message {
  margin: 0;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  font-size: 0.96rem;
}

.error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

.form-actions {
  display: flex;
  gap: 12px;
}

.primary-btn,
.secondary-btn {
  border-radius: 14px;
  min-height: 50px;
  padding: 0.75rem 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.primary-btn {
  flex: 1;
  border: 0;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #ffffff;
  box-shadow: 0 10px 18px rgba(47, 93, 245, 0.18);
}

.secondary-btn {
  min-width: 110px;
  background: var(--panel-muted);
  border: 1px solid var(--line);
  color: var(--text);
}

.primary-btn:hover,
.secondary-btn:hover,
.quick-btn:hover {
  transform: translateY(-1px);
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
}

.settings-modal[hidden] {
  display: none;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 20, 0.5);
}

.settings-panel {
  position: relative;
  width: min(420px, calc(100% - 20px));
  border-radius: 18px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  padding: 16px;
}

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

.settings-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.close-settings {
  border: 1px solid var(--line);
  background: var(--panel-muted);
  color: var(--text);
  border-radius: 10px;
  min-height: 36px;
  min-width: 36px;
  cursor: pointer;
}

.settings-note {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  color: var(--muted);
  font-weight: 600;
}

.settings-option {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.history-panel {
  width: min(560px, calc(100% - 20px));
}

.history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 340px;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.history-item,
.history-empty {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.history-equation {
  margin: 0;
  color: var(--text);
  font-weight: 700;
}

.history-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.history-empty {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 560px) {
  .page-shell {
    width: min(100%, calc(100% - 18px));
    padding-top: 12px;
    padding-bottom: 18px;
  }

  .app-card {
    padding: 16px 14px 18px;
    border-radius: 24px;
  }

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

  .quick-steps {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .form-actions {
    flex-direction: column;
  }

  .app-header {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    flex-direction: row;
    justify-content: flex-end;
  }
}
