@font-face { font-family: "tulu-baravu"; src: url("fonts/baravu.otf"); font-display: block; }
@font-face { font-family: "tulu-mandara"; src: url("fonts/mandara.ttf"); font-display: block; }
@font-face { font-family: "tulu-allige"; src: url("fonts/allige.ttf"); font-display: block; }

:root {
  --bg: #ffffff;
  --surface: #faf7f2;
  --line: #d6c4a8;
  --ink: #451b10;
  --text: #3f4545;
  --muted: #6b7373;
  --placeholder: #9a958c;
  --accent: #a91100;
  --accent-hover: #8e0e00;
  --accent-soft: #f6ebe8;
  --radius: 5px;
  --control-h: 36px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", "Nirmala UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-size: 16px; font-weight: 700; color: var(--ink); text-decoration: none; }
.topbar-link { color: var(--muted); text-decoration: none; font-weight: 500; }
.topbar-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

/* Layout */
.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: grid;
  grid-template-columns: minmax(0, 380px) minmax(0, 1fr);
  gap: 48px;
  align-items: start;
}

.intro { margin-bottom: 24px; }
.intro h1 { font-size: 22px; line-height: 1.25; font-weight: 700; color: var(--ink); }
.intro p { margin-top: 6px; color: var(--muted); }
.intro code, .code {
  font-family: var(--mono);
}
.intro code {
  font-size: 0.92em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0 4px;
  border-radius: 3px;
}

/* Groups */
.group { padding: 22px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.group-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
}
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.muted { color: var(--muted); }

textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  padding: 12px 14px;
  font-size: 16px;
  line-height: 1.6;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
textarea::placeholder { color: var(--placeholder); }
textarea.is-code { font-family: var(--mono); font-size: 15px; }

.code-row { display: flex; align-items: baseline; gap: 10px; font-size: 13px; min-height: 20px; }
.code {
  flex: 1;
  min-width: 0;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Label + control rows */
.row { display: flex; align-items: center; gap: 12px; min-height: var(--control-h); }
.row > label, .row-label { width: 104px; flex-shrink: 0; white-space: nowrap; }
.row .segmented { flex: 1; }

/* Segmented control */
.segmented {
  display: flex;
  height: var(--control-h);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.segmented button { flex: 1; padding: 0 12px; font-weight: 500; white-space: nowrap; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button:hover { background: var(--surface); }
.segmented button:focus-visible { outline-offset: -2px; }
.segmented button[aria-checked="true"] { background: var(--ink); color: #fff; }
.segmented-sm { height: 28px; }
.segmented-sm button { padding: 0 10px; font-size: 12px; }
.group-head .segmented { flex: 0 0 auto; }

/* Range */
input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 20px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--line); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  border: 0;
}
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 0; }
input[type="range"]:disabled { cursor: not-allowed; }
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--line); }
input[type="range"]:disabled::-moz-range-thumb { background: var(--line); }
input:disabled { cursor: not-allowed; }

/* Number + hex inputs */
.num, .hex {
  height: var(--control-h);
  width: 68px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.num-wide { flex: 1; width: auto; min-width: 0; text-align: left; }
.hex { flex: 1; min-width: 0; text-align: left; text-transform: uppercase; }
.num:focus, .hex:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.num:disabled { color: var(--muted); background: var(--surface); }

input[type="color"] {
  width: var(--control-h); height: var(--control-h);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 4px; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 2px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 2px; }

/* Checkbox */
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; width: max-content; min-height: 24px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

/* Swatches */
.swatches { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; }
.swatch { width: 100%; aspect-ratio: 1; border-radius: var(--radius); border: 1px solid rgba(0, 0, 0, 0.1); }
.swatch[data-swatch="#ffffff"] { border-color: var(--line); }
.swatch[aria-checked="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Presets */
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }

.editor-foot { padding-top: 8px; display: flex; justify-content: flex-end; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 13px; }
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.muted-link { color: var(--muted); font-weight: 500; }

/* Preview */
.preview { position: sticky; top: 24px; display: grid; gap: 16px; }
.stage {
  position: relative;
  min-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background-color: #ffffff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Crect width='8' height='8' fill='%23f1eee9'/%3E%3Crect x='8' y='8' width='8' height='8' fill='%23f1eee9'/%3E%3C/svg%3E");
  overflow: hidden;
}
.stage.is-solid { background-image: none; background-color: var(--surface); }
.stage canvas { --max-h: 70; display: block; max-width: 100%; object-fit: contain; }
.stage.is-empty canvas { display: none; }
.empty { display: none; color: var(--muted); text-align: center; }
.stage.is-empty .empty { display: block; }

.actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta.is-off { visibility: hidden; }
.buttons { display: flex; gap: 8px; }

.btn {
  height: 40px;
  padding: 0 18px;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--bg);
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled, .btn:disabled:hover {
  background: var(--surface);
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 8px);
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Single column */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 20px 16px 48px; }
  .topbar-inner { padding: 12px 16px; }
  .editor { display: contents; }
  .intro { order: -3; margin-bottom: 20px; }
  .group-text { order: -2; }
  .preview {
    order: -1;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg);
    padding: 12px 0 16px;
    gap: 12px;
    border-bottom: 1px solid var(--line);
  }
  .preview { padding: 8px 0 12px; }
  .stage { min-height: 120px; padding: 12px; }
  .stage canvas { --max-h: 22; }
  .meta { display: none; }
  .group-text + .group { border-top: 0; }
  .actions { gap: 12px; }
  .buttons { flex: 1 1 100%; }
  .buttons .btn { flex: 1; }
  .segmented-sm { height: 34px; }
  .segmented-sm button { padding: 0 12px; }
  .row > label, .row-label { width: 96px; }
  input[type="range"] { height: 28px; }
  input[type="range"]::-webkit-slider-thumb { width: 20px; height: 20px; margin-top: -9px; }
  input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; }
}
