:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #0a0d19;
  --muted: #65708a;
  --border: #d7deea;
  --soft-border: #e5e9f0;
  --blue: #0b4ee8;
  --blue-dark: #073fc2;
  --lime: #d8ff30;
  --danger: #ba2f3b;
  --shadow: 0 16px 40px rgba(22, 32, 55, 0.07);
  --radius: 18px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.calculator-app {
  min-height: 100dvh;
}

.auth-state {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.auth-card {
  width: min(100%, 480px);
  padding: clamp(32px, 7vw, 52px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 0 auto 24px;
  border-radius: 16px;
  color: var(--lime);
  background: var(--blue);
  font-size: 24px;
  font-weight: 820;
  letter-spacing: -0.05em;
}

.auth-spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 22px;
  border: 3px solid #dce3ef;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: auth-spin 720ms linear infinite;
}

.auth-card h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 38px);
  font-weight: 760;
  letter-spacing: -0.045em;
  line-height: 1.08;
}

.auth-card p {
  margin: 16px auto 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.auth-action {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 24px;
  padding: 0 22px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--blue);
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
}

.auth-action:hover {
  background: var(--blue-dark);
}

.auth-action:focus-visible {
  outline: 3px solid rgba(11, 78, 232, 0.28);
  outline-offset: 3px;
}

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

button,
input {
  font: inherit;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

.site-header {
  height: 74px;
  display: flex;
  align-items: center;
  padding-inline: clamp(24px, 4.2vw, 64px);
  border-bottom: 1px solid var(--border);
  background: rgba(244, 246, 248, 0.94);
}

.wordmark {
  color: var(--ink);
  font-size: 28px;
  font-weight: 850;
  letter-spacing: -0.07em;
  line-height: 1;
  text-decoration: none;
}

.page-shell {
  width: min(1320px, calc(100% - 48px));
  margin: 0 auto;
  padding: 60px 0 46px;
}

.is-embedded .site-header {
  display: none;
}

.is-embedded .page-shell {
  padding-top: clamp(24px, 4.5vw, 48px);
}

.calculator {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.03fr);
  align-items: stretch;
  gap: 22px;
}

.calculator-form,
.results-panel {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.calculator-form {
  display: flex;
  flex-direction: column;
  padding: 42px 38px 34px;
}

.field-group {
  position: relative;
  margin-bottom: 21px;
}

.field-group label {
  display: block;
  margin-bottom: 10px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.015em;
}

.input-shell {
  min-height: 68px;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid #cbd4e3;
  border-radius: 12px;
  background: #fff;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.input-shell:focus-within {
  border-color: var(--blue);
  background: #fbfdff;
  box-shadow: 0 0 0 3px rgba(11, 78, 232, 0.12);
}

.input-shell.has-error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(186, 47, 59, 0.09);
}

.input-prefix {
  width: 56px;
  flex: 0 0 56px;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--soft-border);
  color: var(--muted);
  background: #f7f9fc;
  font-size: 23px;
  font-weight: 700;
}

.input-shell input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  padding: 0 22px;
  color: var(--ink);
  background: transparent;
  font-size: 27px;
  font-weight: 680;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

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

.input-shell input[type="number"]::-webkit-inner-spin-button,
.input-shell input[type="number"]::-webkit-outer-spin-button {
  margin-right: 8px;
  opacity: 0.45;
}

.field-error {
  min-height: 16px;
  display: block;
  margin-top: 5px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.25;
}

.calculate-button {
  width: 100%;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 1px;
  border: 0;
  border-radius: 12px;
  color: white;
  background: var(--blue);
  box-shadow: 0 9px 22px rgba(11, 78, 232, 0.2);
  cursor: pointer;
  font-size: 20px;
  font-weight: 720;
  letter-spacing: -0.02em;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.calculate-button svg,
.reset-button svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.calculate-button:hover {
  background: var(--blue-dark);
  box-shadow: 0 12px 26px rgba(11, 78, 232, 0.26);
  transform: translateY(-1px);
}

.calculate-button:active {
  transform: translateY(1px);
}

.calculate-button:focus-visible,
.reset-button:focus-visible,
.wordmark:focus-visible {
  outline: 3px solid rgba(11, 78, 232, 0.28);
  outline-offset: 3px;
}

.reset-button {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 26px;
  padding: 7px 2px;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  font-weight: 650;
}

.reset-button span {
  border-bottom: 1px solid currentColor;
}

.reset-button:hover {
  color: var(--blue);
}

.results-panel {
  display: flex;
  flex-direction: column;
}

.total-block {
  min-height: 244px;
  padding: 45px 54px 38px;
  color: white;
  background: var(--blue);
}

.total-block p {
  margin: 0 0 20px;
  font-size: 26px;
  font-weight: 710;
  letter-spacing: -0.035em;
}

.total-block output {
  display: block;
  color: var(--lime);
  font-size: clamp(68px, 7vw, 104px);
  font-weight: 820;
  letter-spacing: -0.07em;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.total-block output.is-updating {
  animation: total-pop 360ms ease-out;
}

.breakdown {
  position: relative;
  flex: 1;
  padding: 25px 36px 28px 108px;
}

.breakdown::before {
  content: "";
  position: absolute;
  top: 63px;
  bottom: 66px;
  left: 73px;
  width: 1px;
  background: #a9b5cb;
}

.ledger-line {
  position: relative;
  min-height: 102px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--soft-border);
}

.ledger-line--last {
  border-bottom: 0;
}

.operation {
  position: absolute;
  left: -72px;
  z-index: 1;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 7px solid var(--surface);
  border-radius: 50%;
  color: var(--ink);
  background: #edf1f8;
  font-size: 22px;
  font-weight: 720;
}

.operation::before {
  content: "";
  position: absolute;
  right: 100%;
  width: 26px;
  height: 1px;
  background: #a9b5cb;
}

.ledger-copy {
  min-width: 0;
}

.ledger-copy > span {
  display: block;
  font-size: 19px;
  font-weight: 680;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.ledger-copy small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.ledger-line output {
  color: var(--ink);
  font-size: 28px;
  font-weight: 760;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

@keyframes total-pop {
  0% { opacity: 0.55; transform: translateY(8px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 900px) {
  .page-shell {
    width: min(680px, calc(100% - 32px));
    padding-top: 42px;
  }

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

  .calculator-form {
    padding: 34px 30px 28px;
  }
}

@media (max-width: 560px) {
  .site-header {
    height: 64px;
    padding-inline: 20px;
  }

  .wordmark {
    font-size: 24px;
  }

  .page-shell {
    width: min(100% - 24px, 500px);
    padding: 34px 0 28px;
  }

  .calculator-form {
    padding: 28px 20px 22px;
  }

  .field-group {
    margin-bottom: 15px;
  }

  .field-group label {
    font-size: 15px;
  }

  .input-shell,
  .calculate-button {
    min-height: 62px;
  }

  .input-shell input {
    padding-inline: 18px;
    font-size: 24px;
  }

  .input-prefix {
    width: 50px;
    flex-basis: 50px;
    font-size: 20px;
  }

  .calculate-button {
    font-size: 18px;
  }

  .total-block {
    min-height: 208px;
    padding: 35px 26px 32px;
  }

  .total-block p {
    margin-bottom: 18px;
    font-size: 21px;
  }

  .total-block output {
    font-size: clamp(62px, 20vw, 86px);
  }

  .breakdown {
    padding: 18px 20px 18px 76px;
  }

  .breakdown::before {
    top: 52px;
    bottom: 52px;
    left: 48px;
  }

  .ledger-line {
    min-height: 100px;
    grid-template-columns: 1fr;
    align-content: center;
    gap: 6px;
  }

  .operation {
    left: -53px;
    width: 42px;
    height: 42px;
    border-width: 6px;
    font-size: 18px;
  }

  .operation::before {
    width: 15px;
  }

  .ledger-copy > span {
    font-size: 16px;
  }

  .ledger-copy small {
    max-width: 225px;
    margin-top: 3px;
    font-size: 11px;
  }

  .ledger-line output {
    font-size: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
