:root {
  --bg: #000;
  --text: #fff;
  --subtext: #9a9aa0;
  --num: #27282c;
  --num-active: #3a3b40;
  --fn: #5e5f63;
  --op: #ff9f0a;
  --op-active: #f7be69;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
}
body { display: grid; place-items: center; overscroll-behavior: none; }
button, input, label {
  touch-action: manipulation;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif !important;
}

.phone {
  width: min(100vw, 430px);
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
  padding: 0 14px 0;
  background: var(--bg);
}
@supports (height: 100dvh) {
  .phone {
    height: 100dvh;
    min-height: 100dvh;
  }
}

.calc {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0;
}
.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.icon-share {
  width: 24px;
  height: 24px;
}
.icon-btn.icon-btn-help {
  width: auto;
  height: 42px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  display: flex !important;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.icon-btn-help .icon-svg {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}
.icon-btn-help span {
  display: inline-block;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.hidden {
  display: none !important;
}
.icon-btn-help.hidden {
  display: none !important;
}
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid #33353a;
  background: #15161a; color: #d6d7dc;
  display: grid; place-items: center;
}
.icon { display: inline-block; width: 21px; height: 21px; position: relative; }
.icon-list::before {
  content: "";
  position: absolute;
  left: 7px;
  right: 1px;
  top: 3px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
}
.icon-list::after {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
}
.icon-svg {
  width: 22px;
  height: 22px;
  display: block;
}

.display-wrap {
  margin-top: auto;
  padding: 16px 4px 10px;
  text-align: right;
}
.expr {
  min-height: 40px;
  color: var(--subtext);
  font-size: clamp(32px, 6vw, 52px);
  line-height: 1.1;
  letter-spacing: 0.2px;
  overflow: hidden;
  white-space: nowrap;
}
.display {
  margin-top: 6px;
  font-size: clamp(48px, 16vw, 102px);
  line-height: 1.02;
  font-weight: 350;
  letter-spacing: -1px;
  white-space: nowrap;
  overflow: hidden;
}

.debug {
  display: none;
  margin: 0 4px 10px;
  min-height: 30px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #111218;
  border: 1px solid #2b2d36;
  color: #9fe89f;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.keys {
  --key-size: clamp(70px, 21vw, 96px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: var(--key-size);
  gap: 10px;
  margin-top: 6px;
  padding-bottom: var(--keys-pad-bottom, 40px);
  align-content: end;
  justify-items: center;
}
.key {
  width: var(--key-size);
  height: var(--key-size);
  border-radius: 50%;
  border: none;
  background: var(--num);
  color: #f5f5f7;
  font-size: clamp(32px, 8vw, 56px);
  font-weight: 400;
}
.key:active { background: var(--num-active); }
.key-fn { background: var(--fn); }
.key-op {
  background: var(--op);
  color: #fff;
  font-size: clamp(44px, 10vw, 70px);
  font-weight: 400;
}
.key-op:active { background: var(--op-active); }

.key-sign {
  letter-spacing: 0.5px;
}

.config {
  border: none;
  padding: 0;
  margin: auto 0 0;
  width: 100%;
  max-width: none;
  background: transparent;
}
.config[open] {
  display: flex;
  align-items: flex-end;
  justify-content: stretch;
  min-height: 100vh;
}
.config::backdrop { background: rgba(0, 0, 0, 0.5); }
.config-card {
  margin: 0;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: #15161a;
  color: #fff;
  border-radius: 18px 18px 0 0;
  border-top: 1px solid #30333d;
  overflow: hidden;
}
.sheet-top {
  flex: 0 0 auto;
  padding: 10px 18px 12px;
  background: #15161a;
  border-bottom: 1px solid #2a2d36;
  touch-action: none;
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 18px max(48px, calc(env(safe-area-inset-bottom) + 48px));
}
.config-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 0;
  background: #15161a;
}
.config-card h2 { margin: 0; font-size: 24px; }
.cfg-close {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: #2c2f38;
  color: #d6d9e4;
  font-size: 18px;
  line-height: 1;
}
.hint { margin: 0; color: #b5b8c4; font-size: 15px; }
.config-card label { display: grid; gap: 8px; font-size: 17px; color: #d0d3dd; }
.cfg-help-link {
  margin-top: 4px;
  width: fit-content;
  border: 1px solid #ff9f0a;
  background: transparent;
  color: #ff9f0a;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 15px;
}
.cfg-item-first {
  margin-top: 12px;
}
.cfg-item {
  margin-top: 12px;
}
.config-card input {
  height: 46px;
  border-radius: 10px;
  border: 1px solid #3a3d45;
  background: #0d0e12;
  color: #fff;
  font-size: 18px;
  padding: 0 12px;
}
.sheet-grabber {
  width: 36px;
  height: 5px;
  border-radius: 99px;
  background: #666b77;
  margin: 2px auto 0;
}
.switch-row {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
}
.switch {
  position: relative;
  width: 52px;
  height: 32px;
  display: inline-flex;
}
.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
}
.switch .slider {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #3a3d45;
  transition: background .2s ease;
  position: relative;
}
.switch .slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s ease;
}
.switch input:checked + .slider {
  background: #34c759;
}
.switch input:checked + .slider::before {
  transform: translateX(20px);
}
.cfg-btn {
  width: 100%;
  border: none; border-radius: 12px; height: 50px; padding: 0 16px;
  background: #343843; color: #fff;
  font-size: 18px;
}
.cfg-save-btn {
  margin-top: 12px;
}
.cfg-btn-primary { background: #ff9f0a; }
.cfg-btn-primary:disabled {
  background: #4c4f57;
  color: #b8bbc4;
  cursor: default;
}
.cfg-btn-outline {
  margin-top: 12px;
  width: 100%;
  height: 50px;
  border-radius: 12px;
  border: 1px solid #3a3d45;
  background: transparent;
  color: #d8dbe6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 17px;
}
.cfg-btn-outline .icon-share {
  width: 20px;
  height: 20px;
}

.help-card .sheet-body {
  padding-bottom: max(40px, calc(env(safe-area-inset-bottom) + 40px));
}
.help-content {
  display: grid;
  gap: 16px;
  color: #d6d9e4;
  font-size: 16px;
  line-height: 1.5;
}
.help-item {
  display: grid;
  gap: 10px;
}
.help-item h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  color: #f4f5fa;
}
.help-item p {
  margin: 0;
}
.help-item-emphasis h3 {
  color: #ff9f0a;
}
.help-footer {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid #2b2f3a;
}
.help-footer p {
  color: #bfc3cf;
}
.help-footer a {
  color: #dfe3ee;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.help-content code {
  background: #232733;
  border-radius: 6px;
  padding: 2px 6px;
  color: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  top: max(12px, calc(env(safe-area-inset-top) + 8px)) !important;
  bottom: auto !important;
  transform: translateX(-50%) translateY(-26px);
  background: rgba(28, 29, 34, 0.95);
  border: 1px solid #3a3e49;
  color: #fff;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 50;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 390px) {
  .phone { padding-inline: 10px; }
  .keys { gap: 9px; }
  .display { font-size: clamp(44px, 14vw, 90px); }
  .expr { font-size: clamp(22px, 5.2vw, 40px); }
  .help-content { font-size: 15px; }
  .help-item h3 { font-size: 17px; }
  .toast {
    max-width: calc(100vw - 24px);
    white-space: normal;
    text-align: center;
  }
}
