/*
 * Noto Sans Thai, self-hosted so the page makes no third-party request — the
 * Worker already serves these from the edge. Variable weight 100-900, split by
 * the same unicode-ranges Google Fonts uses so a Thai reader never downloads
 * the latin-ext subset. Licensed under the SIL OFL 1.1 (see fonts/OFL.txt).
 */
@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('./fonts/noto-sans-thai-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}

@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('./fonts/noto-sans-thai-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304,
    U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0,
    U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('./fonts/noto-sans-thai-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215,
    U+FEFF, U+FFFD;
}

:root {
  --bg: #0e1013;
  --panel: #171b20;
  --panel-2: #1e242b;
  --line: #2b333c;
  --text: #e7ecf1;
  --muted: #93a1b0;
  --accent: #4da3ff;
  --radius: 10px;
  --font: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  /* Thai needs more leading than the 1.5 that suits Latin — tone marks stack above
     the baseline and clip against the line above at tighter values. */
  font: 14px/1.7 var(--font);
}

.topbar {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.topbar h1 { margin: 0 0 4px; font-size: 18px; letter-spacing: 0.2px; }
.topbar p { margin: 0; color: var(--muted); }

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 40px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

@media (max-width: 900px) {
  .panel { position: static; max-height: none; }
}

.field { margin-bottom: 18px; }
.field > label { display: block; margin-bottom: 6px; font-weight: 600; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.times { color: var(--muted); }

input[type="number"],
input[type="text"],
select {
  width: 100%;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
}

input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="file"] { width: 100%; color: var(--muted); font-size: 12px; }

.ratios { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.ratios label {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 7px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.ratios label:has(input:checked) { border-color: var(--accent); }
.ratios input { accent-color: var(--accent); }
.ratios span { font-variant-numeric: tabular-nums; }

.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400 !important; }
.check input { margin-top: 3px; accent-color: var(--accent); }

button {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #06121f;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button.secondary { background: var(--panel-2); border-color: var(--line); color: var(--text); }

.linkbtn {
  display: inline-block;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.linkbtn[aria-disabled] { opacity: 0.4; pointer-events: none; }

#apiUrl { font-family: var(--font-mono); font-size: 12px; }
button.ghost { background: transparent; border-color: var(--line); color: var(--muted); font-weight: 500; }
button:hover { filter: brightness(1.08); }

.actions { display: grid; gap: 8px; }
.actions button { width: 100%; }

.preview { display: grid; gap: 16px; min-width: 0; }

.stage {
  background:
    repeating-conic-gradient(#20262d 0% 25%, #171b20 0% 50%) 0 0 / 24px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  justify-content: center;
}

#canvas {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
}

.specs {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.specs th,
.specs td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.specs th { color: var(--muted); font-weight: 600; font-size: 12px; }
.specs tr:last-child td { border-bottom: none; }
