/* 계산기 — 삼성 계산기 결의 밝고 정갈한 화면 */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #e9ebef;
  --line: #e4e6ea;
  --text: #14171c;
  --text-2: #3b414a;
  --muted: #8b9099;
  --accent: #3b82f6;
  --accent-press: #2f6fe0;
  --accent-soft: #eaf1fe;
  --red: #e5484d;
  --orange: #f4792b;
  --radius-key: 24px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05), 0 6px 16px rgba(17, 24, 39, .045);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic",
    "Noto Sans KR", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button, input, select { font-family: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

.view {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.view[hidden] { display: none; }

/* ---------- 상단 아이콘 줄 ---------- */

/* ---------- 맨 위 이름표: 성일이의 계산기 ---------- */
.brandbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 0;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #8b929b;
  user-select: none;
}
.brandbar__emoji {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  animation: brand-bob 3.2s ease-in-out infinite;
}
.brandbar__emoji svg { width: 100%; height: 100%; display: block; }
@keyframes brand-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-2px) rotate(-5deg); }
}
@media (prefers-reduced-motion: reduce) {
  .brandbar__emoji { animation: none; }
}
.topbar { padding-top: calc(2px + env(safe-area-inset-top)); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  padding: calc(4px + env(safe-area-inset-top)) 10px 4px;
  flex: 0 0 auto;
}
.topbar-right { display: flex; align-items: center; gap: 2px; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #2c3138;
  transition: background .15s ease, color .15s ease, transform .08s ease;
}
.icon-btn:active { background: #e7e9ed; transform: scale(.94); }
.icon-btn.is-on { color: var(--accent); background: var(--accent-soft); }

/* ---------- 화면 표시부 ---------- */
.display {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 92px;
  padding: 4px 16px 12px;
  gap: 6px;
  overflow: hidden;
}

.display-head {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 26px;
}
.display-head[hidden] { display: none; }

.copy-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  padding: 4px 9px 4px 7px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: #565d68;
  font-size: 11.5px;
  font-weight: 600;
  transition: background .15s ease, transform .08s ease;
}
.copy-chip svg { width: 13px; height: 13px; stroke-width: 1.9; }
.copy-chip:active { background: #dfe2e8; transform: scale(.95); }

.display-expr {
  flex: 1 1 auto;
  text-align: right;
  font-size: 17px;
  line-height: 1.35;
  color: var(--muted);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  font-variant-numeric: tabular-nums;
  min-height: 23px;
}
.display-expr::-webkit-scrollbar { display: none; }

.display-big {
  text-align: right;
  font-size: 54px;
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -.6px;
  color: var(--text);
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  font-variant-numeric: tabular-nums;
  transition: font-size .12s ease;
  cursor: pointer;
}
.display-big::-webkit-scrollbar { display: none; }

.display-kr {
  text-align: right;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -.2px;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.display-kr::-webkit-scrollbar { display: none; }

/* ---------- 공학용 줄 ---------- */
.sci {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  padding: 2px 10px 8px;
  flex: 0 0 auto;
  animation: sci-in .16s ease-out;
}
.sci[hidden] { display: none; }

@keyframes sci-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.sci-key {
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #e3eafa;
  color: #34405a;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -.2px;
  display: grid;
  place-items: center;
  transition: background .13s ease, transform .07s ease, color .13s ease;
}
.sci-key:active { transform: scale(.95); background: #d2ddf6; }
.sci-key.is-on { background: var(--accent); color: #fff; }

/* ---------- 기본 키패드 ---------- */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 2px 10px calc(10px + env(safe-area-inset-bottom));
  flex: 0 0 auto;
}

.key {
  display: grid;
  place-items: center;
  height: clamp(52px, 7.1vh, 66px);
  padding: 0;
  border: 0;
  border-radius: var(--radius-key);
  background: var(--surface);
  color: var(--text);
  font-size: 27px;
  font-weight: 500;
  line-height: 1;
  box-shadow: var(--shadow);
  user-select: none;
  transition: background .12s ease, transform .07s ease;
}
.key svg { width: 26px; height: 26px; stroke-width: 1.7; }
.key:active { background: #eceded; transform: scale(.965); }

.key-op {
  background: var(--surface-2);
  box-shadow: none;
  color: #40464f;
  font-size: 26px;
}
.key-op:active { background: #dfe2e7; }

.key-red { color: var(--red); }
.key-eq {
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  box-shadow: 0 7px 18px rgba(59, 130, 246, .3);
}
.key-eq:active { background: var(--accent-press); transform: scale(.965); }

/* ---------- 단위 계산기 ---------- */
.subhead {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  flex: 0 0 auto;
}
.subhead h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.5px;
}

.unit-cats {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 12px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 92%, transparent 100%);
  mask-image: linear-gradient(90deg, #000 0, #000 92%, transparent 100%);
}
.unit-cats::-webkit-scrollbar { display: none; }

.cat {
  flex: 0 0 auto;
  padding: 9px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -.3px;
  transition: background .14s ease, color .14s ease;
}
.cat.is-active { background: var(--surface-2); color: var(--text); font-weight: 700; }
.cat:active { background: #e7e9ed; }

.unit-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 20px 0;
}

.unit-row { padding: 18px 2px 16px; }

.unit-pick {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px 2px 2px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.3px;
}
.unit-pick .caret { width: 16px; height: 16px; stroke-width: 2; color: var(--text-2); }
.unit-pick select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  font-size: 16px;
}

.unit-num {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
  min-height: 46px;
}
.unit-value {
  max-width: 82%;
  font-size: clamp(28px, 8.6vw, 38px);
  font-weight: 500;
  letter-spacing: -.7px;
  color: #4a5058;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.unit-value::-webkit-scrollbar { display: none; }
.unit-suffix { font-size: 16px; color: var(--muted); font-weight: 500; }

.unit-row.is-active .unit-value { color: var(--text); font-weight: 600; }
.unit-row.is-active .unit-num::after {
  content: "";
  width: 2px;
  height: 1.25em;
  margin-left: 1px;
  align-self: center;
  background: var(--accent);
  animation: blink 1.1s steps(1, end) infinite;
}
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

.unit-div { height: 1px; background: var(--line); }

.unit-keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px 22px calc(14px + env(safe-area-inset-bottom));
  justify-items: center;
  flex: 0 0 auto;
}
.u-key {
  display: grid;
  place-items: center;
  width: 100%;
  max-width: 82px;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 26px;
  font-weight: 500;
  box-shadow: var(--shadow);
  transition: background .12s ease, transform .07s ease;
}
.u-key svg { width: 26px; height: 26px; stroke-width: 1.8; }
.u-key:active { background: #eceded; transform: scale(.94); }
.u-key.u-red { color: var(--red); }
.u-key.u-arrow {
  background: var(--orange);
  color: #fff;
  box-shadow: 0 8px 18px rgba(244, 121, 43, .28);
}
.u-key.u-arrow:active { background: #e06c21; }
.u-key.u-arrow.is-on { box-shadow: 0 0 0 3px rgba(244, 121, 43, .22), 0 8px 18px rgba(244, 121, 43, .28); }

/* ---------- 생활·사업 계산 ---------- */
.life-tabs {
  display: flex;
  gap: 6px;
  padding: 2px 14px 12px;
  flex: 0 0 auto;
}
.life-tab {
  flex: 1 1 0;
  padding: 10px 4px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -.3px;
  box-shadow: 0 1px 2px rgba(17, 24, 39, .04);
  transition: background .14s ease, color .14s ease;
}
.life-tab.is-active { background: #2f3339; color: #fff; box-shadow: none; }
.life-tab:active { transform: scale(.97); }

.life-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 14px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card[hidden] { display: none; }

.card {
  background: var(--surface);
  border-radius: 20px;
  padding: 18px 16px 16px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 5px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.hint {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  word-break: keep-all;
}
.note {
  margin: 10px 2px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  word-break: keep-all;
  overflow-wrap: break-word;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
}
.card .field:nth-last-of-type(1) { border-bottom: 0; }
.field span:first-child {
  flex: 0 0 78px;
  font-size: 14px;
  color: #4d5560;
  letter-spacing: -.2px;
}
.field input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: right;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -.4px;
  color: var(--text);
  outline: none;
  font-variant-numeric: tabular-nums;
}
.field input::placeholder { color: #c4c8cf; font-weight: 500; }
.field .won { flex: 0 0 auto; font-size: 13px; color: var(--muted); }

.result-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding: 14px 14px;
  border-radius: 14px;
  background: #f2f6ff;
}
.result-main span { font-size: 13.5px; font-weight: 600; color: #5b6472; }
.result-main strong {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.6px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.result-main strong.loss { color: var(--red); }

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 8px;
}
.result-grid.one { grid-template-columns: 1fr; }
.result-grid div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f6f7f9;
}
.result-grid span { font-size: 12.5px; color: var(--muted); }
.result-grid b { font-size: 15.5px; font-weight: 700; letter-spacing: -.3px; }

/* ---------- 스마트 계산 ---------- */
.smart-tabs { padding: 2px 12px 8px; }
.smart-tabs .life-tab {
  padding: 10px 2px;
  font-size: 13px;
  letter-spacing: -.4px;
  white-space: nowrap;
}

.demo-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 14px 10px;
  flex: 0 0 auto;
}
.demo-row::-webkit-scrollbar { display: none; }
.demo-row .chip { flex: 0 0 auto; background: #fff; }

.tts-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: #5b6472;
}

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d7dbe2;
  transition: background .16s ease;
}
.switch i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(17, 24, 39, .18);
  transition: transform .16s ease;
}
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }

.mem-chip {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 9px 12px;
  border: 1px dashed #c9d8f3;
  border-radius: 12px;
  background: #f8fbff;
  color: #3b6fc4;
  font-size: 12.5px;
  font-weight: 600;
  text-align: left;
}

.smart-out-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.mini-btn {
  flex: 0 0 auto;
  padding: 4px 9px;
  border: 0;
  border-radius: 999px;
  background: #e3edff;
  color: #2f6fe0;
  font-size: 11.5px;
  font-weight: 700;
}
.mini-btn:active { background: #d5e4ff; }

/* 메모 장부 */
#memo-input {
  width: 100%;
  min-height: 128px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8f9fb;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  resize: vertical;
  outline: none;
}
#memo-input:focus { border-color: var(--accent); background: #fff; }

.memo-list {
  margin-top: 10px;
  max-height: 190px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}
.memo-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid #f0f1f4;
  font-size: 13px;
}
.memo-line {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #6b7280;
}
.memo-val { flex: 0 0 auto; font-weight: 700; color: #20242b; }
.memo-val.neg { color: var(--red); }
.memo-val.muted { color: #c0c5cd; font-weight: 500; }

.memo-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f2f6ff;
}
.memo-total span { font-size: 13.5px; font-weight: 600; color: #5b6472; }
.memo-total strong { font-size: 23px; font-weight: 700; color: var(--accent); letter-spacing: -.5px; }
.memo-total em { font-style: normal; font-size: 12.5px; font-weight: 600; color: #4b638f; margin-left: auto; }

.memo-actions { display: flex; gap: 8px; margin-top: 10px; }
.ghost-btn {
  flex: 1 1 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: #4d5560;
  font-size: 13px;
  font-weight: 600;
}
.ghost-btn:active { background: #f1f3f6; }

.smart-input {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 10px;
}
.smart-input input {
  flex: 1 1 auto;
  min-width: 0;
  height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8f9fb;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s ease, background .15s ease;
}
.smart-input input::placeholder { color: #b3b8c1; font-size: 12.5px; }
.smart-input input:focus { border-color: var(--accent); background: #fff; }

.mic-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  transition: background .15s ease, color .15s ease;
}
.mic-btn svg { width: 21px; height: 21px; stroke-width: 1.9; }
.mic-btn:active { background: #dbe8fd; }
.mic-btn.is-rec { background: #ffe8e8; color: var(--red); animation: rec 1.1s ease-out infinite; }
@keyframes rec {
  0% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .35); }
  100% { box-shadow: 0 0 0 12px rgba(229, 72, 77, 0); }
}

.primary-btn {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.2px;
  transition: background .13s ease, transform .07s ease;
}
.primary-btn:active { background: var(--accent-press); transform: scale(.99); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #4d5663;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -.2px;
}
.chip:active { background: #eef0f4; }

.smart-out {
  margin-top: 14px;
  padding: 14px 14px 12px;
  border-radius: 16px;
  background: #f2f7ff;
  animation: fade-in .18s ease;
}
.smart-out-label { margin: 0; font-size: 12.5px; font-weight: 600; color: #5b6472; }
.smart-out-value {
  margin: 3px 0 0;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -.6px;
  color: var(--accent);
  word-break: break-all;
}
.smart-out-kr { margin: 2px 0 0; font-size: 13px; font-weight: 600; color: #4b638f; }

.steps {
  list-style: none;
  margin: 12px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid #e0e9fa;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.steps li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  line-height: 1.4;
}
.steps li span { color: #6b7280; flex: 0 0 auto; }
.steps li b { font-weight: 700; color: #20242b; text-align: right; }
.steps li.is-total b { color: var(--accent); }

.seg {
  display: flex;
  gap: 5px;
  padding: 4px;
  margin: 6px 0 8px;
  border-radius: 12px;
  background: #f1f3f7;
}
.seg-btn {
  flex: 1 1 0;
  padding: 9px 6px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #6b7280;
  font-size: 13px;
  font-weight: 600;
}
.seg-btn.is-active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(17, 24, 39, .09); }

.smart-div { height: 1px; background: var(--line); margin: 20px 0 16px; }
.field-date input { font-size: 15px; font-weight: 600; color: var(--text-2); }


/* ---------- 공학·그래프 ---------- */
.eng-body { padding-top: 2px; }
.eng-calc { display: flex; flex-direction: column; gap: 8px; }
.eng-display {
  padding: 6px 8px 8px;
  text-align: right;
  min-height: 86px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
}
.eng-display .display-big { font-size: 40px; }
.eng-sci { padding: 0; }
.eng-keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  padding-bottom: 8px;
}
.eng-keypad .key { height: 48px; font-size: 22px; border-radius: 16px; }
.eng-keypad .key svg { width: 22px; height: 22px; }
.eng-keypad .key-eq { font-size: 24px; }

.graph-wrap {
  position: relative;
  height: 260px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}
.graph-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.graph-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.graph-read { font-size: 12px; color: #5b6472; font-variant-numeric: tabular-nums; }
.graph-btns { display: flex; gap: 4px; flex: 0 0 auto; }
.graph-btns button {
  min-width: 34px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: #4d5560;
  font-size: 13px;
  font-weight: 600;
}
.graph-btns button:active { background: #f1f3f6; }
.graph-draw { align-self: stretch; padding: 0 13px; border-radius: 12px; height: 48px; }

.coef-row { display: flex; gap: 8px; margin: 6px 0 10px; }
.coef {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f9fb;
}
.coef span { font-size: 12px; font-weight: 700; color: #8b9099; }
.coef input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: right;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  outline: none;
}
.eq-out {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #f2f6ff;
  color: var(--accent);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.4px;
  word-break: break-all;
}
.eq-out.small { font-size: 14.5px; color: #2f6fe0; }
.lin-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: 12.5px; color: #6b7280; }
.lin-row input {
  flex: 1 1 0;
  width: 100%;
  min-width: 0;
  padding: 9px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8f9fb;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  outline: none;
}
.lin-row input:focus { border-color: var(--accent); background: #fff; }

/* ---------- 계산 기록 ---------- */
.sheet { position: absolute; inset: 0; z-index: 60; }
.sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .3);
  backdrop-filter: blur(1.5px);
  animation: fade-in .16s ease;
}
.sheet-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(330px, 84%);
  height: 100%;
  background: var(--surface);
  border-radius: 0 24px 24px 0;
  box-shadow: 18px 0 44px rgba(15, 23, 42, .16);
  animation: slide-in .18s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(-14px); opacity: .6; } to { transform: translateX(0); opacity: 1; } }

.sheet-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 10px 8px 18px;
}
.sheet-panel h2 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.3px; }

.sheet-list { flex: 1 1 auto; overflow-y: auto; padding: 2px 10px 8px; }

.hist-item {
  display: block;
  width: 100%;
  padding: 11px 10px 10px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  text-align: right;
  transition: background .13s ease;
}
.hist-item:active { background: #f3f4f6; }
.hist-memo {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #2f6fe0;
  font-size: 11.5px;
  font-weight: 700;
}
.hist-expr {
  display: block;
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-res {
  display: block;
  margin-top: 2px;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.hist-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 2px;
}
.memo-btn {
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #9aa0a9;
  font-size: 11.5px;
  font-weight: 600;
}
.memo-btn:active { background: #f0f1f4; }
.memo-input {
  width: 100%;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid #cfd6e4;
  border-radius: 9px;
  background: #fff;
  font-size: 12.5px;
  text-align: right;
  outline: none;
}
.memo-input:focus { border-color: var(--accent); }

.hist-empty {
  padding: 48px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
  word-break: keep-all;
}

.sheet-panel footer {
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
#history-clear {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 14px;
  background: #f3f4f6;
  color: #4d5560;
  font-size: 14.5px;
  font-weight: 600;
}
#history-clear:active { background: #e8eaee; }

/* ---------- 알림 ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 6px);
  z-index: 80;
  max-width: 80%;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(20, 23, 28, .9);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 넓은 화면 ---------- */
@media (min-width: 720px) {
  body {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    background:
      radial-gradient(900px 520px at 50% -8%, #ffffff 0%, #eef1f6 58%, #e6eaf1 100%);
  }
  .app {
    height: min(880px, calc(100dvh - 40px));
    border-radius: 34px;
    border: 1px solid rgba(15, 23, 42, .06);
    box-shadow: 0 26px 70px rgba(15, 23, 42, .14);
  }
  .key { height: 62px; }
}

@media (max-height: 720px) {
  .key { height: 50px; font-size: 24px; }
  .sci-key { height: 36px; font-size: 13px; }
  .display { min-height: 76px; }
  .display-big { font-size: 38px; }
  .eng-display { min-height: 62px; }
  .eng-keypad .key { height: 44px; font-size: 20px; }
  .eng-sci .sci-key { height: 34px; font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; transition-duration: .001s !important; }
}
