:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --ink: #16181c;
  --ink-soft: #5c6270;
  --line: #dcdcd6;
  --accent: #0f6d4d;
  --accent-soft: #e6f2ec;
  --warn: #8a5a00;
  --warn-soft: #fdf3e0;
  --minus: #a33;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --panel: #16191e;
    --ink: #e9ecf1;
    --ink-soft: #98a1b0;
    --line: #272c34;
    --accent: #4ecf9b;
    --accent-soft: #14261f;
    --warn: #e5b567;
    --warn-soft: #2a2213;
    --minus: #e58080;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 44rem;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

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

/* ---------- header ---------- */

.head { margin-bottom: 1.25rem; }

h1 {
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.15rem;
}

.sub {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ---------- display ---------- */

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

#input {
  display: block;
  width: 100%;
  border: 0;
  resize: none;
  padding: 1rem 1.1rem;
  font-family: var(--mono);
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--ink);
  background: transparent;
  outline: none;
  /* Concrete starting height so the empty state is correct without JS, and a
     ceiling so a long entry scrolls instead of pushing the total off screen. */
  height: 5.25rem;
  max-height: 40vh;
  overflow-y: auto;
}

#input::placeholder { color: var(--ink-soft); opacity: 0.65; }

.readout {
  display: block;
  border-top: 1px solid var(--line);
  padding: 0.9rem 1.1rem 1rem;
  background: var(--accent-soft);
  font-family: var(--mono);
  min-height: 3.5rem;
}

.readout-idle { color: var(--ink-soft); }

.total {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
  display: block;
  overflow-wrap: anywhere;
}

.total-alt {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin-top: 0.2rem;
  display: block;
}

/* ---------- breakdown ---------- */

.detail {
  margin-top: 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.detail-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  margin: 0 0 0.6rem;
  font-weight: 600;
}

.breakdown {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.9rem;
}

.breakdown li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px dashed var(--line);
}

.breakdown li:last-child { border-bottom: 0; }

.sign { width: 1ch; color: var(--ink-soft); flex: none; }
.sign.plus { color: var(--accent); }
.sign.minus { color: var(--minus); }

.amount { flex: none; min-width: 6ch; font-variant-numeric: tabular-nums; }
.what { color: var(--ink-soft); overflow-wrap: anywhere; }
.tag { color: var(--ink-soft); font-style: italic; }

.alts { margin-top: 0.7rem; font-size: 0.85rem; color: var(--ink-soft); }

.warnings { margin-top: 0.6rem; }

.warning {
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font-size: 0.85rem;
  margin-top: 0.35rem;
}

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

.pad { margin-top: 1.25rem; }

.pad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.pad-grid button,
.ghost,
.chip {
  font: inherit;
  cursor: pointer;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.pad-grid button {
  padding: 0.85rem 0;
  font-family: var(--mono);
  font-size: 1rem;
}

.pad-grid button:hover,
.ghost:hover,
.chip:hover { background: var(--accent-soft); border-color: var(--accent); }

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

.pad-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.ghost {
  flex: 1;
  padding: 0.7rem 0.5rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* ---------- examples ---------- */

.examples { margin-top: 1.75rem; }

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
}

.chip {
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-align: left;
  display: inline-block;
  text-decoration: none;
}

/* ---------- scratch pad ---------- */

.scratch-panel {
  margin-top: 1.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.1rem;
}

.scratch-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.scratch-head .detail-title { margin-bottom: 0.6rem; }

.scratch-add {
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 0.25rem 0.6rem;
  white-space: nowrap;
}

.scratch-add:hover { background: var(--accent); color: #fff; }

#scratch {
  display: block;
  width: 100%;
  height: 13rem;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  padding: 0.7rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.6;
  outline: none;
}

#scratch:focus { border-color: var(--accent); }
#scratch::placeholder { color: var(--ink-soft); opacity: 0.6; }

.scratch-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.scratch-status {
  margin: 0.5rem 0 0;
  min-height: 1.2em;
  font-size: 0.8rem;
  color: var(--accent);
  font-family: var(--mono);
}

.scratch-note {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

/* Side by side once there is room; stacked below the calculator until then. */
@media (min-width: 64rem) {
  .wrap { max-width: 66rem; }

  .layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 21rem;
    gap: 1.75rem;
    align-items: start;
  }

  .scratch-panel {
    margin-top: 0;
    position: sticky;
    top: 2rem;
  }

  #scratch { height: 22rem; }
}

/* ---------- footer ---------- */

.foot {
  margin-top: 2.5rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-align: center;
}

.foot p { margin: 0; }

/* .foot .foot-fine, not .foot-fine: it must outrank `.foot p { margin: 0 }`,
   or margin-inline: auto loses and the capped box sits flush left. */
.foot .foot-fine {
  margin-top: 0.5rem;
  font-size: 0.78rem;
  opacity: 0.8;
  max-width: 34rem;
  margin-inline: auto;
}

.kofi { margin-top: 1.1rem !important; }

.kofi img {
  height: 36px;
  width: auto;
  border: 0;
  vertical-align: middle;
}

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

@media (max-width: 30rem) {
  .wrap { padding-top: 1.25rem; }
  .total { font-size: 1.3rem; }
}
