:root {
  --bg: #e9efec;
  --surface: #fbfdfc;
  --ink: #1c2a2e;
  --muted: #5b6b6d;
  --line: #c9d6d2;
  --accent: #0d6b70;
  --accent-soft: #d5ebe9;
  --key: #f3f7f5;
  --key-press: #dfe9e6;
  --warn: #9a5b12;
  --warn-soft: #f6e8d2;
  --f-digit: "DotGothic16", "Osaka-Mono", ui-monospace, monospace;
  --f-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111719; --surface: #192225; --ink: #e3ecea; --muted: #93a4a5; --line: #2c3a3d;
    --accent: #5cc2c6; --accent-soft: #1d3a3c; --key: #1f292c; --key-press: #2a383b;
    --warn: #e2a85a; --warn-soft: #3a2c19; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111719; --surface: #192225; --ink: #e3ecea; --muted: #93a4a5; --line: #2c3a3d;
  --accent: #5cc2c6; --accent-soft: #1d3a3c; --key: #1f292c; --key-press: #2a383b;
  --warn: #e2a85a; --warn-soft: #3a2c19; color-scheme: dark;
}
* { box-sizing: border-box; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--f-body); font-size: 15px; line-height: 1.6;
  padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(16px, env(safe-area-inset-left, 0px));
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.version { margin: 8px 0 0; font-size: 11px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.app { max-width: 440px; margin: 0 auto; padding-block: 20px 40px; display: flex; flex-direction: column; gap: 18px; }

header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-family: var(--f-digit); font-weight: 400; font-size: 26px; letter-spacing: .04em; }
header p { margin: 0; color: var(--muted); font-size: 12px; text-align: right; }

/* Ticket */
.ticket {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px 16px 16px 28px;
}
.ticket::before {
  content: ""; position: absolute; left: 13px; top: 10px; bottom: 10px;
  border-left: 2px dotted var(--line);
}
.ticket-head { display: flex; justify-content: space-between; align-items: center; font-size: 11px; letter-spacing: .12em; color: var(--muted); }
.ticket-head button {
  font: inherit; letter-spacing: .08em; color: var(--muted); background: none; border: 0; padding: 4px 2px; cursor: pointer;
}
.ticket-head button:hover { color: var(--accent); }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.slot {
  font-family: var(--f-digit); font-size: clamp(44px, 15vw, 64px); line-height: 1.15; color: var(--ink);
  background: transparent; border: 0; border-bottom: 3px solid var(--line); border-radius: 6px 6px 0 0;
  padding: 4px 0 2px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.slot.empty { color: var(--line); }
.slot.active { background: var(--accent-soft); border-bottom-color: var(--accent); }
.slot:focus-visible, .key:focus-visible, .switch input:focus-visible + span, .ticket-head button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Keypad */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key {
  font-family: var(--f-digit); font-size: 26px; color: var(--ink);
  background: var(--key); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 0; cursor: pointer; touch-action: manipulation;
}
.key:active { background: var(--key-press); }
.key.fn { font-family: var(--f-body); font-size: 14px; font-weight: 500; color: var(--muted); }

.options { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span {
  width: 40px; height: 24px; border-radius: 12px; background: var(--line); position: relative; transition: background .15s; flex: none;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); transition: transform .15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }

/* Results */
.result { display: flex; flex-direction: column; gap: 10px; }
.summary { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.summary .big { font-family: var(--f-digit); font-size: 34px; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.summary .none { font-weight: 700; }
.summary small { color: var(--muted); font-size: 13px; }
ol.answers { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
ol.answers li {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 10px 2px; border-bottom: 1px solid var(--line); min-width: 0;
}
.expr { font-family: var(--f-mono); font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.expr .eq { color: var(--muted); }
.chip {
  flex: none; font-size: 11px; font-weight: 500; letter-spacing: .04em;
  color: var(--warn); background: var(--warn-soft); border-radius: 999px; padding: 2px 8px;
}
.note { margin: 0; font-size: 12px; color: var(--muted); }
.target { display: inline-flex; align-items: center; gap: 6px; }
.target .step {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--key);
  color: var(--ink); font-size: 18px; line-height: 1; cursor: pointer; touch-action: manipulation;
}
.target .step:active { background: var(--key-press); }
.target output {
  min-width: 2.6ch; text-align: center; font-family: var(--f-digit); font-size: 22px; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.target.changed output { color: var(--warn); }
.target .reset { font: inherit; font-size: 12px; color: var(--accent); background: none; border: 0; padding: 4px 2px; cursor: pointer; }
.target .step:focus-visible, .target .reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .switch span, .switch span::after { transition: none; } }
