/* 125naroom 計算機（2026-10-26）。デザイン：reference/design_handoff_125naroom_keisan */
:root {
  --bg: #faf8f3; --ink: #2b2a27; --sub: #77736a; --line: #e8e3d8; --soft: #f3efe6; --y: #e8dc6a; --yink: #2b2a27;
  --key: 75px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #2b2a27; --ink: #f3efe6; --sub: #a9a397; --line: #45433e; --soft: #34322f; color-scheme: dark; }
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: "Zen Kaku Gothic New", sans-serif; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
p, h1 { margin: 0; }

/* ホーム画面から開くと時計の帯・ホームバーの分（safe-area）が増えるので、足さずに大きいほうをとる */
.app { width: 390px; max-width: 100%; height: 100svh; min-height: 560px; margin: 0 auto; display: flex; flex-direction: column; padding: max(44px, calc(env(safe-area-inset-top, 0px) + 12px)) 24px max(22px, env(safe-area-inset-bottom, 0px)); }

/* ヘッダー */
.head { height: 44px; display: flex; align-items: center; justify-content: space-between; flex: none; }
.head h1 { font-size: 20px; font-weight: 500; letter-spacing: .08em; }
.hint { font-size: 11px; letter-spacing: .1em; color: var(--sub); }

/* 表示 */
.disp { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 22px; }
/* 高さが足りないときは履歴だけ縮む（入りきらない行は JS で古いほうから隠す） */
.hist { flex: 0 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-bottom: 6px; }
.hist:empty { margin-bottom: 0; }
.expr, .ans { flex: none; }
.hist span { font-family: "Jost", sans-serif; font-weight: 300; font-size: 15px; line-height: 1.5; color: var(--sub); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist span:not(:last-child) { opacity: .55; }
.expr { min-height: 30px; text-align: right; font-family: "Jost", sans-serif; font-weight: 300; font-size: 22px; line-height: 30px; color: var(--sub); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.rule { height: 1px; background: var(--line); margin: 12px 0 10px; flex: none; }
.ans { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.ans.is-error { cursor: default; }
.ans-box { height: 96px; width: 100%; display: flex; align-items: flex-end; justify-content: flex-end; }
.ans output { font-family: "Jost", sans-serif; font-weight: 200; font-size: 96px; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ans.is-error output { color: var(--sub); }
.note { height: 20px; display: flex; align-items: center; gap: 6px; font-size: 12px; letter-spacing: .06em; white-space: nowrap; }
.note.is-sub { color: var(--sub); }
.note svg { display: block; }
.note svg * { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.note svg .c { fill: currentColor; stroke: none; }

/* ボタン */
.keys { display: grid; grid-template-columns: repeat(4, var(--key)); justify-content: space-between; row-gap: 14px; flex: none; }
.key { width: var(--key); height: var(--key); border-radius: 50%; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-family: "Jost", sans-serif; font-weight: 400; font-size: 17px; font-variant-numeric: tabular-nums; color: var(--ink);
  transition: background 420ms ease-out, color 420ms ease-out, border-color 420ms ease-out;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.key.num { border-color: var(--ink); font-weight: 300; font-size: 30px; }
.key.pm { font-weight: 300; font-size: 24px; }
.key.ac { letter-spacing: .06em; }
.key svg { display: block; width: 24px; height: 24px; overflow: visible; }
.key svg line { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.key svg circle { fill: currentColor; stroke: none; }
.key.eq { background: var(--y); border-color: var(--y); color: var(--yink); }
.key:focus { outline: none; }
.key:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; }
@media (hover: hover) and (pointer: fine) {
  .key:hover { background: var(--soft); }
  .key.eq:hover { background: var(--y); }
}
/* 押している・選んだ演算子 */
.key.is-press, .key.is-sel, .key.is-press:hover, .key.is-sel:hover { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.key.eq.is-press { background: var(--ink); border-color: var(--ink); color: var(--y); }
.key.is-press { transition-duration: 70ms; }

/* フッター */
.foot { margin-top: auto; padding-top: 20px; display: flex; justify-content: space-between; align-items: center; flex: none; }
.keyhint { font-family: "Jost", sans-serif; font-size: 11px; letter-spacing: .06em; color: var(--sub); }
.logo img { display: block; height: 13px; width: auto; }
.logo-dark { display: none !important; }
@media (prefers-color-scheme: dark) {
  .logo-light { display: none !important; }
  .logo-dark { display: block !important; }
}

/* PC だけのヒント */
.hint, .keyhint { visibility: hidden; }
@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
  .app { padding-top: 40px; padding-bottom: 28px; }
  .hint, .keyhint { visibility: visible; }
}

/* 小さい画面（幅 360px 未満・高さの低いスマホ） */
@media (max-width: 359px) { :root { --key: calc((100vw - 48px - 36px) / 4); } }
@media (max-height: 700px) {
  :root { --key: 64px; }
  .app { padding-top: max(16px, calc(env(safe-area-inset-top, 0px) + 8px)); padding-bottom: max(16px, env(safe-area-inset-bottom, 0px)); }
  .keys { row-gap: 10px; }
  .hist { display: none; }
  .disp { padding-bottom: 12px; }
  .ans-box { height: 72px; }
  .foot { padding-top: 14px; }
}
/* それでも式が入りきらないとき（JS が付ける） */
.app.is-tight { --key: 64px; }
.app.is-tight .keys { row-gap: 10px; }
.app.is-tight .disp { padding-bottom: 12px; }
.app.is-tight .ans-box { height: 72px; }
@media (max-height: 600px) {
  :root { --key: 54px; }
  .keys { row-gap: 8px; }
  .rule { margin: 6px 0; }
  .ans-box { height: 52px; }
}
