/* ===== Клон калькулятора iOS 26. Все размеры сняты со скриншота iPhone 402x874pt ===== */
:root {
  --u: calc(min(100vw, 440px) / 402);     /* 1 единица = 1pt на экране 402pt */
  --bg: #000;
  --digit: #343434;
  --fn: #5e5e5e;
  --op: #ff9302;
  --acc: #2fbd8a;                          /* акцент секретной панели */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; }
html, body { height: 100%; }
body {
  position: fixed; inset: 0;
  background: var(--bg);
  color: #fff;
  font-family: var(--font);
  overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}

.calc {
  position: relative;
  height: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding-bottom: calc(env(safe-area-inset-bottom) + 26.2 * var(--u));
}

/* Верхние круглые кнопки */
.top-btn {
  position: absolute;
  top: calc(10 * var(--u));
  width: calc(40 * var(--u)); height: calc(40 * var(--u));
  border: 0; padding: 0; border-radius: 50%;
  background: #111111;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.09), inset 0 1px 0 rgba(255,255,255,.07);
  color: #fff;
  display: grid; place-items: center;
  transition: filter .3s ease;
  z-index: 2;
}
.top-btn:active { filter: brightness(1.9); transition: none; }
.top-left { left: calc(18.4 * var(--u)); }
.top-right { right: calc(18.4 * var(--u)); }
.top-left svg { width: calc(24.2 * var(--u)); height: calc(24.2 * var(--u)); }
.top-right svg { width: calc(16.95 * var(--u)); height: calc(22.7 * var(--u)); }

/* Экран */
.display {
  position: relative;
  flex: 1 1 auto;
  min-height: calc(120 * var(--u));
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  padding: 0 calc(14.75 * var(--u)) calc(14.7 * var(--u));
}
.expr {
  min-height: calc(26 * var(--u));
  font-size: calc(21 * var(--u));
  line-height: calc(26 * var(--u));
  color: rgba(235,235,245,.6);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  padding-right: calc(3 * var(--u));
}
.out-wrap {
  display: flex;
  justify-content: flex-end;     /* длинное выражение обрезается слева */
  overflow: hidden;
}
.out {
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: calc(67.3 * var(--u));
  font-weight: 400;
  line-height: 1;
  letter-spacing: calc(-0.4 * var(--u));
  font-variant-numeric: lining-nums;
}
.dot {
  position: absolute;
  left: calc(20 * var(--u)); bottom: calc(27 * var(--u));
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #2b2b2d;
}
.dot[hidden] { display: none; }

/* Клавиши */
.keys {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  column-gap: calc(7.4 * var(--u));
  row-gap: calc(7.9 * var(--u));
  padding: 0 calc(14.4 * var(--u));
}
.k {
  border: 0; padding: 0;
  height: calc(81.6 * var(--u));
  border-radius: 999px;
  display: grid; place-items: center;
  padding-bottom: calc(1.2 * var(--u));
  font: 400 calc(35.4 * var(--u))/1 var(--font);
  color: #fff;
  background-color: var(--digit);
  background-image: linear-gradient(180deg, rgba(255,255,255,.012), rgba(0,0,0,.03));
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.06),
    inset 0 1px .5px rgba(255,255,255,.09),
    inset 0 -1px .5px rgba(255,255,255,.03);
  transition: filter .35s ease;
  touch-action: manipulation;
  cursor: pointer;
}
.k.down { filter: brightness(1.75); transition: none; }

.k.fn {
  background-color: var(--fn);
  background-image: radial-gradient(70% 80% at 18% 10%, rgba(255,255,255,.05), transparent 60%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.08),
    inset 0 1px .5px rgba(255,255,255,.14);
}
.k.fn.down { filter: brightness(1.45); }
.k.txt { font-size: calc(34.8 * var(--u)); padding-bottom: calc(1.4 * var(--u)); }
.k[data-k="pct"] { font-size: calc(45.5 * var(--u)); font-weight: 300; padding-bottom: calc(1 * var(--u)); }

.k.op {
  background-color: var(--op);
  background-image: linear-gradient(180deg, rgba(255,255,255,0) 70%, rgba(0,0,0,.025));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.10), inset 0 1px .5px rgba(255,255,255,.22);
}
.k.op.down { filter: brightness(1.3); }

.k:has(svg) { padding-bottom: 0; }
.k svg { display: block; }
.i-op { width: calc(33.4 * var(--u)); height: calc(33.4 * var(--u)); transform: translate(calc(-0.3 * var(--u)), calc(0.3 * var(--u))); }
.i-back { width: calc(38 * var(--u)); height: calc(32 * var(--u)); transform: translate(calc(-1.3 * var(--u)), calc(0.3 * var(--u))); }
.i-sign { width: calc(34 * var(--u)); height: calc(34 * var(--u)); transform: translate(calc(0.2 * var(--u)), calc(0.4 * var(--u))); }

/* ===== Секретная панель ===== */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.72);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  display: grid; place-items: end center;
  padding: 0 10px calc(env(safe-area-inset-bottom) + 10px);
}
.sheet[hidden] { display: none; }
.panel {
  width: 100%; max-width: 440px; max-height: 88dvh; overflow-y: auto;
  background: #141917;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 24px;
  padding: 20px 20px 16px;
  animation: rise .28s cubic-bezier(.22,.61,.36,1);
}
@keyframes rise { from { transform: translateY(26px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 20px; font-weight: 600; }
.done { border: 0; background: none; color: var(--acc); font: 600 16px var(--font); padding: 6px 2px; cursor: pointer; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid rgba(255,255,255,.06); }
.row:first-of-type { border-top: 0; }
.row-title { font-size: 16px; }
.row-sub { font-size: 12.5px; color: #8a938d; line-height: 1.4; margin-top: 3px; }

.switch { flex: 0 0 auto; width: 51px; height: 31px; border-radius: 999px; border: 0; background: #39393d; position: relative; transition: background-color .2s; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform .2s cubic-bezier(.22,.61,.36,1); box-shadow: 0 2px 5px rgba(0,0,0,.35); }
.switch[aria-checked="true"] { background: var(--acc); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

.label { font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase; color: #6c756f; margin: 14px 0 8px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; background: #0d100f; border-radius: 12px; padding: 3px; }
.seg button { border: 0; border-radius: 9px; background: none; color: #b9c0bb; font: 500 13.5px var(--font); padding: 10px 4px; cursor: pointer; transition: background-color .2s, color .2s; }
.seg button.on { background: #26302b; color: #fff; }

.field { width: 100%; background: #0d100f; border: 1px solid rgba(255,255,255,.08); border-radius: 12px; color: #fff; font: 500 20px var(--font); padding: 12px 14px; outline: none; user-select: text; -webkit-user-select: text; }
.field:focus { border-color: var(--acc); }

.preview { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 12px; background: #0d100f; border: 1px solid rgba(47,189,138,.25); border-radius: 14px; padding: 14px 16px; margin: 16px 0 6px; }
.preview-label { font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase; color: #6c756f; }
.preview-num { font-size: 28px; font-weight: 300; color: var(--acc); text-align: right; font-variant-numeric: tabular-nums; }
.preview-decode { grid-column: 1 / -1; font-size: 12.5px; color: #8a938d; text-align: right; margin-top: 2px; min-height: 16px; }

.hint { font-size: 12.5px; color: #8a938d; line-height: 1.5; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.06); }

.seg-note { margin-top: 8px; }

/* Запуск с иконки. Статус-бар системный (чёрный, страница начинается сразу под ним),
   поэтому круглые кнопки стоят у самого верха страницы. Если иконка добавлена давно,
   со старым прозрачным статус-баром, отступ берётся из safe-area. */
html.standalone .top-btn { top: env(safe-area-inset-top); }

/* ===== Экран активации ===== */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: #000;
  display: grid; place-items: center;
  padding: 24px;
  padding-top: calc(env(safe-area-inset-top) + 24px);
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
}
.gate[hidden] { display: none; }
.gate-card { width: 100%; max-width: 360px; }
.gate-card h1 { font-size: 28px; font-weight: 600; letter-spacing: -.3px; margin-bottom: 10px; }
.gate-lead { font-size: 15px; line-height: 1.45; color: #a5aaa7; margin-bottom: 22px; }
.gate-input {
  width: 100%; height: 54px;
  background: #121513; border: 1px solid rgba(255,255,255,.1); border-radius: 14px;
  color: #fff; font: 500 18px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 1px;
  text-align: center; text-transform: uppercase;
  outline: none; user-select: text; -webkit-user-select: text;
  transition: border-color .2s;
}
.gate-input::placeholder { color: #4b524e; letter-spacing: 1px; }
.gate-input:focus { border-color: var(--acc); }
.gate-btn {
  width: 100%; height: 54px; margin-top: 12px;
  border: 0; border-radius: 14px;
  background: var(--acc); color: #04150f;
  font: 600 17px var(--font);
  transition: filter .2s, opacity .2s;
  cursor: pointer;
}
.gate-btn:active { filter: brightness(1.12); }
.gate-btn[disabled] { opacity: .55; }
.gate-msg { min-height: 40px; margin-top: 14px; font-size: 14px; line-height: 1.4; color: #e5796c; }
.gate-msg.ok { color: var(--acc); }
.gate-note { margin-top: 10px; font-size: 12.5px; line-height: 1.5; color: #6c756f; }

.guide-link { display: block; margin-top: 14px; padding: 13px; border-radius: 12px; background: #0d100f; border: 1px solid rgba(255,255,255,.08); color: var(--acc); font-size: 15px; font-weight: 500; text-align: center; text-decoration: none; }
.seg button { white-space: nowrap; }
.gate-buy { display: inline-block; margin-top: 18px; color: var(--acc); font-size: 15px; font-weight: 500; text-decoration: none; }

/* ===== История расчётов ===== */
.hist { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.42); display: flex; align-items: flex-end; }
.hist[hidden] { display: none; }
.hist-panel {
  width: 100%; max-width: 440px; margin: 0 auto; height: 68%;
  background: #1c1c1e; border-radius: calc(38 * var(--u)) calc(38 * var(--u)) 0 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.09);
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  animation: histUp .32s cubic-bezier(.22,.61,.36,1);
}
@keyframes histUp { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.hist-grab { flex: 0 0 auto; width: 36px; height: 5px; border-radius: 3px; background: #5a5a5e; margin: 6px auto 0; }
.hist-head { flex: 0 0 auto; display: flex; justify-content: space-between; padding: 6px 16px 4px; }
.hist-head button { border: 0; background: none; padding: 8px 4px; font: 400 17px var(--font); color: var(--op); cursor: pointer; }
#hist-done { font-weight: 600; }
.hist-list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 0 20px 24px; touch-action: pan-y; }
.hist-group { padding: 18px 0 6px; font-size: 13px; color: #8e8e93; }
.hist-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 10px 0; border: 0; border-bottom: .5px solid #38383a; background: none; color: #fff; font-family: var(--font); text-align: left; cursor: pointer; }
.hist-item:active { background: rgba(255,255,255,.06); }
.hist-expr { font-size: 15px; color: #8e8e93; overflow-wrap: anywhere; }
.hist-res { font-size: 22px; }
.hist-empty { padding-top: 48px; text-align: center; font-size: 17px; color: #8e8e93; }

/* ===== Горизонтальный экран: пять столбцов и четыре ряда, как в оригинале.
   Размеры и цвета сняты со скриншота настоящего калькулятора (экран 874x402pt). ===== */
@media (orientation: landscape) and (min-width: 560px) {
  :root { --u: calc(100vw / 874); --digit: #292929; --fn: #565656; --op: #fe9200; }
  .calc { max-width: none; padding-bottom: calc(25.8 * var(--u)); }
  .top-btn, html.standalone .top-btn { top: calc(22.1 * var(--u)); }
  .top-left { left: calc(34.8 * var(--u)); }
  .top-right { right: calc(34.8 * var(--u)); }
  .display { min-height: 0; padding: 0 calc(72.2 * var(--u)) calc(10 * var(--u)); }
  .out { font-size: calc(42.1 * var(--u)); letter-spacing: calc(-.25 * var(--u)); }
  .expr { min-height: calc(18 * var(--u)); font-size: calc(14 * var(--u)); line-height: calc(18 * var(--u)); padding-right: calc(2 * var(--u)); }
  .dot { left: calc(82 * var(--u)); bottom: calc(16 * var(--u)); }

  .keys {
    grid-template-columns: repeat(5, 1fr);
    grid-template-areas:
      "k7   k8 k9  back div"
      "k4   k5 k6  ac   mul"
      "k1   k2 k3  pct  sub"
      "sign k0 dot eq   add";
    column-gap: calc(7 * var(--u));
    row-gap: calc(7.85 * var(--u));
    padding: 0 calc(71.2 * var(--u));
  }
  .k { height: calc(43.3 * var(--u)); font-size: calc(18.6 * var(--u)); padding-bottom: calc(.6 * var(--u)); }
  .k.txt { font-size: calc(18 * var(--u)); padding-bottom: calc(.6 * var(--u)); }
  .k[data-k="pct"] { font-size: calc(24.1 * var(--u)); padding-bottom: calc(.5 * var(--u)); }
  .k.op, .k:has(svg) { padding-bottom: 0; }
  .i-op { width: calc(17.6 * var(--u)); height: calc(17.6 * var(--u)); transform: translate(calc(-.2 * var(--u)), calc(.1 * var(--u))); }
  .i-back { width: calc(20.2 * var(--u)); height: calc(17 * var(--u)); transform: translate(calc(-.7 * var(--u)), calc(.1 * var(--u))); }
  .i-sign { width: calc(18.4 * var(--u)); height: calc(18.4 * var(--u)); transform: translate(calc(.1 * var(--u)), calc(.1 * var(--u))); }

  .k[data-k="7"] { grid-area: k7; } .k[data-k="8"] { grid-area: k8; } .k[data-k="9"] { grid-area: k9; }
  .k[data-k="4"] { grid-area: k4; } .k[data-k="5"] { grid-area: k5; } .k[data-k="6"] { grid-area: k6; }
  .k[data-k="1"] { grid-area: k1; } .k[data-k="2"] { grid-area: k2; } .k[data-k="3"] { grid-area: k3; }
  .k[data-k="0"] { grid-area: k0; } .k[data-k="dot"] { grid-area: dot; } .k[data-k="sign"] { grid-area: sign; }
  .k[data-k="back"] { grid-area: back; } .k[data-k="ac"] { grid-area: ac; } .k[data-k="pct"] { grid-area: pct; }
  .k[data-k="div"] { grid-area: div; } .k[data-k="mul"] { grid-area: mul; } .k[data-k="sub"] { grid-area: sub; }
  .k[data-k="add"] { grid-area: add; } .k[data-k="eq"] { grid-area: eq; }

  .hist-panel { height: 88%; }
  .gate { overflow-y: auto; place-items: start center; }
}
@font-face{font-family:'Caveat';font-style:normal;font-weight:500;font-display:swap;src:url(fonts/caveat-cyrillic.woff2) format('woff2');unicode-range:U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116}
@font-face{font-family:'Caveat';font-style:normal;font-weight:500;font-display:swap;src:url(fonts/caveat-latin-ext.woff2) format('woff2');unicode-range:U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF}
@font-face{font-family:'Caveat';font-style:normal;font-weight:500;font-display:swap;src:url(fonts/caveat-latin.woff2) format('woff2');unicode-range:U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD}

/* ===== Меню режимов ===== */
.mode-menu {
  position: fixed; z-index: 35;
  top: calc(env(safe-area-inset-top) + 50 * var(--u)); right: calc(14 * var(--u));
  min-width: 250px; padding: 6px;
  background: rgba(44,44,46,.92); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-radius: 22px; box-shadow: 0 18px 50px rgba(0,0,0,.6), inset 0 0 0 1px rgba(255,255,255,.08);
  display: grid; gap: 1px;
  animation: menuIn .18s cubic-bezier(.22,.61,.36,1); transform-origin: top right;
}
.mode-menu[hidden] { display: none; }
@keyframes menuIn { from { transform: scale(.86); opacity: 0; } to { transform: none; opacity: 1; } }
.mode-menu button { display: flex; align-items: center; height: 46px; padding: 0 14px 0 40px; border: 0; border-radius: 16px; background: none; color: #fff; font: 400 17px var(--font); text-align: left; position: relative; cursor: pointer; }
.mode-menu button:active { background: rgba(255,255,255,.1); }
.mode-menu button.on::before { content: ""; position: absolute; left: 15px; top: 50%; width: 11px; height: 6px; border-left: 2.2px solid #fff; border-bottom: 2.2px solid #fff; transform: translateY(-70%) rotate(-45deg); }
.mode-menu button[data-m="convert"] { margin-top: 5px; border-top: .5px solid rgba(255,255,255,.14); border-radius: 0 0 16px 16px; }

/* ===== Математические заметки ===== */
.notes { position: fixed; inset: 0; z-index: 30; background: #000; }
.notes[hidden] { display: none; }
.notes canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.notes-secret { position: absolute; top: 0; left: 30%; width: 40%; height: calc(env(safe-area-inset-top) + 62 * var(--u)); z-index: 2; }
.notes-answer { position: absolute; z-index: 1; display: flex; align-items: center; gap: .08em; white-space: nowrap; pointer-events: none;
  font-family: 'Caveat', 'Bradley Hand', 'Segoe Print', cursive; font-weight: 500; line-height: 1.2; color: #ffd60a; transform-origin: 0 50%; }
.notes-answer[hidden] { display: none; }
.notes-answer span { display: inline-block; clip-path: inset(-10% 100% -10% 0); animation: noteWrite .26s ease-out forwards; }
@keyframes noteWrite { to { clip-path: inset(-10% -10% -10% 0); } }
.notes-answer svg { width: .78em; height: .78em; margin-left: .06em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.notes-answer svg path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: noteDraw .7s ease-in-out forwards; }
@keyframes noteDraw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) {
  .notes-answer span { animation-duration: .01s; } .notes-answer svg path { animation-duration: .01s; }
}
