/* Even — one material, the paper, and hairlines mixed from its own ink.
 * No shadows, no second surface (§6, as in Still's style.css). Colours come
 * from the whole-screen appearance (FR-401) through --ink and --paper. */

@font-face { font-family: "Even Serif"; src: url("./fonts/serif.woff") format("woff"); font-display: swap; }
@font-face { font-family: "Even Sans"; src: url("./fonts/sans.woff") format("woff"); font-display: swap; }
@font-face { font-family: "Even Rounded"; src: url("./fonts/rounded.woff") format("woff"); font-display: swap; }
@font-face { font-family: "Even Inter"; src: url("./fonts/inter.woff") format("woff"); font-display: swap; }
@font-face { font-family: "Even Roboto"; src: url("./fonts/roboto.woff") format("woff"); font-display: swap; }
@font-face { font-family: "Even Montserrat"; src: url("./fonts/montserrat.woff") format("woff"); font-display: swap; }

:root {
  --ink: #232120;
  --paper: #f5f1e9;
  --num-font: "Even Serif", Georgia, "Times New Roman", serif;
  --num-scale: 1;
  --key-scale: 1;
  --fg: color-mix(in srgb, var(--ink) 74%, var(--paper));
  --soft: color-mix(in srgb, var(--ink) 50%, var(--paper));
  --faint: color-mix(in srgb, var(--ink) 30%, var(--paper));
  --line: color-mix(in srgb, var(--ink) 14%, var(--paper));
  --hover: color-mix(in srgb, var(--ink) 6%, var(--paper));
  --press: color-mix(in srgb, var(--ink) 12%, var(--paper));
  --radius: 4px;
  --panel-width: 336px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ui-font:
    system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans JP",
    "Noto Sans SC", sans-serif;
  --main-size: calc(clamp(44px, 13vw, 68px) * var(--num-scale));
  color-scheme: light;
}

:root.is-dark {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.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;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

/* ------------------------------------------------------------ background */

#background {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#background[hidden] {
  display: none;
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  transition: right 200ms ease;
}

/* The drawer makes room so a change can be seen as it is made. */
@media (min-width: 900px) {
  body.panel-open #stage {
    right: var(--panel-width);
  }
}

/* ---------------------------------------------------------------- chrome */

#app-actions {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  opacity: 0.32;
  transition: opacity 160ms ease;
}

#app-actions:hover,
#app-actions:focus-within {
  opacity: 1;
}

#app-actions button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

#app-actions button:hover {
  background: var(--hover);
}

#app-actions svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (pointer: coarse) {
  #app-actions {
    opacity: 0.8;
  }

  #app-actions button {
    width: 42px;
    height: 42px;
  }

  #app-actions svg {
    width: 20px;
    height: 20px;
  }
}

body.quiet #app-actions {
  display: none;
}

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

#calc {
  position: relative;
  display: grid;
  /* minmax(0, …): a long unbroken number must shrink to fit, not widen the column. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  height: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding:
    calc(58px + env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

/* Tape (FR-201, FR-301): older lines rise and fade. */
#tape-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 42%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 42%);
}

#tape-wrap::-webkit-scrollbar {
  display: none;
}

#tape {
  margin: auto 0 0;
  padding: 0 0 6px;
  list-style: none;
}

.tape-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}

.tape-use {
  max-width: 100%;
  min-width: 0;
  padding: 3px 6px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  font-family: var(--num-font);
  font-size: calc(17px * var(--key-scale));
  line-height: 1.5;
  text-align: right;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
}

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

.tape-expr {
  color: var(--soft);
}

.tape-eq {
  margin: 0 0.32em;
  color: var(--faint);
}

.tape-ans {
  color: var(--fg);
}

.tape-tools {
  display: flex;
  flex: none;
  order: -1;
  opacity: 0;
  transition: opacity 120ms ease;
}

.tape-row:hover .tape-tools,
.tape-row:focus-within .tape-tools {
  opacity: 1;
}

@media (pointer: coarse) {
  .tape-tools {
    opacity: 0.45;
  }
}

.tape-tools button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--soft);
  cursor: pointer;
}

.tape-tools button:hover {
  background: var(--hover);
  color: var(--ink);
}

.tape-tools svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Display (FR-201, FR-203). */
#display {
  min-width: 0;
  padding: 8px 6px 16px;
  text-align: right;
}

#welcome {
  margin: 0 0 26px;
  font-size: 13.5px;
  line-height: 1.65;
  text-align: center;
  color: var(--fg);
}

.line {
  overflow: hidden;
  white-space: nowrap;
}

.line.wrap {
  white-space: normal;
  overflow-wrap: anywhere;
}

#main-line {
  min-height: 1.14em;
  font-family: var(--num-font);
  font-size: var(--main-size);
  line-height: 1.14;
  letter-spacing: -0.01em;
  color: var(--ink);
}

#main-line.is-empty {
  color: var(--faint);
}

#main-line.is-answer {
  cursor: copy;
}

#sub-line {
  min-height: 1.35em;
  font-family: var(--num-font);
  font-size: calc(var(--main-size) * 0.42);
  line-height: 1.35;
  color: var(--soft);
}

#sub-line.is-error {
  font-family: var(--ui-font);
  font-size: 14px;
  line-height: calc(var(--main-size) * 0.42 * 1.35);
  color: var(--fg);
}

#hint-line {
  min-height: 1.5em;
  font-family: var(--num-font);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--faint);
}

.fit {
  display: inline-block;
}

.seg-op {
  margin: 0 0.2em;
  color: var(--fg);
}

.seg-ghost {
  color: var(--faint);
}

/* A recalled exact value (FR-302): marked, quietly. */
.seg-val {
  text-decoration: underline dotted var(--faint);
  text-decoration-thickness: 0.05em;
  text-underline-offset: 0.14em;
}

sup {
  font-size: 0.55em;
  line-height: 0;
  vertical-align: 0.8em;
}

/* FR-007: a refused key dims the line for a moment, nothing louder. */
#main-line.refused {
  animation: refused 280ms ease;
}

@keyframes refused {
  40% {
    opacity: 0.45;
  }
}

/* Keypad (FR-102). */
#keypad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.key {
  display: grid;
  place-items: center;
  height: calc(clamp(54px, 8.8dvh, 76px) * var(--key-scale));
  min-width: 44px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-family: var(--num-font);
  font-size: calc(27px * var(--key-scale));
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 140ms ease;
}

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

.key:active,
.key.is-pressed {
  background: var(--press);
  transition: none;
}

.key--op {
  color: var(--fg);
}

.key--fn {
  color: var(--soft);
  font-size: calc(21px * var(--key-scale));
}

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

.key svg {
  width: calc(25px * var(--key-scale));
  height: calc(25px * var(--key-scale));
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.key .clear-label {
  font-family: var(--ui-font);
  font-size: calc(15px * var(--key-scale));
  letter-spacing: 0.06em;
}

body.quiet #keypad {
  display: none;
}

/* A phone has no other way in, so its keys stay (FR-701). */
@media (pointer: coarse) {
  body.quiet #keypad {
    display: grid;
  }
}

/* A phone turned sideways: tape and display on the left, keys on the right. */
@media (orientation: landscape) and (max-height: 540px) {
  #calc {
    max-width: 920px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    column-gap: 28px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  #tape-wrap {
    grid-column: 1;
    grid-row: 1;
    padding-top: 40px;
  }

  #display {
    grid-column: 1;
    grid-row: 2;
  }

  #keypad {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    padding-top: 0;
    border-top: 0;
  }

  .key {
    height: calc((100dvh - 48px) / 5 - 4px);
  }
}

/* ----------------------------------------------------------------- panel */

#panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  width: var(--panel-width);
  max-width: 92vw;
  overflow: hidden;
  background: var(--paper);
  border-left: 1px solid var(--line);
  color: var(--fg);
}

#panel[hidden] {
  display: none;
}

/* Narrow screens: a sheet from below. The keys step aside so the numbers sit
   just above it and every change can be seen (FR-702). */
@media (max-width: 899px) {
  body.panel-open #keypad {
    display: none;
  }

  body.panel-open #calc {
    padding-bottom: calc(min(60dvh, 560px) + 4px);
  }

  #panel {
    top: auto;
    left: 0;
    width: auto;
    max-width: none;
    height: min(60dvh, 560px);
    border-top: 1px solid var(--line);
    border-left: 0;
    border-radius: 12px 12px 0 0;
  }
}

.panel-head {
  position: relative;
  padding: 20px 22px 4px;
}

.panel-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.panel-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
}

.panel-close:hover {
  background: var(--hover);
  opacity: 1;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 22px 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  -webkit-user-select: none;
  user-select: none;
}

.group {
  padding: 22px 0 0;
}

.group > h3 {
  margin: 0 0 12px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  opacity: 0.55;
}

.group > .note {
  margin: -6px 0 12px;
  font-size: 11.5px;
  line-height: 1.5;
  opacity: 0.65;
}

.row {
  margin-bottom: 13px;
}

.row-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
}

.row-head label {
  font-size: 12.5px;
  color: var(--ink);
}

.row-head .value {
  margin-left: auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  opacity: 0.6;
}

.row-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 18px;
  accent-color: color-mix(in srgb, var(--ink) 60%, var(--paper));
}

select {
  width: 100%;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--radius);
  background: var(--hover);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
}

@media (pointer: coarse) {
  select {
    font-size: 16px;
  }
}

input[type="color"] {
  width: 38px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.preset {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 12.5px;
  cursor: pointer;
}

.preset:hover {
  background: var(--hover);
}

.preset[aria-pressed="true"] {
  border-color: var(--ink);
}

.swatch {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 11px;
  line-height: 1;
}

.btn {
  padding: 7px 13px;
  border: 0;
  border-radius: var(--radius);
  background: var(--hover);
  color: var(--ink);
  font-size: 12.5px;
  cursor: pointer;
}

.btn:hover {
  background: var(--press);
}

.btn--primary {
  background: var(--ink);
  color: var(--paper);
}

.btn--primary:hover {
  background: var(--ink);
  opacity: 0.88;
}

.btn--quiet {
  background: transparent;
  color: var(--fg);
}

.btn[disabled] {
  opacity: 0.4;
  cursor: default;
}

.warning {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 4px 0 12px;
  padding: 2px 0 2px 10px;
  border-left: 2px solid #c8860d;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink);
}

.warning[hidden] {
  display: none;
}

/* --------------------------------------------------------------- dialogs */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--ink) 24%, transparent);
  -webkit-backdrop-filter: blur(10px) saturate(0.8);
  backdrop-filter: blur(10px) saturate(0.8);
  animation: fade-in 150ms ease-out;
}

#overlay[hidden] {
  display: none;
}

.card {
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 26px 28px 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--fg);
  animation: card-in 180ms var(--ease);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.card h3 {
  margin: 18px 0 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink);
  opacity: 0.6;
}

.card p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-line;
}

.card a {
  color: var(--ink);
}

.card .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

.card .actions .spacer {
  flex: 1;
}

.shortcut-list {
  display: grid;
  margin: 0 0 6px;
  padding: 0;
  list-style: none;
}

.shortcut-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 34px;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink);
}

kbd {
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--hover);
  font-family: var(--ui-font);
  font-size: 11px;
  white-space: nowrap;
}

.card--handover {
  width: min(480px, 100%);
}

.receipt {
  display: block;
  max-width: 100%;
  max-height: 46dvh;
  margin: 4px auto 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.small {
  font-size: 11.5px !important;
  opacity: 0.7;
}

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

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: min(520px, 88vw);
  padding: 9px 10px 9px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-size: 12.5px;
  line-height: 1.5;
  transform: translateX(-50%);
  animation: fade-in 140ms ease-out;
}

#toast[hidden] {
  display: none;
}

#toast:not(:has(button)) {
  padding-right: 16px;
}

.noscript {
  position: fixed;
  inset: auto 0 40% 0;
  text-align: center;
  font-size: 14px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.985);
  }
}

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