/* ============================================================
   AI Personal Converter — shared styles
   Design: clean, minimal, dev-tool aesthetic (myifew brand)
   ============================================================ */

:root {
  /* color tokens — light */
  --bg: #f4f5f9;
  --bg-grad-1: #eef1fb;
  --bg-grad-2: #f7f3ff;
  --surface: #ffffff;
  --surface-2: #f6f7fb;
  --border: #e6e8f0;
  --border-strong: #d3d7e6;
  --text: #1c2030;
  --text-soft: #5b6175;
  --text-faint: #8a90a4;
  --accent: #5b5bf6;
  --accent-2: #8b5cf6;
  --accent-soft: #ececfe;
  --accent-text: #ffffff;
  --success: #16a34a;
  --danger: #dc2626;
  --danger-soft: #fde8e8;
  --code-bg: #f6f7fb;
  --shadow-sm: 0 1px 2px rgba(20, 24, 48, .06);
  --shadow-md: 0 6px 24px rgba(28, 32, 64, .08);
  --shadow-lg: 0 18px 50px rgba(28, 32, 64, .12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "IBM Plex Sans Thai", "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #0f1117;
  --bg-grad-1: #141728;
  --bg-grad-2: #170f24;
  --surface: #171a24;
  --surface-2: #1e212e;
  --border: #2a2e3d;
  --border-strong: #3a3f52;
  --text: #e9ebf4;
  --text-soft: #aab0c4;
  --text-faint: #777e94;
  --accent: #7c7cff;
  --accent-2: #a78bfa;
  --accent-soft: #23233a;
  --code-bg: #11131b;
  --danger: #f87171;
  --danger-soft: #2a1818;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, .35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 12% -8%, var(--bg-grad-1), transparent 60%),
    radial-gradient(1000px 500px at 100% 0%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: saturate(160%) blur(10px);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
  gap: 14px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 18px;
  box-shadow: var(--shadow-sm);
}
.brand .logo svg { width: 20px; height: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-soft); font-size: 14px; font-weight: 500;
}
.back-link:hover { color: var(--accent); text-decoration: none; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-soft);
  border-radius: 10px;
  cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--border-strong); }
.icon-btn svg { width: 18px; height: 18px; }
.theme-icon-dark { display: none; }
html[data-theme="dark"] .theme-icon-light { display: none; }
html[data-theme="dark"] .theme-icon-dark { display: block; }

/* ---------- landing hero ---------- */
.hero {
  text-align: center;
  padding: 64px 0 36px;
}
.hero .eyebrow {
  display: inline-block;
  font-size: 13px; font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 6px 14px; border-radius: 999px;
  margin-bottom: 18px;
}
.hero h1 {
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.18;
  margin: 0 0 14px;
  letter-spacing: -.5px;
}
.hero h1 .grad {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p {
  color: var(--text-soft);
  font-size: 17px;
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- card grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  padding: 8px 0 56px;
}
.card {
  position: relative;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 24px;
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0; transition: opacity .18s;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}
.card:hover::before { opacity: 1; }
.card .emoji {
  font-size: 30px;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 16px;
}
.card h3 { margin: 0 0 6px; font-size: 19px; }
.card .desc { color: var(--text-soft); font-size: 14px; margin: 0 0 16px; }
.card ul {
  list-style: none; padding: 0; margin: 0 0 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.card ul li {
  position: relative; padding-left: 24px;
  font-size: 14px; color: var(--text-soft);
}
.card ul li::before {
  content: "✓";
  position: absolute; left: 0; top: 0;
  color: var(--accent); font-weight: 700;
}
.card .go {
  margin-top: auto;
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 14px; color: var(--accent);
}
.card:hover .go { gap: 10px; }
.card .stretched { position: absolute; inset: 0; }

/* ---------- tool page ---------- */
.tool-head { padding: 36px 0 20px; }
.tool-head .crumb { font-size: 13px; color: var(--text-faint); margin-bottom: 10px; }
.tool-head h1 {
  font-size: clamp(24px, 4vw, 34px);
  margin: 0 0 8px; letter-spacing: -.4px;
  display: flex; align-items: center; gap: 12px;
}
.tool-head h1 .t-emoji { font-size: .9em; }
.tool-head p { color: var(--text-soft); margin: 0; max-width: 640px; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin: 10px 0 16px;
}
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; gap: 6px; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font);
  font-size: 14px; font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-color: transparent;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); }
.btn-ghost { background: transparent; }

.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding-bottom: 40px;
  align-items: stretch;
}
.pane {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  min-height: 480px;
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.pane-head .label {
  font-size: 13px; font-weight: 600; color: var(--text-soft);
  display: flex; align-items: center; gap: 8px;
}
.pane-head .meta { font-size: 12px; color: var(--text-faint); }
.pane-body { flex: 1; display: flex; min-height: 0; position: relative; }

textarea.editor {
  flex: 1;
  width: 100%;
  border: 0;
  resize: none;
  padding: 16px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text);
  background: transparent;
  outline: none;
  tab-size: 2;
}
textarea.editor::placeholder { color: var(--text-faint); }

/* output renderers */
.output-scroll {
  flex: 1; width: 100%;
  overflow: auto;
  padding: 16px;
}
pre.code-out {
  margin: 0;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre;
  color: var(--text);
}

/* status / error bar */
.status {
  font-size: 13px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  color: var(--text-faint);
}
.status.ok { color: var(--success); }
.status.err { color: var(--danger); background: var(--danger-soft); }

/* ---------- JSON beautifier (json.parser.online.fr style) ---------- */
.json-tree {
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text);
}
.jn { display: block; }
.jline { display: block; white-space: pre; }

/* small square toggle box: [-] / [+] */
.jtog {
  display: inline-block;
  width: 15px; height: 15px;
  margin-right: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 11px; line-height: 13px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  vertical-align: 1px;
}
.jtog:hover { border-color: var(--accent); color: var(--accent); }
.jtog-spacer { display: inline-block; width: 15px; margin-right: 6px; }

/* children indented with a guide line, like the classic tool */
.jchildren {
  display: block;
  margin-left: 7px;
  padding-left: 14px;
  border-left: 1px dotted var(--border-strong);
}

/* collapsed state */
.jn.collapsed > .jchildren,
.jn.collapsed > .jclose { display: none; }
.jph { display: none; color: var(--text-faint); }
.jn.collapsed > .jline > .jph { display: inline; }

/* syntax colors */
.jt-key { color: var(--accent-2); }
.jt-string { color: var(--success); }
.jt-number { color: #c2410c; }
.jt-boolean { color: var(--accent); }
.jt-null { color: var(--text-faint); }
.jt-punc { color: var(--text-soft); }
html[data-theme="dark"] .jt-number { color: #fbbf24; }
html[data-theme="dark"] .jt-string { color: #86efac; }

/* markdown rendered output */
.md-body { color: var(--text); }
.md-body h1, .md-body h2, .md-body h3 { line-height: 1.3; margin: 1.2em 0 .5em; }
.md-body h1 { font-size: 1.7em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.md-body h2 { font-size: 1.4em; border-bottom: 1px solid var(--border); padding-bottom: .3em; }
.md-body h3 { font-size: 1.2em; }
.md-body p { margin: .7em 0; }
.md-body a { color: var(--accent); }
.md-body code {
  font-family: var(--mono); font-size: .9em;
  background: var(--code-bg); padding: .15em .4em; border-radius: 5px;
}
.md-body pre {
  background: var(--code-bg); padding: 14px; border-radius: 10px;
  overflow: auto; border: 1px solid var(--border);
}
.md-body pre code { background: none; padding: 0; }
.md-body blockquote {
  margin: .8em 0; padding: .3em 1em;
  border-left: 3px solid var(--accent);
  color: var(--text-soft); background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}
.md-body ul, .md-body ol { padding-left: 1.6em; margin: .6em 0; }
.md-body li { margin: .25em 0; }
.md-body table { border-collapse: collapse; margin: .8em 0; width: 100%; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 8px 12px; }
.md-body th { background: var(--surface-2); }
.md-body img { max-width: 100%; border-radius: 8px; }
.md-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }

/* html preview iframe */
iframe.preview-frame {
  flex: 1; width: 100%; border: 0; background: #fff;
}

/* ---------- rich text (WYSIWYG) editor ---------- */
.fmtbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.fmtbar .sep {
  width: 1px; align-self: stretch; margin: 2px 4px;
  background: var(--border-strong);
}
.fmtbar button {
  min-width: 30px; height: 30px;
  padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  border-radius: 7px;
  font-family: var(--font);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: .12s;
}
.fmtbar button:hover { background: var(--surface); border-color: var(--border); color: var(--accent); }
.fmtbar button:active { transform: translateY(1px); }
.fmtbar button.mono { font-family: var(--mono); font-weight: 500; }

.rich-editor {
  flex: 1; width: 100%;
  overflow: auto;
  padding: 18px;
  outline: none;
  font-size: 15px;
}
.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
}
.rich-editor:focus { outline: none; }

/* table size popover */
.tbl-pop {
  position: fixed;
  z-index: 40;
  display: none;
  min-width: 180px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
}
.tbl-pop.show { display: block; }
.tbl-pop label {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 13px; color: var(--text-soft);
  margin-bottom: 10px;
}
.tbl-pop input {
  width: 66px; padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface-2); color: var(--text);
  font: inherit; text-align: center;
}
.tbl-pop .btn { width: 100%; justify-content: center; margin-top: 2px; }

/* ---------- footer (replicated from calculator.myifew.com) ---------- */
.site-footer {
  background: #1f2937;
  color: #ffffff;
  padding: 32px 20px;
  margin-top: 48px;
}

.site-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

.site-footer-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.site-footer-tagline {
  color: #9ca3af;
  margin-bottom: 16px;
  font-size: 0.98rem;
}

.site-footer-highlights {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: #9ca3af;
  font-size: 0.92rem;
  margin-bottom: 16px;
}

.site-footer-byline {
  color: #6b7280;
  font-size: 0.92rem;
  margin-bottom: 10px;
}

.site-footer-link {
  color: #60a5fa;
  text-decoration: none;
  transition: color 0.2s;
}

.site-footer-link:hover {
  color: #93c5fd;
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--surface);
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: .25s; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .panes { grid-template-columns: 1fr; }
  .pane { min-height: 340px; }
  .hero { padding: 44px 0 28px; }
}
