/* Calculator — dark, glassy, keyboard friendly. */

:root {
  --bg: #070b16;
  --bg-2: #101a33;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.085);
  --stroke: rgba(255, 255, 255, 0.09);
  --text: #f2f5fb;
  --muted: #97a3ba;
  --accent: #ffb03a;
  --accent-soft: rgba(255, 176, 58, 0.16);
  --blue: #4f8cff;
  --blue-2: #7a5cff;
  --danger: #ff6b81;
  --radius: 16px;
  --key-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  padding: 28px 20px 40px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 620px at 12% -8%, #1b2c57 0%, transparent 62%),
    radial-gradient(900px 560px at 108% 8%, #2a1c4d 0%, transparent 60%),
    linear-gradient(170deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

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

.app {
  width: 100%;
  max-width: 860px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

.calculator {
  width: 100%;
  max-width: 420px;
  padding: 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.028));
  border: 1px solid var(--stroke);
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
}

.calculator__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 4px 14px;
}

.calculator__title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.ghost {
  appearance: none;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ghost:hover { background: rgba(255, 255, 255, 0.09); color: var(--text); }
.ghost:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.ghost__count {
  min-width: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

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

.display {
  position: relative;
  min-height: 128px;
  padding: 12px 16px 14px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.22));
  border: 1px solid var(--stroke);
  box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}

.display__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  margin-bottom: 2px;
}

.display__mem {
  flex: none;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.display__expr {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 18px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  font-variant-numeric: tabular-nums;
}

.display__expr::-webkit-scrollbar { display: none; }

.display__value {
  display: block;
  font-size: 44px;
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: right;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease;
}

.display__value::-webkit-scrollbar { display: none; }

.display__value.is-error {
  color: var(--danger);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0;
  white-space: normal;
  overflow: visible;
}

.display__preview {
  min-height: 20px;
  margin-top: 2px;
  font-size: 14px;
  line-height: 20px;
  color: var(--blue);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ keys */

.keys {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
}

.key {
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  height: var(--key-h);
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.05));
  color: var(--text);
  font: inherit;
  font-size: 20px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
  transition: transform 0.07s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.key:hover { background: linear-gradient(180deg, rgba(255, 255, 255, 0.17), rgba(255, 255, 255, 0.08)); }
.key:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.key:active, .key.is-flash { transform: scale(0.955); }

.key--fn {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.022));
}

.key--fn:hover { color: var(--text); }

.key--clear {
  font-size: 16px;
  font-weight: 700;
  color: #ffd0d7;
  background: linear-gradient(180deg, rgba(255, 107, 129, 0.24), rgba(255, 107, 129, 0.1));
  border-color: rgba(255, 107, 129, 0.28);
}

.key--op {
  color: var(--accent);
  font-size: 23px;
  background: linear-gradient(180deg, rgba(255, 176, 58, 0.2), rgba(255, 176, 58, 0.08));
  border-color: rgba(255, 176, 58, 0.26);
}

.key--op:hover { background: linear-gradient(180deg, rgba(255, 176, 58, 0.3), rgba(255, 176, 58, 0.14)); }

/* the operator that is waiting for its right-hand operand */
.key--op.is-armed {
  background: linear-gradient(180deg, rgba(255, 176, 58, 0.42), rgba(255, 176, 58, 0.22));
  border-color: rgba(255, 176, 58, 0.6);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 176, 58, 0.35), 0 8px 22px -10px rgba(255, 176, 58, 0.8);
}

.key--equals {
  grid-column: span 2;
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 12px 26px -12px rgba(79, 140, 255, 0.9);
}

.key--equals:hover { filter: brightness(1.08); }

/* ------------------------------------------------------------------ hint */

.hint {
  margin: 14px 4px 0;
  font-size: 11px;
  line-height: 2;
  color: #6f7c93;
  text-align: center;
}

.hint kbd {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 5px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  font: inherit;
  font-size: 10px;
  color: #93a0b6;
}

/* --------------------------------------------------------------- history */

.history {
  width: 100%;
  max-width: 400px;
  max-height: 560px;
  padding: 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.025));
  border: 1px solid var(--stroke);
  box-shadow: 0 30px 70px -34px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.history[hidden] { display: none; }

.history__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.history__title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history__list::-webkit-scrollbar { width: 6px; }
.history__list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 3px; }

.history__item {
  width: 100%;
  appearance: none;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  font: inherit;
  padding: 9px 12px;
  text-align: right;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.history__item:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--stroke); }
.history__item:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

.history__expr {
  display: block;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.history__result {
  display: block;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history__empty {
  margin: 6px 2px 2px;
  font-size: 12px;
  color: #6f7c93;
  text-align: center;
}

.history__empty[hidden] { display: none; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 719px) {
  body { padding: 16px 12px 28px; }
  .calculator { max-width: 460px; }
  .history { max-width: 460px; max-height: 320px; }
  :root { --key-h: 52px; }
  .display__value { font-size: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .key:active, .key.is-flash { transform: none; }
}
