@font-face {
  font-family: "AMBILE";
  src: url("assets/fonts/AMBILE.ttf") format("truetype");
}

:root {
  --bg: #0b0e1a;
  --bg2: radial-gradient(
      1200px 800px at 20% -10%,
      rgba(124, 156, 255, 0.22),
      transparent 60%
    ),
    radial-gradient(
      800px 600px at 120% 20%,
      rgba(142, 240, 209, 0.14),
      transparent 50%
    ),
    linear-gradient(180deg, #0b0e1a, #0e1224 60%, #0b0e1a);
  --card: rgba(255, 255, 255, 0.08);
  --text: #f7f8ff;
  --muted: #a9afc3;
  --accent: #7c9cff;
  --accent-2: #8ef0d1;
  --border: rgba(255, 255, 255, 0.18);
  --btn: #141a34;
  --btn-hover: #1a2140;
  --danger: #ff6b6b;
  --good: #43d39e;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --radius: 20px;
  --ring: 0 0 0 3px rgba(124, 156, 255, 0.25);
}
.light {
  --bg: #e9edf6;
  --bg2: radial-gradient(
      1200px 800px at 10% -10%,
      rgba(124, 156, 255, 0.18),
      transparent 60%
    ),
    radial-gradient(
      800px 600px at 120% 20%,
      rgba(142, 240, 209, 0.12),
      transparent 50%
    ),
    linear-gradient(180deg, #e9edf6, #eef1f7);
  --card: rgba(255, 255, 255, 0.92);
  --text: #0f1325;
  --muted: #4b5162;
  --btn: #ffffff;
  --btn-hover: #f3f6fb;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: 0 14px 32px rgba(10, 15, 30, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.75);
  --ring: 0 0 0 3px rgba(124, 156, 255, 0.3);
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: "AMBILE", "Noto Naskh Arabic", Arial, sans-serif;
  background: var(--bg2);
  color: var(--text);
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
  transition: background 0.4s ease, color 0.2s ease;
}

button {
  font-family: inherit;
}
.app {
  width: min(1000px, 96vw);
  display: grid;
  grid-template-columns: 1.25fr 0.9fr;
  gap: 20px;
  animation: fadeUp 0.6s ease both;
}
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
  }
}

.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  overflow: clip;
}
/* Luxe gradient border */
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: calc(var(--radius) + 1px);
  padding: 1px;
  background: linear-gradient(
    135deg,
    rgba(124, 156, 255, 0.55),
    rgba(142, 240, 209, 0.4),
    rgba(124, 156, 255, 0.35)
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.panel {
  padding: 20px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.4px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.title img {
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.25));
}
.title span {
  background: linear-gradient(90deg, #fff, #cfe2ff 40%, #d5fff1);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.light .title span {
  background: linear-gradient(90deg, #0f1325, #3b4a9e 40%, #2e7d6d);
   -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cluster {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
button.toggle {
  background: var(--btn);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 9px 13px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.06s ease, background 0.2s ease, box-shadow 0.2s ease;
}
button.toggle:hover {
  background: var(--btn-hover);
  transform: translateY(-1px);
}
button.toggle:active {
  transform: translateY(0);
}
button.toggle:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Display */
.display {
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.07),
    rgba(255, 255, 255, 0.03)
  );
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02),
    inset 0 -60px 80px rgba(124, 156, 255, 0.05);
}
.display::after {
  content: "";
  position: absolute;
  inset: auto 12px 10px 12px;
  height: 2px;
  border-radius: 999px;
  background: radial-gradient(
    80% 220% at 50% 50%,
    rgba(124, 156, 255, 0.45),
    rgba(142, 240, 209, 0.15),
    transparent 70%
  );
  pointer-events: none;
}
.exp {
  font-size: 15px;
  color: var(--muted);
  word-break: break-all;
  min-height: 20px;
  text-align: right;
}
.out {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.3px;
  text-align: right;
  direction: ltr;
  unicode-bidi: plaintext;
  font-variant-numeric: tabular-nums;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tags {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.tag {
  font-size: 12px;
  color: var(--muted);
  border: 1px dashed var(--border);
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}

/* Keypad */
.keys {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.key {
  position: relative;
  background: var(--btn);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 16px 10px;
  font-size: 19px;
  border-radius: 16px;
  cursor: pointer;
  user-select: none;
  text-align: center;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: transform 0.05s ease, box-shadow 0.15s ease, background 0.2s ease,
    filter 0.2s ease;
  overflow: hidden;
}
.key:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.key:active {
  transform: translateY(0);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  filter: saturate(1.15);
}
.key.op {
  background: linear-gradient(180deg, #2a315a, #1b203a);
}
.key.eq {
  background: linear-gradient(180deg, var(--accent), #5a7df8);
  color: #0c1230;
  font-weight: 900;
  letter-spacing: 0.3px;
}
.key.fn {
  background: linear-gradient(180deg, #24314a, #1b253b);
}
.key.danger {
  background: linear-gradient(180deg, #7a2323, #5a1717);
}
.light .key.fn,
.light .key.danger,
.light .key.op {
  color: #ffffff;
}
.key.wide {
  grid-column: span 2;
}

/* History */
.history {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.history .head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.history .list {
  padding: 10px 14px 18px;
  max-height: 540px;
  overflow: auto;
}
.item {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-top: 12px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.item .e {
  font-size: 13px;
  color: var(--muted);
  direction: ltr;
  unicode-bidi: plaintext;
}
.item .r {
  font-weight: 900;
  margin-top: 6px;
  font-size: 17px;
  direction: ltr;
  unicode-bidi: plaintext;
}
.pill {
  font-size: 12px;
  background: linear-gradient(
    180deg,
    rgba(142, 240, 209, 0.25),
    rgba(142, 240, 209, 0.12)
  );
  color: var(--accent-2);
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 999px;
}

.footer {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  gap: 10px;
  flex-wrap: wrap;
}
.kbd {
  border: 1px solid var(--border);
  padding: 3px 7px;
  border-radius: 7px;
  background: var(--card);
}

/* Animations */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
