*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Space Grotesk', sans-serif;
  background: #0c1118;
  color: #e2eaf3;
  height: 100vh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.018);
  flex-shrink: 0;
  flex-wrap: wrap;
  overflow: hidden;
}

.hdr-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #f0f6ff;
  letter-spacing: 0.015em;
  white-space: nowrap;
}

.hdr-sub {
  font-size: 0.72rem;
  color: #4a6a88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Space Mono', monospace;
}

/* ── Category row ── */
.category-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.4rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
  background: rgba(255,255,255,0.012);
}

.cat-label {
  font-size: 0.75rem;
  color: #4a6a88;
  white-space: nowrap;
}

.category-sel {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.88rem;
  font-weight: 500;
  color: #c8dff5;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 0.3rem 1.8rem 0.3rem 0.65rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%234a6a88'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  transition: background-color 0.12s, border-color 0.12s;
}

.category-sel:hover {
  background-color: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.22);
}

.category-sel:focus {
  border-color: rgba(56,185,245,0.45);
}

/* ── Calculator row ── */
.calc-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.calc-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
  max-width: 380px;
}

.right-block {
  align-items: flex-end;
}

.amount-input {
  font-family: 'Space Mono', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: #38b9f5;
  background: transparent;
  border: none;
  border-bottom: 2px solid rgba(56,185,245,0.35);
  padding: 0 0 0.1rem;
  width: 100%;
  outline: none;
  -moz-appearance: textfield;
}
.amount-input::-webkit-inner-spin-button,
.amount-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.amount-input:focus { border-bottom-color: rgba(56,185,245,0.75); }

.result-val {
  font-family: 'Space Mono', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: #f5a623;
  padding: 0 0 0.1rem;
  border-bottom: 2px solid rgba(245,166,35,0.35);
  min-height: 2.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

/* ── Unit selects ── */
.unit-selects {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}

.right-unit-selects {
  justify-content: flex-end;
}

.prefix-sel,
.base-sel {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  color: #b8d4ec;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 0.28rem 1.4rem 0.28rem 0.55rem;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%234a6a88'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  transition: background-color 0.12s, border-color 0.12s;
  min-width: 0;
}

.prefix-sel:hover,
.base-sel:hover {
  background-color: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.2);
}

.prefix-sel:focus,
.base-sel:focus {
  border-color: rgba(255,255,255,0.25);
}

.prefix-sel {
  width: 6rem;
  flex-shrink: 0;
}

.base-sel {
  flex: 1;
}

.prefix-sel:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Calculate button ── */
.calc-btn {
  background: linear-gradient(135deg, #1a5f8a, #2083b8);
  border: 1px solid rgba(56,185,245,0.45);
  border-radius: 7px;
  color: #d8efff;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.32rem 1rem;
  cursor: pointer;
  flex-shrink: 0;
  letter-spacing: 0.03em;
  transition: all 0.12s;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

.calc-btn:hover {
  background: linear-gradient(135deg, #1e6fa0, #2596ce);
  border-color: rgba(56,185,245,0.7);
  box-shadow: 0 2px 14px rgba(56,185,245,0.22);
}

.calc-btn:active {
  transform: scale(0.97);
  box-shadow: none;
}

/* ── Equation column ── */
.eq-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
  min-width: 72px;
}

.eq-sign {
  font-size: 1.8rem;
  font-weight: 300;
  color: #3a5a78;
  line-height: 1;
}

.unit-ratio {
  font-size: 0.62rem;
  color: #3a5a78;
  text-align: center;
  font-family: 'Space Mono', monospace;
  line-height: 1.3;
  white-space: nowrap;
}

.swap-btn {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 5px;
  color: #4a6a88;
  font-size: 0.9rem;
  padding: 0.22rem 0.5rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.12s;
  margin-top: 0.1rem;
}
.swap-btn:hover {
  background: rgba(255,255,255,0.09);
  color: #a8c8e8;
}

/* ── Kwiki button ── */
.kwiki-btn {
  margin-left: auto;
  background: rgba(56,185,245,0.08);
  border: 1px solid rgba(56,185,245,0.22);
  border-radius: 6px;
  color: #4a9ec8;
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.22rem 0.65rem;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all 0.12s;
  flex-shrink: 0;
}
.kwiki-btn:hover {
  background: rgba(56,185,245,0.16);
  border-color: rgba(56,185,245,0.5);
  color: #7dd3f5;
}

/* ── Kwiki overlay ── */
.kwiki-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.kwiki-overlay.open {
  display: flex;
}

.kwiki-panel {
  background: #0f1822;
  border: 1px solid rgba(56,185,245,0.18);
  border-radius: 12px;
  width: min(700px, 96vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 48px rgba(0,0,0,0.7);
  overflow: hidden;
}

.kwiki-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}
.kwiki-title {
  font-size: 1rem;
  font-weight: 700;
  color: #c8e8ff;
  font-family: 'Space Mono', monospace;
}
.kwiki-close {
  background: none;
  border: none;
  color: #4a6a88;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color 0.12s;
}
.kwiki-close:hover { color: #a0c8e8; }

.kwiki-body {
  overflow-y: auto;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.kwiki-section { display: flex; flex-direction: column; gap: 0.55rem; }

.kwiki-h2 {
  font-size: 0.82rem;
  font-weight: 700;
  color: #38b9f5;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.kwiki-badge {
  background: rgba(56,185,245,0.18);
  color: #38b9f5;
  font-size: 0.65rem;
  font-family: 'Space Mono', monospace;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  letter-spacing: 0.06em;
  text-transform: lowercase;
}

.kwiki-p {
  font-size: 0.82rem;
  color: #8aaccc;
  line-height: 1.55;
}

.kwiki-code {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: #a8d8f5;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  padding: 0.55rem 0.8rem;
  word-break: break-all;
}
.kwiki-code em {
  color: #f5a623;
  font-style: normal;
}

.kwiki-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.kwiki-table th {
  color: #4a6a88;
  font-weight: 600;
  text-align: left;
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kwiki-table td {
  color: #9abcd4;
  padding: 0.32rem 0.6rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: top;
}
.kwiki-table td code {
  font-family: 'Space Mono', monospace;
  font-size: 0.73rem;
  color: #c8e8ff;
}

.kwiki-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.kwiki-chip {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: #7ab8d4;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 5px;
  padding: 0.22rem 0.5rem;
}

.kwiki-examples {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.kwiki-link {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: #38b9f5;
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.12s;
}
.kwiki-link:hover { opacity: 1; text-decoration: underline; }
