/* Plain, corporate look: dark surfaces with a cyan accent, no gradients or
   animation. Always dark, whatever the phone's setting. */

:root {
  --bg: #0b0f14;
  --surface: #121821;
  --key: #161d27;
  --key-fn: #1e2733;
  --key-op: #0f2a33;
  --text: #e6edf3;
  --muted: #8b98a8;
  --faint: #5b6776;
  --border: #243040;
  --accent: #22d3ee;
  --on-accent: #062a33;
  --op-text: #22d3ee;
  --danger: #f87171;
  --ok: #34d399;
  --warn: #fbbf24;
  --press: rgba(255, 255, 255, 0.08);
  --scrim: rgba(0, 0, 0, 0.55);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { overflow: hidden; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */

.app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 12px calc(env(safe-area-inset-bottom) + 12px);
}

.topbar {
  flex: none;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.icon-btn:active { background: var(--press); }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn.small svg { width: 18px; height: 18px; }

/* ---------- display ---------- */

.display {
  flex: 1 1 0;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 4px 6px 12px;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.expr {
  flex: 0 1 auto;
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  resize: none;
  overflow-y: auto;
  scrollbar-width: none;
  background: transparent;
  color: var(--text);
  caret-color: var(--accent);
  font-family: inherit;
  font-size: var(--expr-size, 44px);
  font-weight: 400;
  line-height: 1.25;
  text-align: right;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.expr::-webkit-scrollbar { display: none; }
.expr::selection { background: rgba(34, 211, 238, 0.28); }
.expr.done { color: var(--muted); }

.result {
  flex: none;
  min-height: 1.25em;
  text-align: right;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  font-size: var(--result-size, 52px);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.result::-webkit-scrollbar { display: none; }
.result.preview { --result-size: 28px; font-weight: 400; color: var(--muted); }
.result .u { font-size: 0.6em; margin: 0 0.3em 0 0.03em; color: var(--muted); }
.result .u:last-child { margin-right: 0; }

.hint { flex: none; min-height: 18px; margin-top: 2px; text-align: right; font-size: 13px; color: var(--danger); visibility: hidden; }
.hint.show { visibility: visible; }

/* ---------- keypad ---------- */

.keypad {
  flex: 0 1 min(56vh, 480px);
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: 8px;
  padding-top: 12px;
}

/* keys fill their cell with fully rounded ends (pill shape); text scales with the key (--key) */
.key {
  min-height: 0;
  border-radius: 999px;
  background: var(--key);
  border: 1px solid var(--border);
  font-size: calc(var(--key, 64px) * 0.36);
  font-weight: 400;
  line-height: 1;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.key:active, .key.pressed { box-shadow: inset 0 0 0 999px var(--press); }
.key.fn { background: var(--key-fn); font-size: calc(var(--key, 64px) * 0.32); }
.key.fn svg { width: calc(var(--key, 64px) * 0.38); height: calc(var(--key, 64px) * 0.38); }
.key.clear { color: var(--danger); font-weight: 500; }
.key.op { background: var(--key-op); color: var(--op-text); font-size: calc(var(--key, 64px) * 0.4); font-weight: 500; border-color: transparent; }
.key.eq { background: var(--accent); color: var(--on-accent); font-size: calc(var(--key, 64px) * 0.42); font-weight: 500; border-color: transparent; }
.key.unit small { margin-top: 3px; font-size: max(10px, calc(var(--key, 64px) * 0.17)); color: var(--muted); }
.key.zero { grid-column: span 2; }

@media (max-height: 640px) {
  .keypad { gap: 6px; padding-top: 8px; }
  .display { min-height: 120px; }
}

/* ---------- sheets ---------- */

.scrim { position: fixed; inset: 0; z-index: 10; background: var(--scrim); }

.sheet {
  position: fixed;
  z-index: 11;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px);
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.12);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.sheet-actions { display: flex; align-items: center; gap: 6px; }
.sync-label { font-size: 12px; color: var(--muted); margin-right: 4px; }
.text-btn { padding: 8px 10px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.text-btn.danger { color: var(--danger); }
.text-btn:active { background: var(--press); }

/* history */
.confirm-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 8px;
  padding: 8px 8px 8px 12px;
  border-radius: 12px;
  background: var(--key-fn);
  font-size: 14px;
}
.confirm-bar span { flex: 1; color: var(--text); }
.history-list { overflow-y: auto; margin: 0 -16px; }
.history-day { padding: 14px 16px 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.history-item:active { background: var(--press); }
.h-main { min-width: 0; text-align: right; }
.h-expr { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-result { font-size: 20px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.h-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.h-time { font-size: 11px; color: var(--faint); }
.h-del { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--faint); }
.h-del svg { width: 16px; height: 16px; }
.h-del:active { background: var(--press); color: var(--danger); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.history-note { padding: 14px 16px 6px; border-top: 1px solid var(--border); text-align: center; font-size: 12px; color: var(--faint); }

/* settings */
.settings-body { overflow-y: auto; }
.group { padding: 8px 0 12px; border-top: 1px solid var(--border); }
.group:first-child { border-top: 0; }
.group h3 { margin: 6px 0 10px; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 15px; cursor: pointer; }
.switch-row small { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.about { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.about dt { color: var(--muted); }
.about dd { margin: 0; color: var(--text); word-break: break-word; }
.sync-body { font-size: 15px; line-height: 1.5; color: var(--muted); }
.sync-body p { margin: 0 0 12px; }
.sync-body strong { color: var(--text); font-weight: 500; }
.account { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.account img, .account .avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--key-fn); display: grid; place-items: center; font-weight: 600; color: var(--text); }
.account .who { min-width: 0; }
.account .who div { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.account .who span { font-size: 13px; }
.sync-line { display: flex; align-items: center; gap: 8px; color: var(--text); }
.sync-line .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.sync-line.synced .dot { background: var(--ok); }
.sync-line.pending .dot, .sync-line.offline .dot { background: var(--warn); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.btn {
  width: 100%;
  height: 44px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.btn:active { box-shadow: inset 0 0 0 999px var(--press); }
.btn.google svg { width: 18px; height: 18px; stroke: none; }
.account-id {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 12px;
  color: var(--muted);
  text-align: left;
}
.account-id code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.account-id span { color: var(--accent); font-weight: 500; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  background: #1e2733;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  display: none;
}
.toast.show { display: block; }
.toast.actionable.show { display: flex; align-items: center; gap: 14px; }
.toast-action { font-weight: 600; color: var(--accent); }
