:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe7d6;
  --text: #1f1d1a;
  --muted: #6b645a;
  --border: #ddd2bd;
  --ink: #1b2a6b;
  --ink-text: #ffffff;
  --ok: #1e7a46;
  --ok-bg: #e3f3e8;
  --warn: #8a5a00;
  --warn-bg: #fdf0d2;
  --bad: #a3231b;
  --bad-bg: #fbe3e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme='light']) {
    --bg: #15161b;
    --surface: #1e2027;
    --surface-2: #272a33;
    --text: #ece8df;
    --muted: #a39d92;
    --border: #353844;
    --ink: #8da2ff;
    --ink-text: #10132a;
    --ok: #6fd39a;
    --ok-bg: #173325;
    --warn: #f0c060;
    --warn-bg: #3a2e14;
    --bad: #ff8f84;
    --bad-bg: #3d1c1a;
    color-scheme: dark;
  }
}

:root[data-scheme='dark'] {
  --bg: #15161b;
  --surface: #1e2027;
  --surface-2: #272a33;
  --text: #ece8df;
  --muted: #a39d92;
  --border: #353844;
  --ink: #8da2ff;
  --ink-text: #10132a;
  --ok: #6fd39a;
  --ok-bg: #173325;
  --warn: #f0c060;
  --warn-bg: #3a2e14;
  --bad: #ff8f84;
  --bad-bg: #3d1c1a;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', 'Noto Sans Thai', 'Leelawadee UI', Roboto, sans-serif;
}
a { color: var(--ink); }
[hidden] { display: none !important; }

.top, main, .privacy, .foot { max-width: 880px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.top { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding-top: 20px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.tagline { margin: 0; color: var(--muted); font-size: 0.92rem; }
.switches { display: flex; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; color: var(--text); padding: 6px 12px; font: inherit; font-size: 0.85rem; cursor: pointer; }
.seg button[aria-pressed='true'] { background: var(--ink); color: var(--ink-text); }
.privacy { color: var(--muted); font-size: 0.9rem; margin-top: 12px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin: 16px 0; }
.panel h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 1.2rem; }
.num { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--ink-text); font-size: 0.9rem; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.right { text-align: right; margin: 0; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; font-size: 0.92rem; }
.field > span { color: var(--muted); }
input[type='text'], input[type='password'], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, .btn:focus-within, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--ink) 45%, transparent);
  outline-offset: 2px;
}
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.grow { flex: 1 1 220px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 12px; font-size: 0.92rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 16px; border-radius: 999px; font: inherit; font-size: 0.95rem; cursor: pointer; text-decoration: none;
  min-height: 42px;
}
.btn:hover { filter: brightness(0.97); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--ink-text); }
.btn.big { width: 100%; font-size: 1.05rem; min-height: 50px; }
.btn.end { margin-bottom: 12px; }
.btn:disabled { opacity: 0.55; cursor: wait; }
.buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.link-btn { border: 0; background: none; color: var(--ink); text-decoration: underline; cursor: pointer; font: inherit; padding: 4px; }

.msg { margin: 6px 0; font-size: 0.92rem; min-height: 1em; }
.msg:empty { display: none; }
.msg.ok { color: var(--ok); }
.msg.warn { color: var(--warn); }
.msg.bad { color: var(--bad); }
.banner { border-radius: 10px; padding: 10px 14px; margin: 0 0 12px; font-size: 0.92rem; }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.warn-list { margin: 0; padding-left: 20px; color: var(--warn); font-size: 0.9rem; }

/* theme picker */
.themes { border: 0; padding: 0; margin: 6px 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.themes legend { color: var(--muted); font-size: 0.92rem; margin-bottom: 6px; padding: 0; }
.theme-card { position: relative; display: flex; flex-direction: column; gap: 2px; padding: 10px; border: 2px solid var(--border); border-radius: 10px; cursor: pointer; background: var(--bg); }
.theme-card:has(input:checked) { border-color: var(--ink); }
.theme-card:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--ink) 45%, transparent); }
.theme-card input { position: absolute; opacity: 0; }
.theme-card small { color: var(--muted); line-height: 1.35; }
.mini { display: grid; height: 74px; border-radius: 6px; overflow: hidden; padding: 6px; gap: 4px; margin-bottom: 6px; }
.mini i { display: block; border-radius: 2px; }
.mini-masonry { background: #faf8f4; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 14px; }
.mini-masonry i { background: #cdbfa6; }
.mini-masonry i:nth-child(1) { grid-row: span 2; }
.mini-masonry i:nth-child(2) { grid-row: span 3; background: #9fb0d8; }
.mini-masonry i:nth-child(3) { grid-row: span 2; background: #e0a43a; }
.mini-masonry i:nth-child(5) { grid-row: span 2; background: #9fb0d8; }
.mini-minimal { background: #fff; justify-items: center; grid-template-rows: 1fr 1fr; }
.mini-minimal i { width: 60%; background: #c9c9c9; }
.mini-minimal i:first-child { background: #8e8e8e; }
.mini-dark { background: #0e0e10; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.mini-dark i { background: #3a3a44; }
.mini-dark i:nth-child(2n) { background: #5a5f7a; }

/* works */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 20px 12px; text-align: center; background: var(--bg); transition: border-color 0.2s, background 0.2s; }
.drop.over { border-color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, var(--bg)); }
.drop-hint { margin: 0 0 10px; font-weight: 600; }
.works { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.work-item { display: grid; grid-template-columns: auto 88px 1fr auto; gap: 10px; align-items: start; padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.work-item.dragging { opacity: 0.4; }
.work-item.drop-before { box-shadow: 0 -3px 0 var(--ink); }
.work-item.drop-after { box-shadow: 0 3px 0 var(--ink); }
.handle { cursor: grab; color: var(--muted); padding: 6px 2px; user-select: none; font-size: 1.2rem; line-height: 1; }
.work-item img { width: 88px; height: 88px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.work-fields { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.work-fields input, .work-fields textarea { padding: 6px 9px; font-size: 0.92rem; }
.work-fields .meta { font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-tools { display: flex; flex-direction: column; gap: 4px; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 0.95rem; }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

progress { width: 100%; height: 10px; margin-top: 12px; accent-color: var(--ink); }
#result { margin-top: 12px; }
#preview { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: 10px; margin-top: 8px; background: #fff; }

.foot { color: var(--muted); font-size: 0.88rem; padding-bottom: 40px; }
.foot p { margin: 4px 0; }

@media (max-width: 560px) {
  .panel { padding: 16px 14px; }
  .work-item { grid-template-columns: 64px 1fr auto; }
  .work-item .handle { display: none; }
  .work-item img { width: 64px; height: 64px; }
}
