:root {
  color-scheme: dark;
  --ink: #f6f2e9;
  --muted: #b8b4ac;
  --panel: rgba(18, 25, 35, 0.9);
  --panel-soft: rgba(27, 37, 50, 0.72);
  --line: rgba(255, 255, 255, 0.12);
  --amber: #ffbd59;
  --amber-bright: #ffd58a;
  --cyan: #62d6dc;
  --green: #8be0a4;
  --red: #ff938b;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 5%, rgba(98, 214, 220, 0.16), transparent 31rem),
    radial-gradient(circle at 91% 7%, rgba(255, 189, 89, 0.15), transparent 27rem),
    linear-gradient(145deg, #091018 0%, #101a27 52%, #0a111a 100%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, black, transparent 70%);
}

.page-shell {
  position: relative;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 58px 0 36px;
}

.hero { max-width: 920px; margin-bottom: 30px; }

.eyebrow {
  margin: 0 0 12px;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.18em 0.35em;
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.25rem, 5.7vw, 5rem);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.045em;
}

.title-expression {
  display: inline-flex;
  align-items: center;
  gap: 0.14em;
  color: var(--amber-bright);
  white-space: nowrap;
}

.title-expression small {
  margin-right: 0.12em;
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.35em;
  font-weight: 500;
  letter-spacing: 0;
}

.power { text-shadow: 0 0 30px rgba(255, 189, 89, 0.14); }
.power sup { position: relative; top: -0.12em; font-size: 0.46em; }
.title-sign { color: var(--cyan); font-style: italic; }

.lede {
  max-width: 760px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.8vw, 1.18rem);
  line-height: 1.65;
}

.calculator-card, .result-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(25, 34, 46, 0.94), rgba(13, 20, 29, 0.94));
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.calculator-card { padding: clamp(20px, 4vw, 36px); }

.input-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 100px minmax(140px, 1fr) minmax(140px, .8fr);
  gap: 18px;
  align-items: end;
}

.field, .sign-control { display: grid; gap: 9px; }
.field > span, .sign-label { color: var(--muted); font-size: 0.8rem; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase; }

input {
  width: 100%;
  height: 68px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  outline: none;
  color: var(--ink);
  background: rgba(5, 10, 16, 0.58);
  font: 650 1.2rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input::placeholder { color: #73777e; font-weight: 450; }
input:hover { border-color: rgba(98, 214, 220, 0.42); }
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 4px rgba(98, 214, 220, 0.13); background: rgba(7, 13, 21, 0.84); }
input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(255, 147, 139, 0.11); }

#signToggle {
  display: block;
  width: 100px;
  height: 68px;
  border-radius: 14px;
  outline: none;
  cursor: pointer;
}

#signToggle:focus-visible { box-shadow: 0 0 0 4px rgba(98, 214, 220, .25); }

.input-rules { margin: 14px 0 0; color: #8f9298; font-size: .86rem; }

.button-row { display: flex; gap: 12px; margin-top: 24px; }

button {
  min-width: 132px;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 12px;
  font: 750 .95rem/1 Inter, ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease, opacity .16s ease;
}

button:not(:disabled):hover { transform: translateY(-2px); }
button:not(:disabled):active { transform: translateY(0); }
.primary-button { color: #18202a; background: linear-gradient(135deg, var(--amber-bright), var(--amber)); box-shadow: 0 8px 24px rgba(255, 189, 89, .2); }
.primary-button:disabled { color: #797d81; background: #3d4248; box-shadow: none; cursor: not-allowed; opacity: .65; }
.secondary-button { color: var(--ink); background: rgba(255,255,255,.09); border: 1px solid var(--line); }
.secondary-button:hover { background: rgba(255,255,255,.14); }

.status { min-height: 24px; margin: 18px 2px 0; color: var(--cyan); }
.status.error { color: var(--red); }
.results { display: grid; gap: 18px; margin-top: 18px; }

.result-card { overflow: hidden; box-shadow: 0 15px 45px rgba(0,0,0,.23); }
.result-card > header { display: flex; align-items: center; gap: 12px; padding: 19px 24px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.025); }
.step-number { display: grid; place-items: center; flex: 0 0 30px; height: 30px; border-radius: 50%; color: #102029; background: var(--cyan); font-weight: 850; font-size: .82rem; }
.result-card h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.32rem; font-weight: 500; }
.card-body { padding: 22px 24px 25px; color: #ddd9d1; line-height: 1.65; }
.card-body p { margin: 0 0 14px; }
.card-body p:last-child { margin-bottom: 0; }

.notice { padding: 18px 20px; border: 1px solid rgba(255,189,89,.27); border-radius: 14px; color: #f5dfb8; background: rgba(255,189,89,.075); }
.success-notice { border-color: rgba(139,224,164,.28); color: #c7f4d3; background: rgba(139,224,164,.07); }

.equation {
  margin: 14px 0;
  padding: 14px 16px;
  overflow-x: auto;
  border-left: 3px solid var(--cyan);
  border-radius: 0 10px 10px 0;
  background: rgba(4, 9, 15, .42);
}

.integer-label { margin-top: 16px; color: var(--muted); font-size: .77rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.integer {
  margin-top: 7px;
  padding: 13px 15px;
  overflow-wrap: anywhere;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 10px;
  color: var(--amber-bright);
  background: rgba(5, 9, 14, .56);
  font: 600 .94rem/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.factor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.factor-box { min-width: 0; padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-soft); }
.factor-box strong { display: block; margin-bottom: 8px; color: var(--cyan); font-family: Georgia, "Times New Roman", serif; font-size: 1.18rem; }
.factor-box .integer { margin-top: 0; }

.table-wrap { margin-top: 17px; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; font-size: .89rem; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: rgba(255,255,255,.035); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
td.numeric { max-width: 260px; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: #f1d8a8; }

details { margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025); }
summary { padding: 13px 15px; cursor: pointer; color: var(--cyan); font-weight: 700; }
details > div { padding: 0 15px 15px; }

footer { padding: 26px 4px 0; color: #81858b; font-size: .82rem; text-align: center; }
footer code { color: #aeb3b9; }
.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; }

@media (max-width: 760px) {
  .page-shell { width: min(100% - 22px, 1120px); padding-top: 34px; }
  .input-row { grid-template-columns: 1fr 86px 1fr; }
  .exponent-field { grid-column: 1 / -1; }
  #signToggle { width: 86px; }
  .factor-grid { grid-template-columns: 1fr; }
}

@media (max-width: 470px) {
  h1 { font-size: 2.42rem; }
  .title-expression { font-size: .86em; }
  .calculator-card { padding: 18px; border-radius: 17px; }
  .input-row { gap: 10px; }
  input { height: 60px; padding: 0 12px; }
  #signToggle { height: 60px; }
  .button-row { display: grid; grid-template-columns: 1fr 1fr; }
  button { min-width: 0; }
  .result-card > header, .card-body { padding-left: 17px; padding-right: 17px; }
}
