/* ==============
   Design tokens
   ============== */
:root {
  --bg: #0b1220; /* page background */
  --panel: #0e172a; /* card/box background */
  --ink: #e5e7eb; /* primary text */
  --muted: #9aa5b1; /* secondary text */
  --line: #223248; /* borders */
  --brand: #2dd4bf; /* accent 1 */
  --brand-2: #38bdf8; /* accent 2 */
  --danger: #ef4444; /* danger */
  --shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
}

/* Reset-ish */
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, Segoe UI, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Global (page/document) scrollbars */
html {
  scrollbar-gutter: stable both-edges;
}
html::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}
html::-webkit-scrollbar-track {
  background: transparent;
}
html::-webkit-scrollbar-thumb {
  background-color: #22324a;
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: content-box;
}
html::-webkit-scrollbar-thumb:hover {
  background-color: #2e4362;
}
html {
  scrollbar-width: thin;
  scrollbar-color: #22324a transparent;
}

/* ============
   App wrapper
   ============ */
.wrap {
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.header {
  text-align: center;
}
.header h1 {
  margin: 0 0 6px;
  font-size: clamp(22px, 5.6vw, 34px);
  font-weight: 800;
  letter-spacing: 0.2px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.header p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(13px, 3.6vw, 16px);
}

/* =========
   Cards/boxes
   ========= */
.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.label {
  font-weight: 700;
  font-size: clamp(13px, 3.8vw, 16px);
  color: var(--ink);
  flex: 0 0 auto;
}

/* Tools row (buttons wrap neatly on mobile) */
.tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  width: 100%;
}
@media (min-width: 520px) {
  .tools {
    width: auto;
  }
}

/* Generic box surface */
.box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* Scrollable areas: contained height with inner scrollbar */
.scrollable {
  height: clamp(220px, 40vh, 320px);
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  -webkit-overflow-scrolling: touch; /* iOS momentum */
}

/* Inputs/outputs text areas */
#json-input,
.pre {
  padding: 12px 14px;
  line-height: 1.55;
  color: var(--ink);
  font-family: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas,
    "Liberation Mono", monospace;
  font-size: clamp(12px, 3.6vw, 14px);
}
#json-input {
  resize: none;
}
.pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* Row info below inputs (size, chars, lines, source) */
.row-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  min-height: 1lh;
}
.truncate {
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}
@media (min-width: 768px) {
  .truncate {
    max-width: 50%;
  }
}

/* =======
   Buttons
   ======= */
.actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
  margin-bottom: 6px;
}

/* Base button */
.btn,
.cta {
  background: #101a2f;
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background 0.2s, border-color 0.2s, transform 0.06s ease-out,
    box-shadow 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(13px, 4vw, 14px);
  line-height: 1;
}
.btn:active,
.cta:active {
  transform: scale(0.985);
}
.btn:hover {
  background: #18243b;
}

.btn.primary {
  border-color: #0f766e;
  color: #99f6e4;
}
.btn.primary:hover {
  background: #0f2630;
}

.btn.danger {
  border-color: #7f1d1d;
  color: #fecaca;
}
.btn.danger:hover {
  background: #3f1212;
}

.btn.sm {
  padding: 8px 12px;
  border-radius: 8px;
}

/* CTA (Format button) */
.cta {
  border: none;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  color: #07111f;
  box-shadow: var(--shadow);
}
.cta:hover {
  filter: brightness(1.06);
}
.hidden {
  display: none !important;
}

/* ===========
   Output shell
   =========== */
.out-shell {
  position: relative;
  padding: 0;
}

/* Progress overlay in output box */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 12, 24, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 12px;
  z-index: 5;
  text-align: center;
  padding: 16px;
}
.meter {
  width: min(360px, 86%);
  height: 10px;
  background: #20314b;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}
.fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transition: width 0.25s ease;
}
.stage {
  font-weight: 800;
  font-size: 14px;
}
.detail {
  color: var(--muted);
  font-size: 12px;
}

/* ==========
   Modal (URL)
   ========== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.dialog {
  width: min(560px, 96vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.dialog h3 {
  margin: 0 0 10px;
  font-size: 16px;
}
.dialog input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0a1222;
  color: var(--ink);
  outline: none;
  margin-bottom: 12px;
  font-family: inherit;
  font-size: 14px;
}
.dialog input:focus {
  border-color: #1fa99a;
}
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* =====
   Toast
   ===== */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 16px;
  background: #b91c1c;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 50;
  max-width: 92vw;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
}
.toast.notice {
  background: #0f766e;
} /* neutral notice style */

/* ==========================
   Syntax highlighting (values only)
   ========================== */
.jv-string {
  color: #fde68a;
}
.jv-number {
  color: #7dd3fc;
}
.jv-boolean {
  color: #fb923c;
  font-weight: 700;
}
.jv-null {
  color: #9aa5b1;
  font-weight: 700;
}
.jv-punc {
  color: #22d3ee;
  font-weight: 700;
}

/* ==========================
   Smooth, modern scrollbars for internal boxes
   ========================== */
.scrollable::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.scrollable::-webkit-scrollbar-track {
  background: transparent;
}
.scrollable::-webkit-scrollbar-thumb {
  background-color: #2a3a59;
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.scrollable::-webkit-scrollbar-thumb:hover {
  background-color: #3a4a69;
}

/* Improve momentum scrolling on iOS */
.scrollable {
  -webkit-overflow-scrolling: touch;
}

/* ==========================
   Small-screen refinements
   ========================== */
@media (max-width: 420px) {
  .tools .btn {
    flex: 1 1 auto;
    justify-content: center;
  }
  .row-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .truncate {
    max-width: 100%;
    text-align: left;
  }
  .actions {
    gap: 8px;
  }
}
