* {
  box-sizing: border-box;
}

:root {
  --kvibe-surface: #191b24;
  --kvibe-grid-dot: rgba(50, 52, 62, 0.45);
  --accent: #c8ff00;
  --accent-dim: #9bcc12;
  --purple: #8f79c9;
  --card: #0b0a39;
  --card-hi: #2a2e3f;
  --text: #e8eaf0;
  --muted: #9a9db0;
  --danger: #ff6b81;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'SN Pro', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background-color: var(--kvibe-surface);
  background-image: radial-gradient(
    var(--kvibe-grid-dot) 1px,
    var(--kvibe-surface) 1px
  );
  background-size: 20px 20px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

/* ===== Калькулятор ===== */

.calc {
  width: min(23rem, 100%);
  background: var(--card);
  border: 1px solid #33374a;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes pop {
  from {
    transform: translateY(18px) scale(0.96);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.calc__bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 0.9rem;
  background: #1b1e2a;
  border-bottom: 1px solid #33374a;
}

.calc__dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.calc__dot--r { background: #ff5f57; }
.calc__dot--y { background: #febc2e; }
.calc__dot--g { background: #28c840; }

.calc__name {
  margin-left: auto;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.calc__sound {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  opacity: 0.85;
  transition: transform 0.15s;
}

.calc__sound:hover {
  transform: scale(1.15);
}

.calc__sound.is-off {
  filter: grayscale(1);
  opacity: 0.45;
}

/* ===== Экран ===== */

.display {
  padding: 1.4rem 1.2rem 1rem;
  text-align: right;
  background: linear-gradient(180deg, #1d2030, #212431);
}

.display__expr {
  min-height: 1.2rem;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.9rem;
  color: var(--purple);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.display__value {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-weight: 600;
  font-size: clamp(2rem, 9vw, 2.9rem);
  line-height: 1.15;
  color: var(--accent);
  word-break: break-all;
  transition: transform 0.12s;
}

.display__value.bump {
  animation: bump 0.18s ease-out;
}

@keyframes bump {
  50% { transform: scale(1.05); }
}

.display__value.is-error {
  color: var(--danger);
  font-size: 1.6rem;
}

/* ===== Кнопки ===== */

.pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
  padding: 0.9rem;
}

.btn {
  padding: 0;
  aspect-ratio: 1 / 1;
  border: 1px solid #363b50;
  border-radius: 14px;
  background: var(--card-hi);
  color: var(--text);
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 1.35rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, box-shadow 0.15s;
}

.btn:hover {
  background: #333850;
  box-shadow: 0 0 0 2px rgba(200, 255, 0, 0.25);
}

.btn:active,
.btn.is-pressed {
  transform: scale(0.92);
}

.btn--fn {
  background: #2b2f43;
  color: var(--muted);
  font-size: 1.15rem;
}

.btn--op {
  background: rgba(143, 121, 201, 0.22);
  color: #cdbcf5;
}

.btn--op.is-active {
  background: var(--purple);
  color: #161426;
}

.btn--neg {
  background: #2b2f43;
  color: var(--muted);
  font-size: 1.1rem;
}

.btn--eq {
  background: var(--accent);
  border-color: var(--accent);
  color: #171a10;
}

.btn--eq:hover {
  background: var(--accent-dim);
  box-shadow: 0 0 0 2px rgba(200, 255, 0, 0.4);
}

/* ===== История ===== */

.history {
  width: min(17rem, 100%);
  background: var(--card);
  border: 1px solid #33374a;
  border-radius: 22px;
  padding: 1.1rem 1.1rem 1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.history__title {
  margin: 0 0 0.7rem;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 15rem;
  overflow-y: auto;
}

.history__list li {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.82rem;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  background: #1d2030;
  cursor: pointer;
  transition: background 0.15s;
  animation: slideIn 0.25s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(-10px);
    opacity: 0;
  }
}

.history__list li:hover {
  background: #262a3d;
}

.history__list .history__eq {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.history__list .history__res {
  color: var(--accent);
  font-weight: 600;
}

.history__empty {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  background: none !important;
  cursor: default !important;
}

.history__empty:hover {
  background: none !important;
}

.history__clear {
  margin-top: 0.8rem;
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #363b50;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.history__clear:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ===== Графики ===== */

.graph {
  flex: 1 1 100%;
  width: min(52rem, 100%);
  background: var(--card);
  border: 1px solid #33374a;
  border-radius: 22px;
  padding: 1.1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.graph__head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.7rem;
}

.graph__title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.graph__mode {
  margin-left: auto;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.74rem;
  color: #00f5d4;
  background: #0e1118;
  border: 1px solid #2a2e3f;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}

.graph__deriv {
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--purple);
  border-radius: 999px;
  background: rgba(143, 121, 201, 0.22);
  color: #cdbcf5;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.graph__deriv:hover {
  background: var(--purple);
  color: #161426;
}

.graph__deriv:active {
  transform: scale(0.94);
}

.graph__row {
  display: flex;
  gap: 0.5rem;
}

.graph__input {
  flex: 1;
  min-width: 0;
  background: #0b0d13;
  border: 1px solid #33374a;
  border-radius: 12px;
  color: var(--accent);
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
}

.graph__input:focus {
  border-color: var(--accent);
}

.graph__build {
  padding: 0 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--accent);
  color: #171a10;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.graph__build:hover {
  background: var(--accent-dim);
}

.graph__build:active {
  transform: scale(0.95);
}

.graph__keys {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.6rem 0 0.7rem;
}

.kbtn {
  min-width: 2.3rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid #363b50;
  border-radius: 9px;
  background: var(--card-hi);
  color: var(--text);
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.08s;
}

.kbtn:hover {
  background: #333850;
  box-shadow: 0 0 0 2px rgba(200, 255, 0, 0.25);
}

.kbtn:active {
  transform: scale(0.9);
}

.graph__canvas {
  display: block;
  width: 100%;
  height: min(54vh, 430px);
  min-height: 260px;
  background: #000;
  border: 1px solid #2a2e3f;
  border-radius: 14px;
  cursor: crosshair;
  touch-action: none;
}

.graph__status {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.4rem;
}

.graph__coord {
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.graph__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.75rem;
  background: #1d2030;
  border: 1px solid #2a2e3f;
  padding: 0.3rem 0.6rem;
  border-radius: 9px;
  color: #cfd2e0;
}

.legend__sw {
  width: 16px;
  height: 4px;
  border-radius: 2px;
}

.legend__d {
  color: var(--purple);
  font-size: 0.7rem;
}

.legend__empty {
  color: var(--muted);
}

.graph__err {
  min-height: 1rem;
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--danger);
}

.graph__hint {
  margin: 0.35rem 0 0;
  font-size: 0.73rem;
  line-height: 1.55;
  color: var(--muted);
}

.graph__hint b {
  color: var(--accent);
}

/* ===== Об авторе ===== */

.about-fab {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  padding: 0.7rem 1.15rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #171a10;
  font-family: 'SN Pro', system-ui, sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(200, 255, 0, 0.25);
  transition: transform 0.12s, background 0.15s;
}

.about-fab:hover {
  background: var(--accent-dim);
  transform: translateY(-2px);
}

.about-fab:active {
  transform: scale(0.95);
}

.about {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.about[hidden] {
  display: none;
}

.about__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
}

.about__card {
  position: relative;
  width: min(24rem, 100%);
  background: var(--card);
  border: 1px solid #3c415a;
  border-radius: 22px;
  padding: 1.7rem 1.4rem 1.5rem;
  text-align: center;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
  animation: pop 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.about__close {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  width: 2rem;
  height: 2rem;
  border: 1px solid #3c415a;
  border-radius: 50%;
  background: #1d2030;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.1s;
}

.about__close:hover {
  color: #fff;
  border-color: var(--danger);
  transform: rotate(90deg);
}

.about__avatar {
  font-size: 3.2rem;
  line-height: 1;
}

.about__title {
  margin: 0.55rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
}

.about__name {
  margin: 0.2rem 0;
  font-size: 1rem;
}

.about__name b {
  color: #cdbcf5;
}

.about__text {
  margin: 0.75rem 0;
  font-size: 0.86rem;
  line-height: 1.65;
  color: var(--muted);
}

.about__text em {
  color: var(--accent);
  font-style: normal;
}

.about__stack {
  display: inline-block;
  margin: 0;
  padding: 0.32rem 0.65rem;
  border: 1px solid #3c415a;
  border-radius: 999px;
  background: rgba(143, 121, 201, 0.18);
  color: #cdbcf5;
  font-family: 'JetBrains Mono', Menlo, monospace;
  font-size: 0.72rem;
}

@media (max-width: 680px) {
  .app {
    padding: 1rem 0.75rem;
  }
  .history {
    width: min(23rem, 100%);
  }
}
