/* ---------- Design tokens (shadcn/ui "zinc" palette) ---------- */
:root {
  color-scheme: light dark;
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 45%;
  --radius: 0.6rem;

  --code-bg: 240 10% 3.9%;
  --code-fg: 0 0% 92%;
  --code-keyword: 210 90% 72%;
  --code-string: 142 60% 60%;
  --code-number: 35 90% 65%;
  --code-comment: 240 5% 55%;
  --code-punct: 0 0% 75%;
  --code-func: 45 93% 68%;
}

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

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: 240 10% 6%;
  --foreground: 0 0% 98%;
  --card: 240 8% 9%;
  --card-foreground: 0 0% 98%;
  --border: 240 4% 18%;
  --input: 240 4% 18%;
  --ring: 240 4.9% 83.9%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 4% 15%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 4% 15%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 4% 15%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 45%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 60% 50%;

  --code-bg: 240 10% 4%;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: 240 10% 6%;
    --foreground: 0 0% 98%;
    --card: 240 8% 9%;
    --card-foreground: 0 0% 98%;
    --border: 240 4% 18%;
    --input: 240 4% 18%;
    --ring: 240 4.9% 83.9%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 4% 15%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 4% 15%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 4% 15%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 45%;
    --destructive-foreground: 0 0% 98%;
    --success: 142 60% 50%;
    --code-bg: 240 10% 4%;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: var(--font-sans);
}

a { color: inherit; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background) / 0.85);
  backdrop-filter: blur(8px);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
}

.topbar-title .mark {
  display: block;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 0.45rem;
  flex-shrink: 0;
  object-fit: cover;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tabbar {
  display: none;
  position: sticky;
  top: 52px;
  z-index: 19;
  gap: 0.25rem;
  padding: 0.4rem;
  background: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border));
}

.tab {
  flex: 1;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: calc(var(--radius) - 2px);
  border: none;
  background: transparent;
  color: hsl(var(--muted-foreground));
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  align-items: start;
  max-width: 1400px;
  margin: 0 auto;
}

.panel-form {
  min-width: 0;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel-code {
  min-width: 0;
  position: sticky;
  top: calc(52px + 1.25rem);
  height: calc(100vh - 52px - 2.5rem);
  margin: 1.25rem 1.25rem 1.25rem 0;
  display: flex;
  flex-direction: column;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
  background: hsl(var(--code-bg));
}

/* ---------- Card ---------- */
.card {
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.1rem;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 0.15rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card-description {
  font-size: 0.78rem;
  color: hsl(var(--muted-foreground));
  margin: 0 0 0.85rem;
}

/* ---------- Form primitives ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.field:last-child { margin-bottom: 0; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.label {
  font-size: 0.78rem;
  font-weight: 500;
  color: hsl(var(--foreground));
}

.helper {
  font-size: 0.72rem;
  color: hsl(var(--muted-foreground));
  margin-top: -0.1rem;
}

.helper-warning {
  color: hsl(var(--destructive));
  font-weight: 500;
}

.input-warning {
  border-color: hsl(var(--destructive)) !important;
}
.input-warning:focus {
  box-shadow: 0 0 0 3px hsl(var(--destructive) / 0.15) !important;
}

.input, .select, .textarea {
  width: 100%;
  border: 1px solid hsl(var(--input));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border-radius: calc(var(--radius) - 2px);
  padding: 0.5rem 0.65rem;
  font-size: 0.83rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.15);
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  padding-right: 1.75rem;
}

.color-input {
  width: 3rem;
  height: 2.1rem;
  padding: 0.15rem;
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--background));
  cursor: pointer;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  padding: 0.5rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.25);
}

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-primary:hover { opacity: 0.9; }

.btn-outline {
  background: transparent;
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
}
.btn-outline:hover { background: hsl(var(--secondary)); }

.btn-ghost {
  background: transparent;
  color: hsl(var(--foreground));
}
.btn-ghost:hover { background: hsl(var(--secondary)); }

.btn-icon {
  padding: 0.45rem;
  width: 2.05rem;
  height: 2.05rem;
}

.btn-sm { padding: 0.32rem 0.6rem; font-size: 0.74rem; }

.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.icon-img {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  border-radius: 3px;
  display: block;
}

/* ---------- Tooltip (icon-only controls) ---------- */
[data-tooltip] { position: relative; }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: hsl(var(--foreground));
  color: hsl(var(--background));
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.3rem 0.55rem;
  border-radius: 0.35rem;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 60;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Right-align tooltip for controls near the right edge so it doesn't clip */
#theme-toggle::after,
#ghStarLink::after {
  left: auto;
  right: 0;
  transform: translateY(-4px);
}
#theme-toggle:hover::after,
#theme-toggle:focus-visible::after,
#ghStarLink:hover::after,
#ghStarLink:focus-visible::after {
  transform: translateY(0);
}

/* Tooltips inside the tag/color rows sit above instead of below (avoid clipping at list edges) */
.tag-row [data-tooltip]::after {
  top: auto;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
}
.tag-row [data-tooltip]:hover::after,
.tag-row [data-tooltip]:focus-visible::after {
  transform: translateX(-50%) translateY(0);
}

#ghStarLink { padding: 0.45rem 0.7rem; }
#ghStarCount {
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#ghStarCount:empty { display: none; }

/* ---------- Tag list (forum tags) ---------- */
.tag-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.tag-row {
  display: flex;
  gap: 0.4rem;
}

.tag-row .input { flex: 1; }

/* ---------- Toggle helper for radio-style selects ---------- */
.inline-hint {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

/* ---------- Code panel ---------- */
.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid hsl(0 0% 100% / 0.08);
}

.code-toolbar-title {
  font-size: 0.78rem;
  color: hsl(var(--code-fg) / 0.6);
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-toolbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Code panel is always dark regardless of site theme, so its buttons
   need fixed colors instead of the theme-linked --foreground/--border. */
.code-toolbar .btn-outline {
  border-color: hsl(0 0% 100% / 0.15);
  color: hsl(var(--code-fg));
}
.code-toolbar .btn-outline:hover {
  background: hsl(0 0% 100% / 0.08);
}
.code-toolbar .btn-primary {
  background: hsl(var(--code-fg));
  color: hsl(var(--code-bg));
}

.code-scroll {
  flex: 1;
  overflow: auto;
  padding: 1rem 1.1rem 2rem;
}

.code-scroll pre {
  margin: 0;
}

.code-scroll code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  color: hsl(var(--code-fg));
  white-space: pre;
}

.tok-keyword { color: hsl(var(--code-keyword)); }
.tok-string { color: hsl(var(--code-string)); }
.tok-number { color: hsl(var(--code-number)); }
.tok-comment { color: hsl(var(--code-comment)); font-style: italic; }
.tok-func { color: hsl(var(--code-func)); }
.tok-punct { color: hsl(var(--code-punct)); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  padding: 0.55rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  box-shadow: 0 8px 24px hsl(0 0% 0% / 0.25);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Icon button visuals for theme toggle ---------- */
.icon-sun, .icon-moon {
  display: none;
}
:root[data-theme="dark"] .icon-moon,
:root:not([data-theme="light"]) .icon-moon { display: block; }
:root[data-theme="dark"] .icon-sun,
:root:not([data-theme="light"]) .icon-sun { display: none; }
:root[data-theme="light"] .icon-sun { display: block; }
:root[data-theme="light"] .icon-moon { display: none; }

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .icon-sun { display: block; }
  :root:not([data-theme]) .icon-moon { display: none; }
}

/* ---------- Footer note ---------- */
.footnote {
  font-size: 0.72rem;
  color: hsl(var(--muted-foreground));
  text-align: center;
  padding: 0.5rem 1.25rem 1.5rem;
  line-height: 1.9;
}

.footnote a {
  color: hsl(var(--muted-foreground));
  text-decoration: underline;
  text-underline-offset: 2px;
}
.footnote a:hover { color: hsl(var(--foreground)); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .social-link { display: none; }
  .topbar-title span:last-child > span { display: none; }
}

@media (max-width: 900px) {
  .tabbar { display: flex; }

  .layout {
    grid-template-columns: 1fr;
  }

  .panel-code {
    position: static;
    height: auto;
    min-height: calc(100vh - 104px);
    margin: 0;
    border: none;
    border-radius: 0;
    border-top: 1px solid hsl(var(--border));
  }

  .layout[data-tab="form"] .panel-code { display: none; }
  .layout[data-tab="code"] .panel-form { display: none; }

  .field-row { grid-template-columns: 1fr; }
}
