:root {
  --bg: #0b1220;
  --panel: #121a2b;
  --card: #1a2438;
  --text: #e5eaf3;
  --muted: #a9b4c8;
  --line: #2c3a57;
  --accent: #6ea8fe;
  --accent-2: #7ef0c6;
  --bg-grad-start: #0b1220;
  --bg-grad-end: #0f172a;
  --header-bg: rgba(11, 18, 32, 0.85);
  --interactive-bg: rgba(110, 168, 254, 0.08);
  --interactive-bg-hover: rgba(110, 168, 254, 0.16);
  --interactive-bg-strong: rgba(110, 168, 254, 0.12);
  --interactive-bg-strong-hover: rgba(110, 168, 254, 0.2);
  --interactive-alt-bg: rgba(126, 240, 198, 0.11);
  --interactive-alt-bg-hover: rgba(126, 240, 198, 0.2);
  --focus-ring: rgba(110, 168, 254, 0.45);
  --surface-soft: rgba(11, 18, 32, 0.35);
  --surface-strong: rgba(11, 18, 32, 0.42);
  --field-bg: #0b1220;
  --placeholder: #8e9ab3;
  --hero-grad-a: rgba(126, 240, 198, 0.08);
  --hero-grad-b: rgba(110, 168, 254, 0.08);
  --result-border: rgba(126, 240, 198, 0.45);
  --result-grad-a: rgba(126, 240, 198, 0.14);
  --result-grad-b: rgba(110, 168, 254, 0.12);
  --result-shadow: rgba(0, 0, 0, 0.28);
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --container-max: 1100px;
  --result-top-offset: 76px;
}

[data-theme="light"] {
  --bg: #eef3fb;
  --panel: #ffffff;
  --card: #f7faff;
  --text: #152238;
  --muted: #4f607e;
  --line: #c9d4e6;
  --accent: #2563eb;
  --accent-2: #0f766e;
  --bg-grad-start: #eef3fb;
  --bg-grad-end: #e6edf8;
  --header-bg: rgba(255, 255, 255, 0.88);
  --interactive-bg: rgba(37, 99, 235, 0.08);
  --interactive-bg-hover: rgba(37, 99, 235, 0.14);
  --interactive-bg-strong: rgba(37, 99, 235, 0.1);
  --interactive-bg-strong-hover: rgba(37, 99, 235, 0.18);
  --interactive-alt-bg: rgba(15, 118, 110, 0.1);
  --interactive-alt-bg-hover: rgba(15, 118, 110, 0.18);
  --focus-ring: rgba(37, 99, 235, 0.35);
  --surface-soft: rgba(255, 255, 255, 0.72);
  --surface-strong: rgba(255, 255, 255, 0.9);
  --field-bg: #ffffff;
  --placeholder: #6f7f9b;
  --hero-grad-a: rgba(15, 118, 110, 0.08);
  --hero-grad-b: rgba(37, 99, 235, 0.09);
  --result-border: rgba(15, 118, 110, 0.3);
  --result-grad-a: rgba(15, 118, 110, 0.11);
  --result-grad-b: rgba(37, 99, 235, 0.09);
  --result-shadow: rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, var(--bg-grad-start) 0%, var(--bg-grad-end) 100%);
  color: var(--text);
  min-height: 100vh;
}

.container {
  width: min(var(--container-max), 92vw);
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(6px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 14px 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.brand-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.62) 58%, rgba(255, 255, 255, 0.12) 80%, rgba(255, 255, 255, 0) 92%);
  box-shadow:
    0 0 0 6px rgba(255, 255, 255, 0.3),
    0 0 32px rgba(255, 255, 255, 0.72);
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

.btn-link {
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--interactive-bg);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  flex: 1 1 auto;
  text-align: center;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--interactive-bg);
  color: var(--accent);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  align-self: flex-end;
}

.theme-toggle:hover {
  background: var(--interactive-bg-hover);
}

main { padding: var(--space-6) 0 40px; }

.hero {
  border: 1px solid var(--line);
  background: linear-gradient(145deg, var(--hero-grad-a), var(--hero-grad-b));
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 18px;
}

.hero h1 { margin: 0 0 8px; font-size: 28px; }
.hero p { margin: 0; color: var(--muted); }

.ce-search-input {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 12px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--interactive-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.ce-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.ce-search-input::placeholder {
  color: var(--muted);
}
.ce-search-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 15px;
}

.section-title {
  margin: 24px 0 10px;
  font-size: 18px;
  color: var(--accent-2);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.most-used-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1100px) {
  .most-used-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .most-used-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .most-used-grid {
    grid-template-columns: 1fr;
  }
}

.card {
  display: block;
  text-decoration: none;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.card:hover { border-color: var(--accent); }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 13px; }

.tool-box {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-3);
}

.result-panel,
.input-panel,
.helper-panel,
.utility-links {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  padding: var(--space-3);
}

.input-panel {
  display: grid;
  gap: var(--space-3);
}

.converter-ui {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-top: 0;
}

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

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.field-group.compact {
  justify-content: end;
}

.tool-box input,
.tool-box select,
.tool-box textarea,
.tool-box button {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  color: var(--text);
  padding: 10px 12px;
  font-size: 16px;
  line-height: 1.35;
}

.tool-box input::placeholder,
.tool-box textarea::placeholder {
  color: var(--placeholder);
}

.tool-box textarea {
  min-height: 96px;
  resize: vertical;
}

.tool-box input[type="checkbox"],
.tool-box input[type="radio"] {
  width: 16px;
  height: 16px;
  padding: 0;
  accent-color: var(--accent);
}

.tool-box label {
  color: var(--muted);
  font-size: 13px;
}

.input,
.select,
.action-btn {
  font: inherit;
}

.input:focus,
.select:focus,
.action-btn:focus,
.btn-link:focus,
.theme-toggle:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
  border-color: var(--accent);
}

.action-btn {
  cursor: pointer;
  background: var(--interactive-bg-strong);
  transition: background 0.18s ease, border-color 0.18s ease;
  font-weight: 600;
  min-height: 44px;
}

.action-btn:hover {
  background: var(--interactive-bg-strong-hover);
  border-color: var(--accent);
}

.result {
  order: -1;
  margin-top: 0;
  border-radius: 14px;
  border: 1px solid var(--result-border);
  background: linear-gradient(145deg, var(--result-grad-a), var(--result-grad-b));
  padding: var(--space-4);
  font-weight: 700;
  font-size: clamp(1.25rem, 4.4vw, 2rem);
  line-height: 1.3;
  box-shadow: 0 8px 24px var(--result-shadow);
}

.result.prominent {
  position: sticky;
  top: var(--result-top-offset);
  z-index: 3;
}

body.ce-keyboard-open .result.prominent,
body.ce-focus-input .result.prominent {
  position: static;
}

@media (max-height: 700px) {
  .result.prominent {
    position: static;
  }
}

@media (max-width: 767px) {
  body.ce-focus-input .result.prominent {
    position: static;
  }
}

.result:empty::before {
  content: "Enter a value to see the result.";
  color: var(--muted);
  font-weight: 500;
}

.result-meta {
  margin-top: var(--space-2);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid var(--line);
  margin-right: 6px;
}

.badge.live {
  background: rgba(126, 240, 198, 0.18);
  border-color: rgba(126, 240, 198, 0.45);
  color: #9ef8da;
}

.badge.fallback {
  background: rgba(255, 193, 7, 0.14);
  border-color: rgba(255, 193, 7, 0.35);
  color: #ffd666;
}

.chips {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-btn {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--interactive-bg-strong);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.chip-btn:hover {
  border-color: var(--accent);
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.metric-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-strong);
  padding: 10px;
}

.metric-card .k {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.metric-card .v {
  font-weight: 700;
}

.action-row {
  margin-top: var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.action-row .action-btn {
  flex: 1 1 160px;
}

.action-btn.secondary {
  background: var(--interactive-alt-bg);
}

.action-btn.secondary:hover {
  background: var(--interactive-alt-bg-hover);
  border-color: var(--accent-2);
}

.hint {
  margin-top: 0;
  color: var(--muted);
  font-size: 12px;
}

.tool-box > h2 {
  margin: 0;
}

.tool-box > .note,
.tool-box > .result-meta,
.tool-box > .hint {
  color: var(--muted);
  font-size: 13px;
}

.tool-box > .note {
  margin-top: 0;
}

@media (min-width: 768px) {
  :root {
    --container-max: 860px;
  }

  .header-inner {
    flex-direction: row;
    justify-content: flex-start;
  }

  .nav-links {
    width: auto;
    justify-content: flex-end;
    margin-left: auto;
  }

  .btn-link {
    flex: 0 0 auto;
  }

  .theme-toggle {
    align-self: auto;
  }

  .converter-ui {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .converter-ui > .field-group:first-child {
    grid-column: 1 / -1;
  }

  .result {
    font-size: clamp(1.5rem, 3.2vw, 2.25rem);
  }

  .result.prominent {
    position: static;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  :root {
    --container-max: 1100px;
  }

  .tool-box {
    grid-template-columns: minmax(0, 7fr) minmax(300px, 5fr);
    column-gap: var(--space-5);
    row-gap: var(--space-3);
    align-items: start;
  }

  .tool-box > h2,
  .tool-box > .input-panel,
  .tool-box > .helper-panel,
  .tool-box > .note,
  .tool-box > .result-meta,
  .tool-box > .hint,
  .tool-box > [data-copy-action="1"] {
    grid-column: 1;
  }

  .tool-box > .result-panel {
    grid-column: 2;
    grid-row: 1 / span 4;
    align-self: start;
  }

  .tool-box > .result-panel .result {
    margin-top: 0;
  }

  .tool-box.special-layout {
    grid-template-columns: minmax(0, 6fr) minmax(320px, 6fr);
    column-gap: var(--space-4);
    row-gap: var(--space-2);
  }

  .tool-box.special-layout > .result-panel {
    padding: var(--space-3);
  }

  .tool-box.special-layout > .input-panel {
    gap: var(--space-2);
  }

  .tool-box.special-layout > .helper-panel {
    padding: 10px 12px;
    display: grid;
    gap: 6px;
  }

  .tool-box.special-layout > .helper-panel .note,
  .tool-box.special-layout > .helper-panel .hint,
  .tool-box.special-layout > .helper-panel .result-meta {
    margin: 0;
    font-size: 12px;
    line-height: 1.4;
  }

  .tool-box.special-layout > .helper-panel .chips {
    margin-top: 2px;
  }
}

.note {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

/* ── UI Builder: Drop Zone ── */
.ce-drop-zone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: var(--interactive-bg);
  padding: var(--space-5);
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}
.ce-drop-zone:hover,
.ce-drop-zone.ce-drop-active {
  border-color: var(--accent);
  background: var(--interactive-bg-hover);
}
.ce-drop-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.ce-drop-label {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
  text-align: center;
}

/* ── UI Builder: Field Row (inline group) ── */
.ce-field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
}

/* ── UI Builder: Checkbox Label ── */
.ce-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* ── UI Builder: Canvas Result ── */
.ce-canvas-result {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

/* ── UI Builder: Download Area ── */
.ce-download-area {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ── UI Builder: Progress Bar ── */
.ce-progress {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-strong);
  overflow: hidden;
}
.ce-progress-bar {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s ease;
}

/* ── UI Builder: Overlay ── */
.ce-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  border-radius: 12px;
  z-index: 4;
}

/* ── Breadcrumb ── */
.ce-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: var(--space-3);
}
.ce-breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}
.ce-breadcrumb a:hover {
  text-decoration: underline;
}
.ce-breadcrumb-sep::before {
  content: '›';
  margin: 0 2px;
}

/* ── Related Tools ── */
.ce-related {
  margin-top: var(--space-6);
}
.ce-related-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 var(--space-3);
  color: var(--accent-2);
}
.ce-related-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}
@media (min-width: 768px) {
  .ce-related-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
  .ce-related-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.ce-related-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-3);
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ce-related-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.ce-related-card strong {
  font-size: 14px;
  color: var(--accent-2);
}
.ce-related-card span {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Ad Slots ── */
.ce-ad-slot {
  border-radius: 10px;
  background: var(--surface-soft);
  text-align: center;
  margin: var(--space-4) auto;
  max-width: 336px;
  overflow: hidden;
}
.ce-ad-slot::before {
  content: 'Advertisement';
  display: block;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 0 2px;
}
.ce-ad-slot.hero-ad {
  min-height: 100px;
  max-width: 100%;
}
/* Ad inside result-panel */
.result-panel > .ce-ad-slot.sidebar {
  margin-top: var(--space-4);
  max-width: 100%;
}

/* ── Sharing Buttons ── */
.ce-share-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.ce-share-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-right: 2px;
}
.ce-share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--interactive-bg);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}
.ce-share-btn:hover {
  background: var(--interactive-bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}
.ce-share-btn svg {
  display: block;
}

.fine-print {
  margin-top: 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  opacity: 0.9;
}

footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 18px 0 26px;
  font-size: 13px;
}

.footer-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  text-align: center;
}

.footer-copy {
  margin: 0;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.footer-links a {
  color: var(--accent);
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

@media (min-width: 768px) {
  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
    text-align: left;
  }
}
