/* ---------- Fonts (self-hosted, no CDN) ---------- */
@font-face { font-family: "Noto Sans Tagalog"; src: url("fonts/noto-sans-tagalog.woff2") format("woff2"); font-weight: 400; font-display: block; unicode-range: U+1700-171F, U+1735-1736, U+200B-200D, U+25CC; }
@font-face { font-family: "Cormorant Garamond"; src: url("fonts/cormorant-garamond-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Cormorant Garamond"; src: url("fonts/cormorant-garamond-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Cormorant Garamond"; src: url("fonts/cormorant-garamond-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Cormorant Garamond"; src: url("fonts/cormorant-garamond-latin-500-italic.woff2") format("woff2"); font-weight: 500; font-style: italic; font-display: swap; }
@font-face { font-family: "Poppins"; src: url("fonts/poppins-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Poppins"; src: url("fonts/poppins-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Poppins"; src: url("fonts/poppins-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --bg: #f4ede1;
  --paper: #fffaf1;
  --ink: #1f1a14;
  --muted: #7a6a58;
  --line: #e3d6c2;
  --accent: #b4452a;
  --accent-ink: #fff;
  --gold: #c98f2a;
  --radius: 14px;
  --bb: "Noto Sans Tagalog", "Poppins", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Poppins", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, #f9e3c4 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Header ---------- */
.top { padding: 22px clamp(16px, 4vw, 40px) 8px; }
.brand { display: flex; align-items: center; gap: 16px; }
.brand-mark {
  font-family: var(--bb); font-size: 30px; line-height: 1;
  background: var(--ink); color: #e8b04a; padding: 12px 14px; border-radius: 14px;
}
.brand h1 { font-family: "Cormorant Garamond", serif; font-weight: 600; font-size: 34px; margin: 0; letter-spacing: .5px; }
.brand p { margin: 2px 0 0; color: var(--muted); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
  gap: 24px;
  padding: 16px clamp(16px, 4vw, 40px) 24px;
  align-items: start;
}
.controls { display: flex; flex-direction: column; gap: 16px; }
.preview-wrap { position: sticky; top: 16px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .preview-wrap { position: static; order: -1; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03), 0 8px 24px -16px rgba(60,40,20,.25);
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card h2 { font-size: 15px; font-weight: 600; margin: 0; }
.step {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--ink); color: #f4d48a;
}

textarea, input[type=text], select {
  width: 100%; font: inherit; color: inherit;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea { font-size: 16px; resize: vertical; min-height: 70px; }
textarea:focus, input[type=text]:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,143,42,.18); }
input[type=text] { margin-top: 8px; }

label { display: block; font-size: 12.5px; color: var(--muted); }
label > select { margin-top: 4px; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }

.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; color: var(--ink); font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.range { margin-top: 10px; color: var(--ink); font-size: 13px; }
.range output { float: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.range input { width: 100%; accent-color: var(--accent); margin-top: 4px; }

.colors { display: flex; gap: 16px; margin-top: 8px; }
.colors label { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.colors input[type=color] { width: 36px; height: 28px; border: 1px solid var(--line); border-radius: 6px; padding: 0; background: none; cursor: pointer; }

.hint { color: var(--muted); font-size: 12px; line-height: 1.5; margin: 10px 0 0; }

/* ---------- Chips / output ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font: inherit; font-size: 12px; border: 1px solid var(--line); background: #fff;
  padding: 4px 10px; border-radius: 999px; cursor: pointer; color: var(--ink);
}
.chip:hover { border-color: var(--gold); }

.result { margin-top: 14px; background: #1f1a14; color: #f6e7c8; border-radius: 12px; padding: 12px 14px; }
.result-top { display: flex; justify-content: space-between; align-items: center; }
.result .label { font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: #c9b48a; }
.bb-out { font-family: var(--bb); font-size: 40px; line-height: 1.6; min-height: 64px; word-break: break-word; white-space: pre-wrap; }
.syllables { font-size: 12px; color: #c9b48a; letter-spacing: .3px; }

.opts { margin-top: 12px; }
.opts summary, .ref summary { cursor: pointer; font-weight: 500; font-size: 13px; list-style: none; }
.opts summary::before, .ref summary::before { content: "▸ "; color: var(--gold); }
.opts[open] summary::before, .ref[open] summary::before { content: "▾ "; }
.opts .grid2 { margin-top: 10px; }
.ref summary h2 { display: inline; }

/* ---------- Buttons ---------- */
button { font: inherit; cursor: pointer; }
.ghost { background: transparent; border: 1px solid rgba(255,255,255,.25); color: inherit; border-radius: 8px; padding: 4px 10px; }
.ghost:hover { border-color: #e8b04a; }
.small { font-size: 12px; }
.primary {
  width: 100%; border: 0; border-radius: 12px; padding: 13px 16px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 16px -8px rgba(180,69,42,.8);
  transition: transform .08s, filter .15s;
}
.primary:hover { filter: brightness(1.07); }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: .6; cursor: progress; }

.seg { display: flex; background: #f1e7d6; border-radius: 10px; padding: 3px; gap: 3px; margin-bottom: 8px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 4px; border-radius: 8px; font-weight: 500; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.dims { color: var(--muted); font-size: 12px; margin: 6px 0 12px; font-variant-numeric: tabular-nums; }

/* ---------- Design gallery ---------- */
.designs { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.design {
  border: 2px solid transparent; border-radius: 12px; padding: 0; background: none;
  text-align: left; overflow: hidden; position: relative;
  box-shadow: 0 0 0 1px var(--line);
  transition: transform .12s, box-shadow .12s;
}
.design:hover { transform: translateY(-2px); }
.design.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(180,69,42,.2); }
.design canvas { display: block; width: 100%; aspect-ratio: 1; }
.design .dn { display: block; padding: 6px 8px 7px; background: #fff; font-size: 12px; font-weight: 600; line-height: 1.2; }
.design .ds { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.checker, .design canvas.checker {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e8e2d8 25%, transparent 25%), linear-gradient(-45deg, #e8e2d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e2d8 75%), linear-gradient(-45deg, transparent 75%, #e8e2d8 75%);
  background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

/* ---------- Preview ---------- */
.preview {
  background: #2a241d; border-radius: 18px; padding: clamp(14px, 3vw, 32px);
  display: grid; place-items: center;
  min-height: 300px; max-height: calc(100vh - 120px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.05);
}
.preview canvas {
  display: block; max-width: 100%; max-height: calc(100vh - 190px);
  width: auto; height: auto; border-radius: 6px;
  box-shadow: 0 20px 50px -20px rgba(0,0,0,.7);
}
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.preview-bar span { color: var(--muted); font-size: 13px; }
.preview-bar .primary { width: auto; padding: 10px 22px; }

/* ---------- Letter guide ---------- */
.refgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; margin-top: 12px; }
.refgrid div { background: #fff; border: 1px solid var(--line); border-radius: 8px; text-align: center; padding: 6px 2px; }
.refgrid b { display: block; font-family: var(--bb); font-weight: 400; font-size: 26px; line-height: 1.5; }
.refgrid span { font-size: 11px; color: var(--muted); }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 32px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
