:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e6e9f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #6366f1;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px rgba(15, 23, 42, .07);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ----- Header ------------------------------------------------------------ */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.app-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  font-size: 18px;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  box-shadow: 0 8px 18px rgba(99, 102, 241, .30);
}

.app-titles h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-titles p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}

.btn-ghost {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.btn-ghost:hover {
  background: #f8fafc;
  border-color: #d5dae6;
}

.btn:active {
  transform: translateY(1px);
}

/* ----- Layout ------------------------------------------------------------ */

.content {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.card-body {
  padding: 20px 22px;
}

/* ----- Inputs ------------------------------------------------------------ */

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  background: #fbfcff;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}

/* ----- Operands ---------------------------------------------------------- */

.operands {
  display: flex;
  flex-wrap: wrap;
  gap: 26px;
  margin-bottom: 18px;
}

.operand {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.operand-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.tex-box {
  min-width: 60px;
  font-size: 1.05rem;
}

/* ----- Result tables ----------------------------------------------------- */

.ops {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.ops th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0 8px;
  border-bottom: 1px solid var(--border);
}

.ops td {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.ops tr:last-child td {
  border-bottom: 0;
  padding-bottom: 0;
}

.ops td:first-child {
  width: 34%;
  color: var(--muted);
}

.value,
.tex-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  word-break: break-word;
}

.value {
  font-weight: 600;
}

/* ----- Displayed result -------------------------------------------------- */

.result {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  margin-top: 4px;
  padding: 20px;
  overflow-x: auto;
  background: #fbfcff;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.tex-display {
  font-size: 1.4rem;
}

/* ----- Responsive -------------------------------------------------------- */

@media (max-width: 640px) {
  .app-header {
    padding: 14px 16px;
  }

  .app-titles p {
    display: none;
  }

  .content {
    padding: 16px;
    gap: 16px;
  }

  .card-body {
    padding: 16px;
  }

  .tex-display {
    font-size: 1.15rem;
  }
}
