/* Kilim — Anatolian kilim pattern generator */

* { box-sizing: border-box; }

:root {
  --bg: #070a12;
  --bg2: #0c1120;
  --panel: #0e1424;
  --line: #1c2438;
  --ink: #e8e4d8;
  --dim: #8b90a0;
  --gold: #f4c15d;
  --red: #b0483c;
}

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 13px;
}

/* ---------- header ---------- */

.top {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
}
.top__home {
  color: var(--dim); text-decoration: none; font-size: 12px; white-space: nowrap;
}
.top__home:hover { color: var(--gold); }
.top__brand {
  font-family: "Marcellus", serif;
  font-size: 21px; font-weight: 400; margin: 0; letter-spacing: 0.06em;
  color: var(--gold);
}
.top__sub { color: var(--dim); font-size: 11px; margin-right: auto; }
.top__actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

button {
  font: inherit; cursor: pointer;
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 12px;
  transition: border-color .15s, color .15s, background .15s;
}
button:hover { border-color: var(--gold); color: var(--gold); }
.btn--gold { background: var(--gold); color: #201607; border-color: var(--gold); font-weight: 600; }
.btn--gold:hover { background: #ffd47a; color: #201607; }

/* ---------- layout ---------- */

.wrap {
  display: flex; align-items: flex-start; gap: 18px;
  padding: 16px; max-width: 1500px; margin: 0 auto;
}
.panel {
  width: 318px; flex: 0 0 318px;
  display: flex; flex-direction: column; gap: 10px;
  position: sticky; top: 62px;
  max-height: calc(100vh - 78px);
  overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  padding-right: 2px;
}
.stage {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
#rug svg {
  display: block;
  border-radius: 3px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55), 0 4px 16px rgba(0,0,0,.4);
}

/* ---------- panel sections ---------- */

details.sec {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px;
}
details.sec > summary {
  cursor: pointer; list-style: none;
  font-family: "Marcellus", serif; font-size: 15px; letter-spacing: .05em;
  color: var(--gold);
  display: flex; align-items: center; gap: 8px;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after {
  content: "▾"; margin-left: auto; color: var(--dim); font-size: 11px;
  transition: transform .15s;
}
details.sec:not([open]) > summary::after { transform: rotate(-90deg); }
.sec__body { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }

.row { display: flex; align-items: center; gap: 10px; }
.row > label { color: var(--dim); font-size: 11px; width: 74px; flex: 0 0 74px; }
.row > output { width: 44px; text-align: right; color: var(--gold); font-size: 11px; }
input[type="range"] { flex: 1; accent-color: var(--gold); min-width: 0; }

.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checks label {
  display: flex; align-items: center; gap: 6px;
  color: var(--dim); font-size: 11px; cursor: pointer;
}
.checks input { accent-color: var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 4px 9px; font-size: 11px; border-radius: 999px; color: var(--dim); }
.chips button:hover { color: var(--gold); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 12px; font-size: 11px; color: var(--dim); }
.seg .seg--on { background: var(--gold); color: #201607; }

/* motif thumbnails — scrollable drawers, room for the library to grow */
#motifLib, #customList, #hiddenList {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px;
  max-height: 380px; overflow-y: auto; padding: 2px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
#customList:empty, #hiddenList:empty, .sellist:empty { display: none; }
.thumb--hidden { opacity: 0.55; }
.thumb--hidden:hover { opacity: 1; }

/* Z/B placement chips on library thumbs */
.thumb__where { display: flex; gap: 3px; margin-top: 1px; }
.wchip {
  font-style: normal; font-size: 8px; line-height: 13px;
  min-width: 16px; padding: 0 2px; text-align: center; cursor: pointer;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg); color: var(--dim); opacity: 0.55;
}
.wchip--sug { opacity: 1; border-color: var(--dim); }
.wchip--z.wchip--on { background: var(--gold); border-color: var(--gold); color: #201607; opacity: 1; }
.wchip--b.wchip--on { background: #5f8fb4; border-color: #5f8fb4; color: #0b1017; opacity: 1; }
.wchip:hover { border-color: var(--gold); opacity: 1; }

/* selected-motif rows with individual scale sliders */
.sellist { display: flex; flex-direction: column; gap: 6px; }
.selrow {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg2); border-radius: 8px; padding: 4px 8px 6px 4px;
}
.selrow__hd { display: flex; align-items: center; gap: 8px; }
.selrow__th .thumb__svg { width: 34px; height: 22px; display: block; border-radius: 4px; }
.selrow__nm {
  font-size: 10px; color: var(--dim); flex: 1 1 auto; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.selrow__sz { display: flex; align-items: center; gap: 8px; }
.selrow__sz input[type="range"] { flex: 1; min-width: 0; }
.numk {
  flex: 0 0 52px; width: 52px; font: inherit; font-size: 10px;
  background: var(--bg); color: var(--gold); text-align: right;
  border: 1px solid var(--line); border-radius: 5px; padding: 2px 4px;
}
.numk:focus { border-color: var(--gold); outline: none; }
.selrow__x {
  padding: 0; width: 20px; height: 20px; line-height: 1;
  font-size: 12px; border-radius: 5px; color: var(--dim); flex: 0 0 20px;
}
.selrow__x:hover { color: #e05252; }
.selrow__mv { font-size: 8px; }
.selrow__mv:hover { color: var(--gold); }
.selrow__mv:disabled { opacity: 0.25; cursor: default; }
.selrow__mv:disabled:hover { color: var(--dim); border-color: var(--line); }

/* text sections */
#textSecs { display: flex; flex-direction: column; gap: 10px; }
.textsec { display: flex; flex-direction: column; gap: 6px; }
.textsec__row { display: flex; align-items: center; gap: 8px; }
.textsec__row select { flex: 1 1 auto; min-width: 0; padding: 3px 6px; font-size: 11px; }
#bandPicker { max-height: 246px; }
.thumb {
  position: relative; min-width: 0;
  padding: 4px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: var(--bg2); border-radius: 8px;
}
.thumb span {
  font-size: 8.5px; color: var(--dim); letter-spacing: 0; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.thumb__n {
  position: absolute; top: 2px; right: 2px;
  font-style: normal; font-size: 9px; line-height: 14px;
  width: 14px; text-align: center;
  background: var(--gold); color: #201607; border-radius: 50%;
}
.thumb--on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.thumb--on span { color: var(--gold); }
.thumb__svg { width: 100%; height: 40px; border-radius: 4px; }
.thumb--sm { padding: 3px; }
.thumb--sm .thumb__svg { height: 26px; width: 40px; }

.bandrow { display: flex; align-items: center; gap: 8px; }
.bandrow > label { color: var(--dim); font-size: 11px; flex: 0 0 10px; }
.bandrow__strip {
  display: flex; gap: 5px; overflow-x: auto; min-width: 0;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
  padding-bottom: 3px;
}
.bandrow__strip .thumb { flex: 0 0 auto; }

/* palettes */
#palettes { display: flex; flex-wrap: wrap; gap: 6px; }
.pal {
  display: flex; align-items: center; gap: 7px; padding: 5px 9px;
  background: var(--bg2); border-radius: 999px; font-size: 11px; color: var(--dim);
}
.pal--on { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.pal__sw { display: inline-flex; border-radius: 4px; overflow: hidden; }
.pal__sw i { width: 10px; height: 14px; display: inline-block; }

#colorInputs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.cinp { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 10.5px; cursor: pointer; }
.cinp input {
  width: 26px; height: 20px; padding: 0; border: 1px solid var(--line);
  border-radius: 5px; background: none; cursor: pointer;
}

select {
  font: inherit; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; padding: 4px 8px;
}

.tinput {
  font: inherit; width: 100%;
  background: var(--bg2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 10px;
}
.tinput:focus { outline: none; border-color: var(--gold); }
.tinput::placeholder { color: var(--dim); opacity: .6; }
textarea.tinput { resize: vertical; min-height: 44px; line-height: 1.45; }

.cpick {
  width: 44px; height: 24px; padding: 0;
  border: 1px solid var(--line); border-radius: 6px;
  background: none; cursor: pointer;
}

.hint { font-size: 10.5px; color: var(--dim); line-height: 1.5; margin: 0; }

/* custom-motif thumb tools */
.thumb__tool {
  position: absolute; top: 2px; left: 2px;
  font-style: normal; font-size: 10px; line-height: 14px;
  width: 15px; text-align: center; cursor: pointer;
  background: var(--bg); color: var(--dim); border-radius: 4px;
  opacity: 0; transition: opacity .12s;
}
.thumb__tool--del { left: auto; right: 2px; top: 18px; }
.thumb:hover .thumb__tool { opacity: 1; }
.thumb__tool:hover { color: var(--gold); }
.thumb__tool--del:hover { color: #e05252; }

/* atölye editor modal */
#editor {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 5, 9, 0.78);
}
#editor[hidden] { display: none; }
.editor__panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
  max-width: 94vw; max-height: 92vh; overflow: auto;
}
.editor__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tinput--name { width: 150px; }
.emdim { color: var(--dim); font-size: 11px; display: flex; align-items: center; gap: 4px; }
.emdim input {
  width: 46px; font: inherit; background: var(--bg2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
.editor__slots { display: inline-flex; gap: 5px; margin-left: auto; }

/* edge-resize arrows around the editor canvas */
.emwrap {
  display: grid; grid-template-columns: auto auto auto;
  justify-items: center; align-items: center; gap: 5px;
  align-self: center;
}
.emedge { display: flex; gap: 4px; }
.emedge--t { grid-column: 2; grid-row: 1; }
.emedge--l { grid-column: 1; grid-row: 2; flex-direction: column; }
.emedge--r { grid-column: 3; grid-row: 2; flex-direction: column; }
.emedge--b { grid-column: 2; grid-row: 3; }
.emwrap canvas { grid-column: 2; grid-row: 2; }
.emedge button {
  width: 24px; height: 24px; padding: 0;
  font-size: 14px; line-height: 1; border-radius: 6px; color: var(--dim);
}
.emedge button:hover { color: var(--gold); }

/* overwrite confirmation */
.emconfirm {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.emconfirm[hidden] { display: none; }
.emconfirm p { margin: 0; font-size: 12px; color: var(--dim); line-height: 1.5; }
.emconfirm b { color: var(--gold); font-weight: 600; }
.emconfirm__btns { display: flex; gap: 8px; }
.emslot {
  width: 26px; height: 22px; padding: 0; border-radius: 5px;
  border: 1px solid var(--line); cursor: pointer;
}
.emslot--on { outline: 2px solid var(--gold); outline-offset: 1px; }
#emCanvas {
  align-self: center; cursor: crosshair;
  border: 1px solid var(--line); border-radius: 6px;
  image-rendering: pixelated; touch-action: none;
}
.editor__foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.editor__foot .checks { margin-right: auto; border-radius: 6px; padding: 2px 4px; }
.checks--warn { outline: 2px solid #e05252; }
.checks--warn label { color: #e05252; }

/* ---------- mobile ---------- */

@media (max-width: 860px) {
  .wrap { flex-direction: column-reverse; }
  .panel { width: 100%; flex: none; position: static; max-height: none; }
  .top { flex-wrap: wrap; gap: 8px; }
  .top__sub { display: none; }
  #fieldPicker { grid-template-columns: repeat(5, 1fr); }
}
