/* Палитра 2: Полночь + фиолет */
:root {
  --bg: #0B1020;
  --num: #1C2440;
  --fn: #36406A;
  --op: #8B6CF6;
  --txt: #E8EAF6;
  --op-txt: #FFFFFF;
  --muted: #7C84A8;
  --sheet: #141A30;

  --key: 80px;   /* размер кнопки — пересчитывается в app.js */
  --gap: 10px;   /* расстояние между кнопками */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Верхняя панель */
.topbar {
  display: flex;
  justify-content: space-between;
  padding: 10px 20px 0;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--num);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter .25s;
}
.icon-btn:active { filter: brightness(1.5); transition: none; }

/* Дисплей */
.display {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 0 24px 10px;
  text-align: right;
}
.expr {
  color: var(--muted);
  font-size: 30px;
  min-height: 1.25em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
}
.result {
  font-size: 88px;
  font-weight: 300;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  letter-spacing: -0.02em;
}

/* Клавиатура */
.keypad-area {
  position: relative;
  padding: 0 16px 16px;
}
.keypad {
  display: grid;
  grid-template-columns: repeat(4, var(--key));
  grid-auto-rows: var(--key);
  gap: var(--gap);
  width: max-content;
  margin-left: auto;
  margin-right: auto;
}
.key {
  width: var(--key);
  height: var(--key);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--key) * 0.4);
  font-weight: 400;
  transition: filter .3s, background-color .2s, color .2s;
}
.key.num { background: var(--num); }
.key.fn  { background: var(--fn); font-size: calc(var(--key) * 0.32); }
.key.op  { background: var(--op); color: var(--op-txt); font-size: calc(var(--key) * 0.46); }
.key.pressed { filter: brightness(1.45); transition: none; }

/* Выбранная операция (ждём второе число) — инверсия цветов, как в iOS */
.key.op.sel { background: var(--txt); color: var(--op); }

.pm { font-size: 0.85em; letter-spacing: -0.05em; }

/* Шторка истории */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  max-height: 75%;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  animation: up .25s ease-out;
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sheet-title { font-weight: 600; }
.text-btn { color: var(--op); font-size: 17px; padding: 6px 2px; }
.history-list {
  list-style: none;
  margin: 0;
  padding: 0 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.history-list li {
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
  text-align: right;
}
.history-list .h-expr { color: var(--muted); font-size: 16px; }
.history-list .h-res { font-size: 26px; }
.history-list .empty { color: var(--muted); text-align: center; padding: 40px 0; border: 0; }

/* Всплывающая подсказка */
.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 70px);
  transform: translateX(-50%);
  background: var(--fn);
  color: var(--txt);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 15px;
  z-index: 20;
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }

/* Настройка зоны пальца */
.zone {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(11, 16, 32, .94);
  touch-action: none;
}
.zone[hidden] { display: none; }
.zone-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.zone-bar {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 18px;
  gap: 12px;
}
.zone-bar .text-btn { background: var(--num); border-radius: 18px; padding: 8px 14px; }
.zone-bar .strong { background: var(--op); color: var(--op-txt); font-weight: 600; }
.zone-hint {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 70px);
  left: 24px;
  right: 24px;
  text-align: center;
  font-size: 18px;
  line-height: 1.4;
  color: var(--txt);
  pointer-events: none;
}
.zone-preview { position: absolute; touch-action: none; }
.zone-preview[hidden] { display: none; }
.zone-preview .keypad { margin: 0; pointer-events: none; }
.zone-preview::before {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px dashed var(--op);
  border-radius: 16px;
}
.zone-handle {
  position: absolute;
  top: -22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--txt);
  color: var(--op);
  display: flex;
  align-items: center;
  justify-content: center;
}
.zone-handle.right-hand { left: -22px; }
.zone-handle.left-hand { right: -22px; transform: scaleX(-1); }

/* Горизонтальный телефон: iOS не даёт веб-приложению запретить поворот, поэтому просим повернуть обратно */
@media (orientation: landscape) and (max-height: 500px) {
  .app, .zone, .sheet-backdrop { visibility: hidden; }
  body::after {
    content: "Поверни телефон вертикально";
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--muted);
  }
}

.haptic { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
