/*
 * tools.css — shared design system for developer utility tools
 * Tokens follow a CSS custom-property approach (similar to Tailwind 4's @theme layer,
 * but plain CSS — no build step required).
 *
 * Usage: <link rel="stylesheet" href="tools.css">
 * Then add a single <style> block for tool-specific overrides only.
 */

/* ─── Fonts ──────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── Design tokens ──────────────────────────────────────────────────────── */

:root {
  /* Surfaces */
  --bg:           oklch(0.985 0.004 75);
  --surface:      oklch(0.995 0.003 75);

  /* Borders */
  --line:         oklch(0.92  0.005 75);
  --line-strong:  oklch(0.85  0.006 75);

  /* Foreground scale */
  --fg:           oklch(0.20  0.008 60);
  --fg-muted:     oklch(0.50  0.008 60);
  --fg-faint:     oklch(0.68  0.008 60);

  /* Accent — warm orange */
  --accent:       oklch(0.66  0.16  45);
  --accent-fg:    oklch(0.99  0.003 75);

  /* Semantic */
  --danger:       oklch(0.58  0.16  25);
  --ok:           oklch(0.62  0.14 155);

  /* Shape */
  --radius:       14px;
  --radius-sm:    8px;

  /* Shadows */
  --shadow-sm:    0 1px 0 oklch(0.92 0.005 75);
  --shadow-pill:  0 1px 2px oklch(0 0 0 / 0.06), 0 0 0 1px var(--line);

  /* Typography */
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Dark theme — explicit [data-theme="dark"] on <html> */
:root[data-theme="dark"] {
  --bg:           oklch(0.16  0.006 60);
  --surface:      oklch(0.20  0.006 60);
  --line:         oklch(0.27  0.007 60);
  --line-strong:  oklch(0.36  0.008 60);
  --fg:           oklch(0.96  0.004 75);
  --fg-muted:     oklch(0.72  0.008 60);
  --fg-faint:     oklch(0.55  0.008 60);
  --accent:       oklch(0.74  0.15  50);
  --accent-fg:    oklch(0.18  0.006 60);
  --shadow-sm:    0 1px 0 oklch(0.27 0.007 60);
}

/* System-preference fallback — only fires when no explicit theme is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg:           oklch(0.16  0.006 60);
    --surface:      oklch(0.20  0.006 60);
    --line:         oklch(0.27  0.007 60);
    --line-strong:  oklch(0.36  0.008 60);
    --fg:           oklch(0.96  0.004 75);
    --fg-muted:     oklch(0.72  0.008 60);
    --fg-faint:     oklch(0.55  0.008 60);
    --accent:       oklch(0.74  0.15  50);
    --accent-fg:    oklch(0.18  0.006 60);
    --shadow-sm:    0 1px 0 oklch(0.27 0.007 60);
  }
}

/* ─── color-scheme hints ─────────────────────────────────────────────────── */

html                    { color-scheme: light dark; }
html[data-theme="light"]{ color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

/* ─── Smooth theme transitions ───────────────────────────────────────────── */

body,
.panel, .panel-head, .panel-foot,
.mode, .mode .pill,
.theme, .theme .pill,
.chip,
.icon-btn,
.swap button,
footer kbd {
  transition:
    background-color .25s ease,
    color            .25s ease,
    border-color     .25s ease;
}

/* ─── Reset & base ───────────────────────────────────────────────────────── */

*  { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ─── App shell ──────────────────────────────────────────────────────────── */

.app {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 32px 24px;
  gap: 22px;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--fg);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.02em;
  /* mark also needs theme transition */
  transition: background-color .25s ease, color .25s ease;
}

.brand .title  { font-size: 14px; }

.brand .sub {
  color: var(--fg-faint);
  font-weight: 400;
  font-size: 13px;
  margin-left: 2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ─── Segmented pill control (shared by .theme and .mode) ────────────────── */
/*
 * Both controls use the same pill-track pattern:
 *   <div class="seg-ctrl" data-active="…">
 *     <span class="pill"></span>
 *     <button data-value="…" aria-pressed="true|false">…</button>
 *     …
 *   </div>
 * .theme uses icon-only 28×28px buttons; .mode uses text buttons with padding.
 */

.theme,
.mode {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  position: relative;
}

/* shared pill */
.theme .pill,
.mode .pill {
  position: absolute;
  background: var(--bg);
  border-radius: 999px;
  box-shadow: var(--shadow-pill);
  transition: transform .22s cubic-bezier(.4, 0, .2, 1);
  z-index: 0;
}

/* shared button reset */
.theme button,
.mode button {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: color .18s ease;
}

/* ── Theme switcher (3 icon buttons × 28px) ── */

.theme button {
  color: var(--fg-faint);
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
}

.theme button:hover                 { color: var(--fg-muted); }
.theme button[aria-pressed="true"]  { color: var(--fg); }
.theme button svg                   { width: 14px; height: 14px; }

.theme .pill {
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
}

.theme[data-theme="light"]  .pill { transform: translateX(0px); }
.theme[data-theme="system"] .pill { transform: translateX(28px); }
.theme[data-theme="dark"]   .pill { transform: translateX(56px); }

/* ── Mode / direction switcher (text labels) ── */

.mode button {
  font: inherit;
  font-weight: 500;
  padding: 7px 18px;
  border-radius: 999px;
  color: var(--fg-muted);
  letter-spacing: -0.005em;
  white-space: nowrap;
}

.mode button[aria-pressed="true"] { color: var(--fg); }

.mode .pill {
  top: 3px;
  bottom: 3px;
  width: calc(50% - 3px);
}

/* pill position is set per-tool via data attribute, e.g.:
   .mode[data-mode="decode"] .pill { transform: translateX(100%); }  */

/* ─── Main two-panel grid ────────────────────────────────────────────────── */

main {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
}

/* ─── Panel ──────────────────────────────────────────────────────────────── */

.panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 420px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.panel-label {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.panel-label .name {
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
}

.panel-label .kind {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-faint);
  text-transform: lowercase;
}

.panel-tools {
  display: flex;
  gap: 2px;
}

/* ─── Textarea ───────────────────────────────────────────────────────────── */

textarea {
  flex: 1;
  appearance: none;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 18px 20px 22px;
  outline: 0;
  width: 100%;
  tab-size: 2;
}

textarea::placeholder {
  color: var(--fg-faint);
  font-style: normal;
}

textarea[readonly] { cursor: default; }

/* ─── Panel footer ───────────────────────────────────────────────────────── */

.panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 18px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-faint);
  background: var(--surface);
}

.panel-foot .stats        { display: flex; gap: 14px; }
.panel-foot .stats span b { color: var(--fg-muted); font-weight: 500; }

/* ─── Icon button ────────────────────────────────────────────────────────── */

.icon-btn {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--fg-muted);
  width: 28px;
  height: 28px;
  border-radius: 7px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .14s ease, color .14s ease;
  position: relative;
}

.icon-btn:hover  { background: var(--bg); color: var(--fg); }
.icon-btn:active { transform: translateY(0.5px); }
.icon-btn svg    { width: 15px; height: 15px; }

/* Copy-success flash */
.icon-btn[data-flash="ok"] { color: var(--ok); }
.icon-btn[data-flash="ok"]::after {
  content: "copied";
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--fg);
  color: var(--bg);
  font-size: 10.5px;
  font-family: var(--font-mono);
  padding: 3px 6px;
  border-radius: 5px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

/* ─── Swap divider ───────────────────────────────────────────────────────── */

.swap {
  display: grid;
  place-items: center;
  width: 56px;
  position: relative;
}

/* Faded vertical rule */
.swap::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  background: linear-gradient(
    to bottom,
    transparent 0,
    var(--line) 18%,
    var(--line) 82%,
    transparent 100%
  );
}

.swap button {
  appearance: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--fg-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition:
    transform    .35s cubic-bezier(.4, 0, .2, 1),
    color        .14s ease,
    border-color .14s ease,
    background   .14s ease;
  position: relative;
  z-index: 1;
}

.swap button:hover {
  color: var(--fg);
  border-color: var(--line-strong);
  background: var(--bg);
}

.swap button.spin { transform: rotate(180deg); }
.swap svg         { width: 16px; height: 16px; }

/* ─── Options bar ────────────────────────────────────────────────────────── */

.options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 4px 2px 0;
}

.opt-group {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.opt-label {
  font-size: 12px;
  color: var(--fg-faint);
  margin-right: 2px;
}

/* ─── Chip (toggle button) ───────────────────────────────────────────────── */

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg-muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color .14s, border-color .14s, background .14s;
  user-select: none;
}

.chip:hover                 { color: var(--fg); border-color: var(--line-strong); }
.chip[aria-pressed="true"]  { color: var(--fg); border-color: var(--fg); background: var(--bg); }

.chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}

.chip[aria-pressed="true"] .dot { background: var(--accent); }

/* ─── Footer ─────────────────────────────────────────────────────────────── */

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--fg-faint);
  font-family: var(--font-mono);
  font-size: 11px;
}

footer .kbd-list {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

footer kbd {
  font: inherit;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--fg-muted);
  background: var(--surface);
  margin: 0 2px;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 820px) {
  .app              { padding: 18px; gap: 16px; }
  header            { flex-wrap: wrap; gap: 12px; }
  .header-right     { flex-wrap: wrap; gap: 8px; }
  main              { grid-template-columns: 1fr; }

  .swap             { width: auto; height: 48px; }
  .swap::before {
    left: 0; right: 0; top: 50%;
    width: auto; height: 1px;
    background: linear-gradient(
      to right,
      transparent 0,
      var(--line) 18%,
      var(--line) 82%,
      transparent 100%
    );
  }
  .swap button      { transform: rotate(90deg); }
  .swap button.spin { transform: rotate(270deg); }

  .options          { flex-direction: column; align-items: stretch; }
  footer            { flex-direction: column; gap: 8px; align-items: flex-start; }
}
