:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: #202535;
  background: #f1f3f8;
  font-synthesis: none;
  --ink: #202535;
  --muted: #6f7585;
  --line: #dfe2ea;
  --surface: #ffffff;
  --dark: #171b26;
  --accent: #ed5a3a;
  --accent-soft: #fff1ed;
  --success: #167b5c;
  --danger: #bb3a2e;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top right, rgba(237, 90, 58, 0.11), transparent 24rem),
    #f1f3f8;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  width: min(100% - 32px, 720px);
  margin: 0 auto;
  padding: 34px 0 56px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 20px;
}

.page-header > div:last-child {
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 52px;
  height: 52px;
  place-items: center;
  border-radius: 16px;
  color: white;
  background: var(--dark);
  box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.08);
  font-size: 24px;
  font-weight: 800;
}

.eyebrow,
.step {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  color: var(--dark);
  font-size: clamp(1.75rem, 5vw, 2.4rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
  overflow-wrap: anywhere;
}

.calculator-card,
.history-card {
  border: 1px solid rgba(32, 37, 53, 0.08);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 16px 44px rgba(32, 37, 53, 0.07);
}

.calculator-card {
  padding: 24px;
}

.history-card {
  margin-top: 14px;
  padding: 24px;
}

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

.section-heading h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.field-wide {
  margin-bottom: 14px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 0 16px;
  padding: 4px;
  border: 0;
  border-radius: 12px;
  background: #eef0f4;
}

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

.mode-switch label {
  cursor: pointer;
}

.mode-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode-switch span {
  display: grid;
  min-height: 38px;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  transition: color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.mode-switch input:checked + span {
  color: var(--ink);
  background: white;
  box-shadow: 0 2px 8px rgba(32, 37, 53, 0.09);
}

.mode-switch input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.manual-field {
  margin-bottom: 14px;
}

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

.field label {
  display: block;
  margin-bottom: 8px;
  color: #3b4050;
  font-size: 0.88rem;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 13px;
  outline: none;
  color: var(--ink);
  background: #fbfbfd;
  padding: 0 15px;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

input::placeholder {
  color: #a4a8b4;
}

input:focus {
  border-color: #7c8190;
  background: white;
  box-shadow: 0 0 0 4px rgba(32, 37, 53, 0.07);
}

input[aria-invalid="true"] {
  border-color: var(--danger);
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 50px;
}

.input-with-unit span {
  position: absolute;
  top: 50%;
  right: 15px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  transform: translateY(-50%);
  pointer-events: none;
}

.field-hint,
.field-error {
  min-height: 15px;
  margin: 6px 2px 0;
  font-size: 0.74rem;
}

.field-hint {
  color: #8a8f9d;
}

.field-error {
  color: var(--danger);
}

.field-error:empty {
  display: none;
}

.result-panel {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 24px;
  align-items: center;
  min-height: 110px;
  margin: 18px 0 14px;
  padding: 18px;
  border-radius: 17px;
  color: white;
  background: var(--dark);
  overflow: hidden;
  position: relative;
}

.result-panel::after {
  position: absolute;
  right: -42px;
  bottom: -70px;
  width: 160px;
  height: 160px;
  border: 28px solid rgba(255, 255, 255, 0.035);
  border-radius: 50%;
  content: "";
}

.result-label {
  margin-bottom: 5px;
  color: #aeb4c2;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

#negative-result {
  display: block;
  color: #c9ced8;
  font-size: clamp(2rem, 8vw, 2.75rem);
  font-weight: 850;
  line-height: 1;
  letter-spacing: -0.05em;
}

.result-panel.has-result #negative-result {
  color: #75ddba;
}

.result-panel.has-result.is-positive #negative-result {
  color: #ff9c87;
}

.result-details {
  display: grid;
  gap: 12px;
  z-index: 1;
}

.result-details div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.result-details div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.result-details span {
  color: #aeb4c2;
  font-size: 0.75rem;
}

.result-details strong {
  font-size: 0.84rem;
  white-space: nowrap;
}

.primary-button {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  color: white;
  background: var(--accent);
  font-weight: 800;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease;
}

.primary-button:hover:not(:disabled) {
  background: #dd4c2d;
  transform: translateY(-1px);
}

.primary-button:active:not(:disabled) {
  transform: translateY(0);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.text-button,
.remove-button {
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.78rem;
  font-weight: 700;
}

.text-button:hover,
.remove-button:hover {
  color: var(--danger);
}

.empty-state {
  padding: 20px 12px 10px;
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 auto 12px;
  place-items: center;
  border-radius: 50%;
  color: #8b91a0;
  background: #f2f3f7;
  font-size: 1.25rem;
}

.empty-state p {
  margin-bottom: 4px;
  font-size: 0.9rem;
  font-weight: 700;
}

.empty-state span {
  color: var(--muted);
  font-size: 0.8rem;
}

.history-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  position: relative;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fbfbfd;
}

.history-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.history-main h3 {
  max-width: 410px;
  margin-bottom: 3px;
  font-size: 0.96rem;
  overflow-wrap: anywhere;
}

.history-main time {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.history-negative {
  flex: 0 0 auto;
  color: var(--success);
  font-size: 1.18rem;
}

.history-negative.is-positive {
  color: var(--danger);
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 13px;
  padding-right: 58px;
}

.history-meta span {
  padding: 5px 8px;
  border-radius: 7px;
  color: var(--muted);
  background: #eef0f4;
  font-size: 0.72rem;
}

.history-meta b {
  color: #4c5261;
}

.remove-button {
  position: absolute;
  right: 12px;
  bottom: 20px;
  padding: 4px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  padding: 12px 16px;
  border-radius: 11px;
  color: white;
  background: var(--success);
  box-shadow: 0 12px 32px rgba(17, 24, 39, 0.2);
  font-size: 0.84rem;
  font-weight: 750;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-error {
  background: var(--danger);
}

@media (max-width: 600px) {
  .page-shell {
    width: min(100% - 16px, 720px);
    padding: 14px 0 28px;
  }

  .page-header {
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
  }

  .brand-mark {
    flex-basis: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 17px;
  }

  h1 {
    margin-bottom: 0;
    font-size: clamp(1.35rem, 6vw, 1.65rem);
  }

  .calculator-card,
  .history-card {
    border-radius: 16px;
    padding: 16px;
  }

  .section-heading {
    margin-bottom: 14px;
  }

  .section-heading h2 {
    font-size: 1.08rem;
  }

  .form-grid,
  .result-panel {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .form-grid {
    gap: 12px;
  }

  .field-wide {
    margin-bottom: 12px;
  }

  .mode-switch {
    margin-bottom: 12px;
  }

  .field label {
    margin-bottom: 6px;
    font-size: 0.82rem;
  }

  input {
    min-height: 44px;
    border-radius: 11px;
    padding: 0 13px;
  }

  .field-hint,
  .field-error {
    margin-top: 4px;
  }

  .result-panel {
    gap: 12px;
    min-height: 0;
    margin: 14px 0 12px;
    padding: 16px;
  }

  .result-details {
    gap: 8px;
    padding-top: 0;
    border-top: 0;
  }

  .result-details div {
    padding-bottom: 7px;
  }

  #negative-result {
    font-size: 2rem;
  }

  .primary-button {
    min-height: 46px;
  }

  .history-heading {
    margin-bottom: 10px;
  }

  .empty-state {
    padding: 10px 8px 4px;
  }

  .empty-icon {
    width: 36px;
    height: 36px;
    margin-bottom: 8px;
  }
}

@media (max-width: 390px) {
  .eyebrow {
    font-size: 0.64rem;
  }

  .history-main {
    display: block;
  }

  .history-negative {
    display: block;
    margin-top: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
