/*
 * Tothren Calculator styles.
 * Colors follow the Tothren palette (see the master brief): the company
 * accent #85232D for key highlights and controls, #6B1C24 for hover/pressed.
 */

@font-face {
  font-family: 'Geist';
  src: url('../assets/fonts/geist-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --accent: #85232d;
  --accent-strong: #6b1c24;
  --accent-tint: #f5edee;
  --accent-tint-strong: #ede0e1;
  --white: #ffffff;
  --paper: #f6f6f4;
  --ink: #191a1c;
  --muted: #6b6b6b;
  --hairline: #e2e2de;
  --key-fn: #efefec;
  --key-fn-hover: #e6e6e2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgb(25 26 28 / 0.04), 0 8px 24px rgb(25 26 28 / 0.06);
  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------ top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 820px;
  margin: 0 auto;
  padding: 20px 20px 0;
  padding-top: max(20px, env(safe-area-inset-top));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
}

.brand img {
  border-radius: 6px;
}

.brand-name {
  font-weight: 650;
  letter-spacing: 0.14em;
}

.brand-sep {
  color: var(--hairline);
}

.brand-app {
  color: var(--muted);
}

.saved-link {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
}

.saved-link:hover {
  background: var(--accent-tint);
}

.count {
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--white);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 400px) minmax(0, 360px);
  justify-content: center;
  align-items: start;
  gap: 28px;
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

@media (max-width: 859px) {
  .layout {
    grid-template-columns: minmax(0, 440px);
    gap: 24px;
    padding-top: 16px;
  }

  .saved-link {
    display: inline-flex;
  }
}

/* ------------------------------------------------------------ calculator */

.calculator {
  background: var(--white);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.display {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 168px;
  padding: 52px 16px 14px;
  border-radius: var(--radius);
  background: var(--paper);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.work {
  margin: 0;
  color: var(--ink);
  font-size: 30px;
  font-weight: 450;
  line-height: 1.25;
  overflow-wrap: anywhere;
  max-height: 7.5em;
  overflow-y: auto;
  transition: color 120ms ease;
}

.ghost {
  color: #b5b5b0;
}

.answer {
  margin: 6px 0 0;
  min-height: 1.5em;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  transition: color 120ms ease;
}

/* After "=": the answer becomes the big line, the equation the small one. */
.display.is-result .work {
  color: var(--muted);
  font-size: 18px;
}

.display.is-result .answer {
  color: var(--ink);
  font-size: 40px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.display.is-result .answer[data-size='m'] {
  font-size: 30px;
}

.display.is-result .answer[data-size='s'] {
  font-size: 22px;
}

.display.is-error .answer {
  color: var(--accent);
  font-size: 16px;
  font-weight: 550;
}

/* ------------------------------------------------------------ toggles (Learn, Save) */

/* Learn sits top-left and Save top-right of the display. Both use the same
   look: OFF is an accent outline on white, ON is a solid accent pill with a
   filled icon, so the two states are easy to tell apart. */
.toggle {
  position: absolute;
  top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px 6px 10px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: var(--white);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.learn-toggle {
  left: 10px;
}

.save-toggle {
  right: 10px;
}

.toggle .icon path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.toggle:hover:not(:disabled) {
  background: var(--accent-tint);
}

.toggle[aria-pressed='true'] {
  background: var(--accent);
  color: var(--white);
}

.toggle[aria-pressed='true'] .icon path:not(.icon-line) {
  fill: currentColor;
}

.toggle[aria-pressed='true']:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.toggle:disabled {
  border-color: var(--hairline);
  color: #a3a3a0;
  cursor: default;
}

/* ------------------------------------------------------------ keypad */

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.key {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink);
  font-size: 22px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom on phones */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 80ms ease, transform 80ms ease;
}

.key:hover {
  background: var(--paper);
}

.key:active,
.key.is-pressed {
  transform: scale(0.97);
  background: var(--key-fn-hover);
}

.key-fn {
  background: var(--key-fn);
  border-color: transparent;
  font-size: 20px;
}

.key-fn:hover {
  background: var(--key-fn-hover);
}

.key-clear {
  background: var(--key-fn);
  border-color: transparent;
  color: var(--accent);
  font-weight: 650;
}

.key-clear:hover {
  background: var(--key-fn-hover);
}

.key-op {
  background: var(--accent-tint);
  border-color: transparent;
  color: var(--accent);
  font-size: 26px;
}

.key-op:hover,
.key-op:active,
.key-op.is-pressed {
  background: var(--accent-tint-strong);
}

.key-equals {
  grid-row: span 2;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--white);
  font-size: 28px;
}

.key-equals:hover,
.key-equals:active,
.key-equals.is-pressed {
  background: var(--accent-strong);
}

.key-zero {
  grid-column: span 2;
}

.hint {
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--paper);
  font-family: inherit;
  font-size: 12px;
}

@media (hover: none) {
  .hint {
    display: none;
  }
}

/* ------------------------------------------------------------ learn mode */

/* Learn mode reuses the calculator's card, display and key styles, so the
   two modes feel like one app. The display holds the problem box and the
   answer line; the steps appear under the symbol keys. */

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

.display.is-learn {
  min-height: 0;
  text-align: left;
}

.learn-view {
  display: grid;
  gap: 8px;
}

.learn-input {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: 9.5em;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--ink);
  font-family: inherit;
  font-size: 20px; /* 16px or more stops phones zooming in on focus */
  font-weight: 450;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  resize: none;
  overflow-y: auto;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.learn-input::placeholder {
  color: #a3a3a0;
  font-size: 16px;
}

.learn-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint-strong);
}

.learn-answer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  min-height: 1.6em;
  padding: 0 2px;
  overflow-wrap: anywhere;
}

.learn-answer-label {
  color: var(--muted);
  font-size: 14px;
}

.learn-answer-text {
  color: var(--ink);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.learn-answer.is-error .learn-answer-text {
  color: var(--accent);
  font-size: 16px;
  font-weight: 550;
}

.learn-answer-hint {
  color: var(--muted);
  font-size: 14px;
}

.learn-panel {
  margin-top: 16px;
}

.learn-keys {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.learn-keys .key {
  min-height: 48px;
  font-size: 19px;
}

.learn-keys .key-op {
  font-size: 22px;
}

.learn-keys sup {
  font-size: 0.65em;
}

.learn-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
  margin-top: 8px;
}

.learn-actions .key {
  min-height: 52px;
  font-size: 18px;
}

.solve-button {
  grid-row: auto;
  font-weight: 600;
}

.learn-result {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  transition: opacity 120ms ease;
}

/* The problem was edited since it was solved: dim the old steps. */
.learn-result.is-stale {
  opacity: 0.45;
}

.math {
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* example problems and choice chips */

.learn-examples-title {
  margin: 0 2px 8px;
  color: var(--muted);
  font-size: 13px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.chip:hover {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.chip[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--white);
  cursor: default;
}

/* notices: ambiguity, fixes, errors */

.notice-box {
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-tint);
}

.notice-box.is-error {
  background: var(--paper);
}

.notice-title {
  margin: 0;
  color: var(--accent);
  font-size: 15px;
  font-weight: 650;
}

.notice-text {
  margin: 4px 0 0;
  font-size: 14px;
}

.reading-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.reading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms ease;
}

.reading:hover {
  border-color: var(--accent);
}

.reading[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  cursor: default;
}

.reading-badge {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--white);
  font-size: 12px;
  font-weight: 600;
}

.notice-line {
  margin: 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--muted);
  font-size: 13.5px;
}

.notice-line.is-fixed {
  color: var(--ink);
}

.reading-as,
.target-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin: 0;
  padding: 0 2px;
}

.reading-as .math {
  font-size: 18px;
  font-weight: 500;
}

.reading-as-label,
.target-label {
  color: var(--muted);
  font-size: 13px;
}

/* steps */

.steps {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.step {
  position: relative;
  padding: 12px 14px 12px 50px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  counter-increment: step;
}

.step::before {
  content: counter(step);
  position: absolute;
  top: 12px;
  left: 14px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
  line-height: 24px;
  text-align: center;
}

.step-title {
  margin: 1px 0 0;
  font-size: 15px;
  font-weight: 620;
}

.step-detail {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.step-rows {
  display: grid;
  gap: 2px;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--paper);
}

.step-rows .math {
  margin: 0;
  font-size: 17px;
}

.step-rows .math:last-child {
  font-weight: 600;
}

/* final answer */

.answer-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--white);
}

.answer-card-label {
  margin: 0;
  font-size: 13px;
  opacity: 0.85;
}

.answer-card-text {
  margin: 2px 0 0;
  font-size: 28px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.answer-card-detail {
  margin: 6px 0 0;
  font-size: 14px;
  opacity: 0.9;
}

/* saved list tag for Learn problems */

.saved-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  line-height: 18px;
  text-transform: uppercase;
  vertical-align: 1px;
}

@media (max-width: 380px) {
  .learn-keys {
    gap: 6px;
  }

  .learn-keys .key {
    min-height: 44px;
  }

  .step {
    padding-left: 44px;
  }

  .step::before {
    left: 11px;
  }
}

/* ------------------------------------------------------------ saved list */

.saved {
  background: var(--white);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  padding: 18px 16px 14px;
  scroll-margin-top: 16px;
}

.saved:focus {
  outline: none;
}

.saved-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
}

.saved h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 620;
}

.text-button {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}

.text-button:hover {
  background: var(--accent-tint);
}

.empty,
.notice,
.privacy {
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: 14px;
}

.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-tint);
  color: var(--accent);
}

.privacy {
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
  font-size: 12.5px;
}

.saved-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  max-height: min(60vh, 560px);
  overflow-y: auto;
}

@media (max-width: 859px) {
  .saved-list {
    max-height: none;
  }
}

.saved-item {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  transition: border-color 120ms ease, background-color 120ms ease;
}

.saved-item.is-current {
  border-color: var(--accent);
  background: var(--accent-tint);
}

.saved-use {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  background: none;
  text-align: left;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.saved-use:hover {
  background: var(--paper);
}

.saved-item.is-current .saved-use:hover {
  background: var(--accent-tint-strong);
}

.saved-expr {
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.saved-result {
  font-size: 18px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.saved-date {
  color: var(--muted);
  font-size: 12px;
}

.saved-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  flex: none;
  border: 0;
  border-left: 1px solid var(--hairline);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.saved-remove:hover {
  background: var(--accent-tint);
  color: var(--accent);
}

/* ------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 10px 12px 10px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--white);
  font-size: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  z-index: 10;
}

.toast-action {
  padding: 4px 10px;
  border: 1px solid rgb(255 255 255 / 0.35);
  border-radius: 8px;
  background: none;
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.toast-action:hover {
  background: rgb(255 255 255 / 0.12);
}

/* ------------------------------------------------------------ small phones */

@media (max-width: 380px) {
  .calculator {
    padding: 12px;
  }

  .keypad {
    gap: 8px;
  }

  .key {
    min-height: 54px;
  }

  .work {
    font-size: 26px;
  }

  .brand-sep,
  .brand-app {
    display: none;
  }
}

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

/* ------------------------------------------------------------ links & privacy page */

.privacy a,
.policy a {
  color: var(--accent);
  text-underline-offset: 2px;
}

.privacy a {
  display: block;
  width: fit-content;
  margin-top: 2px;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.policy {
  max-width: 680px;
  margin: 24px auto 64px;
  padding: 28px 24px;
  background: var(--white);
  border: 1px solid var(--hairline);
  border-radius: 20px;
}

.policy h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.policy h2 {
  margin: 28px 0 6px;
  font-size: 17px;
  font-weight: 620;
}

.policy p {
  margin: 0 0 12px;
}

.policy-date {
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 720px) {
  .policy {
    margin: 16px 12px 48px;
    padding: 22px 18px;
  }
}
