:root {
  --bg: #12110f;
  --panel: #1a1815;
  --line: #3a332c;
  --text: #f3eee6;
  --muted: #9d9388;
  --accent: #e28a45;
  --accent-ink: #2a160c;
  --danger: #d4544a;
  --field: #100e0c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", Aptos, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
}

.top {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #171512;
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 {
  margin: 0;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.brand p { margin: 0; color: var(--muted); font-size: 13px; }

.top-actions { display: flex; gap: 8px; }
.language-control select { max-width: 155px; height: 100%; min-height: 38px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--field); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
#share-dialog { width: min(540px, calc(100vw - 32px)); }
#share-url { width: 100%; margin-block: 8px 16px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); }
#share-status { white-space: pre-line; }
html[dir="rtl"] .panel, html[dir="rtl"] dialog { text-align: right; }
html[dir="rtl"] input[type="number"], html[dir="rtl"] output, html[dir="rtl"] .anchor-grid, html[dir="rtl"] .logo-sides { direction: ltr; }
@media (max-width: 900px) { .top { flex-wrap: wrap; } .top-actions { flex-wrap: wrap; width: 100%; } .top-actions > * { flex: 1 1 auto; } .language-control select { width: 100%; max-width: none; } }

button {
  border: 1px solid var(--line);
  background: #241f1b;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
button:hover { border-color: #5a4e43; }
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}
button.ghost { background: transparent; }
button:disabled { opacity: 0.5; cursor: default; }

.panel {
  position: relative;
  z-index: 2;
  overflow: auto;
  border-right: 1px solid var(--line);
  padding: 8px 16px 24px;
  background: var(--panel);
}
.panel-tabs { position: sticky; top: -8px; z-index: 3; display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; background: var(--panel); padding: 10px 0; border-bottom: 1px solid var(--line); }
.panel-tabs button { background: transparent; border: 0; color: var(--muted); border-radius: 8px; }
.panel-tabs [aria-selected="true"] { background: #30251d; color: var(--accent); font-weight: 600; }
.label-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 18px; }
.label-heading h3 { margin: 0; font-size: 17px; font-weight: 600; }
.label-heading .note { font-size: 11px; margin: 5px 0; }
.panel-tabs button { padding: 9px 4px; font-size: 12px; }
.insert-plan-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.insert-plan-title h2 { margin: 0; }
.insert-plan-title button { padding: 5px 8px; font-size: 10px; }
#inserts-plan { display: block; width: 100%; max-height: 220px; margin-top: 12px; background: #111513; border: 1px solid #3a4943; border-radius: 10px; touch-action: none; cursor: crosshair; }
#inserts-plan .grid-cell { fill: #1e2925; stroke: #63776c; stroke-width: .22; }
#inserts-plan .grid-cell:hover { fill: #364b40; }
#inserts-plan text { pointer-events: none; fill: #b6c9bc; font-family: 'Segoe UI',sans-serif; }
#inserts-plan .insert-tile { cursor: grab; stroke: #0d1a15; stroke-width: .3; }
#inserts-plan .insert-tile.selected { stroke: #ffc491; stroke-width: .8; }
#inserts-plan:focus-visible { outline: 2px solid var(--accent); }
.insert-toolbar { display: flex; gap: 6px; margin: 9px 0; }
.insert-toolbar button { flex: 1; padding: 7px 5px; font-size: 11px; }
.insert-catalog { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
.insert-catalog button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 3px; font-size: 11px; background: var(--field); }
.insert-catalog button[aria-pressed="true"] { border-color: #64bdb0; background: #203530; }
.insert-catalog svg { width: 57px; height: 35px; fill: #4ba5a023; stroke: #78c1b5; stroke-width: 1.2; stroke-linejoin: round; }
.insert-catalog small { font-size: 9px; color: var(--muted); }
.insert-grid-settings { margin-top: 18px; }
#insert-inspector { border-top: 1px solid #4a675a; }
#inserts-status { white-space: pre-line; color: #acd6bb; padding-bottom: 8px; }
#inserts-status.danger { color: var(--danger); }
#insert-color { width: 100%; height: 34px; padding: 3px; }
.inserts-nav { grid-template-columns: repeat(2,1fr); }
#inlay-settings { border: 0; padding: 0; margin: 0; min-width: 0; }
#inlay-settings:disabled { opacity: .45; }
#inlay-color { width: 100%; height: 34px; padding: 3px; }
#inlay-status { white-space: pre-line; color: #acd6bb; }
#inlay-status.danger { color: var(--danger); }
#standard-size-settings { padding: 5px 10px; border: 1px solid #4e624f; border-radius: 10px; background: #19251e; margin: 10px 0; }
#standard-size-settings .note { font-size: 11px; }
.label-nav { position: sticky; top: 48px; z-index: 2; display: grid; grid-template-columns: repeat(3,1fr); gap: 3px; background: var(--field); padding: 4px; border: 1px solid var(--line); border-radius: 10px; margin-top: 14px; }
.label-nav button { border: 0; background: transparent; padding: 8px 3px; font-size: 11px; color: var(--muted); border-radius: 6px; }
.label-nav [aria-selected="true"] { background: #30251d; color: var(--accent); font-weight: 600; }
.section-choice { font-size: 13px; font-weight: 600; padding-top: 0 !important; margin-bottom: 9px; }
.relief-templates { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.relief-templates button { gap: 3px !important; padding: 10px 3px !important; font-size: 11px !important; }
.relief-templates svg { width: 70px; max-width: 100%; height: 43px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.relief-templates .relief-base { fill: currentColor; fill-opacity: .04; }
.relief-templates .relief-solid { fill: currentColor; fill-opacity: .17; }
.relief-templates small { font-size: 10px; color: var(--muted); }
.logo-drop { border: 1px dashed #594737; border-radius: 11px; background: #15120f; }
.icon-library-open { width: 100%; display: flex; align-items: center; gap: 10px; margin-bottom: 9px; padding: 11px; text-align: left; background: #30251d; border-color: #725437; }
.icon-library-open > svg { width: 27px; height: 27px; flex-shrink: 0; stroke: var(--accent); fill: none; stroke-width: 1.4; stroke-linejoin: round; }
.icon-library-open > span:first-of-type { flex: 1; font-size: 12px; }
.icon-library-open small { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
#icon-library { width: min(680px,calc(100vw - 28px)); max-height: calc(100dvh - 32px); padding: 22px; box-sizing: border-box; }
#icon-library[open] { display: flex; flex-direction: column; }
#icon-library .dialog-heading { flex-shrink: 0; }
.icon-search-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
#icon-search { width: 100%; background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; flex-shrink: 0; }
.icon-categories { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 0 2px; flex-shrink: 0; }
.icon-categories button { padding: 6px 10px; border-radius: 18px; background: var(--field); font-size: 11px; color: var(--muted); }
.icon-categories [aria-pressed="true"] { background: #30251d; border-color: var(--accent); color: var(--text); }
#icon-library-status { margin: 10px 0; font-size: 11px; min-height: 16px; flex-shrink: 0; }
#icon-library-status.danger { color: var(--danger); }
.icon-grid { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 7px; overflow-y: auto; min-height: 0; padding: 2px; align-content: start; }
.library-icon { min-height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; background: var(--field); padding: 10px 4px; }
.library-icon svg { width: 28px; height: 28px; flex-shrink: 0; fill: currentColor; color: #dfc7a8; }
.library-icon span { font-size: 10px; line-height: 1.25; min-height: 25px; display: flex; align-items: center; }
.library-icon[aria-pressed="true"] { border-color: var(--accent); background: #30251d; }
.library-icon:focus-visible, .icon-categories button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-library-credit { margin: 12px 0 0; color: var(--muted); font-size: 10px; flex-shrink: 0; }
@media (max-width: 560px) {
  #icon-library { padding: 16px; }
  .icon-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
}
.logo-drop.dragging { border-color: var(--accent); background: #30251d; }
.logo-upload { width: 100%; border: 0; background: transparent; display: flex; align-items: center; flex-direction: column; gap: 7px; padding: 17px 9px; font-size: 12px; }
.logo-upload svg { width: 31px; height: 31px; stroke: var(--accent); fill: none; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.logo-upload small { color: var(--muted); font-size: 10px; }
.logo-drop.has-logo .logo-upload { flex-direction: row; justify-content: center; padding: 8px; }
.logo-drop.has-logo .logo-upload svg { width: 20px; height: 20px; }
.logo-drop.has-logo .logo-upload small { display: none; }
.logo-file-row { display: flex; gap: 9px; align-items: center; margin: 12px 0; }
#logo-thumb { flex: 0 0 72px; border: 1px solid var(--line); border-radius: 7px; background: #ded7cc; }
.logo-file-row > div { flex: 1; min-width: 0; }
#logo-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 500; }
.icon-button { padding: 2px 7px; font-size: 21px; }
.logo-sides { display: grid; grid-template-columns: repeat(4,1fr); gap: 5px; margin: 12px 0 0; }
.logo-sides button { font-size: 10px; background: var(--field); color: var(--muted); padding: 7px 2px; display: flex; flex-direction: column; gap: 5px; align-items: center; }
.logo-sides [aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: #30251d; }
.logo-sides span { font-size: 15px; height: 28px; display: flex; align-items: center; }
.logo-sides .stacked { flex-direction: column; justify-content: center; line-height: .9; }
.logo-sides small { font-size: 9px; margin-top: 3px; }
#logo-message:empty { display: none; }
#logo-message.danger { color: #f0a29b; }
.switch { position: relative; flex: 0 0 38px; height: 23px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }
.switch span { display: block; width: 38px; height: 23px; border-radius: 20px; background: #42392f; transition: background .15s; }
.switch span::after { content: ''; display: block; position: absolute; width: 17px; height: 17px; top: 3px; left: 3px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(15px); }
.switch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 3px; }
#label-settings { border: 0; margin: 0; padding: 0; min-width: 0; }
#label-settings:disabled { opacity: .4; }
.templates { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.templates button { padding: 8px 3px; background: var(--field); display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 7px; font-size: 10px; color: var(--muted); }
.templates [aria-pressed="true"] { color: var(--text); background: #30251d; border-color: var(--accent); }
.template-sample { font-size: 20px; line-height: 1; letter-spacing: -.06em; height: 35px; min-width: 55px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.template-sample small { font-size: 7px; letter-spacing: 0; margin-top: 4px; }
.template-sample.framed { border: 1px solid currentColor; border-radius: 4px; font-size: 15px; }
.field textarea { display: block; width: 100%; resize: vertical; min-height: 60px; max-height: 160px; background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 9px; margin-top: 6px; line-height: 1.4; }
#label-panel .field input[type="number"] { width: 100%; display: block; margin-top: 6px; }
.compact { font-size: 12px; padding: 3px 0; color: var(--muted); }
.color-field { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.color-field input { width: 42px; height: 33px; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: var(--field); cursor: pointer; }
.placement-row { display: flex; gap: 15px; align-items: center; }
.anchor-grid { flex: 0 0 108px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.anchor-grid button { padding: 3px; height: 31px; color: var(--muted); background: var(--field); border-radius: 5px; font-size: 18px; }
.anchor-grid [aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: #30251d; }
.placement-copy { font-size: 11px; color: var(--muted); }
.placement-copy b { font-weight: 500; color: var(--text); }
.placement-copy p { margin: 6px 0 0; }
.rotation-presets { display: flex; gap: 5px; }
.rotation-presets button { flex: 1; padding: 4px; font-size: 11px; background: transparent; }
.label-advanced { margin-top: 14px; font-size: 12px; color: var(--muted); }
.label-advanced summary { cursor: pointer; padding: 5px 0; }
.label-bottom { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 3px; }
#label-status { font-size: 12px; color: var(--muted); }
#label-status.danger { color: #f0a29b; }
.label-actions { display: flex; gap: 6px; }
.label-actions button { font-size: 11px; padding: 7px 8px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

section { padding: 14px 0; border-bottom: 1px solid #2a241c; }
section:last-child { border: 0; }
h2 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.note, #hint { color: var(--muted); font-size: 12.5px; }
.note { margin: 8px 0 12px; }

.segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
}
.seg {
  display: flex;
  justify-content: center;
  padding: 8px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--muted);
}
.seg:has(input:checked) {
  background: #2b241e;
  color: var(--text);
}
.seg input, .choice input, .checks input { accent-color: var(--accent); }
.seg input { display: none; }

.auto-hint { color: var(--accent); font-weight: 600; letter-spacing: 0; text-transform: none; margin-left: 6px; }
.field { display: block; margin: 10px 0; color: var(--muted); font-size: 12px; }
.field select { display: block; width: 100%; margin-top: 6px; padding: 8px 5px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); }
.pair-grid > * { min-width: 0; }
.field input[type="number"] {
  width: 88px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
}
.pair { display: grid; grid-template-columns: 88px 1fr; gap: 10px; align-items: center; margin-top: 6px; }
.pair-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.presets button { font-size: 12px; padding: 6px 9px; }

.choice {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 2px;
  cursor: pointer;
}

.checks { display: grid; gap: 6px; }
.checks label { display: flex; gap: 8px; color: var(--muted); cursor: pointer; }

.stage-wrap { position: relative; z-index: 0; min-width: 0; min-height: 0; background: #141210; }
#stage { display: block; width: 100%; height: 100%; }

#toast {
  position: absolute;
  left: 16px;
  bottom: 16px;
  background: #2a241e;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}
#toast.danger { border-color: var(--danger); color: #f0c4c0; }
#label-live-status { position: absolute; top: 12px; right: 12px; max-width: min(340px, calc(100% - 24px)); padding: 7px 10px; border: 1px solid #6f5235; border-radius: 8px; background: #211a12e8; color: #e5c3a2; font-size: 11px; pointer-events: none; }
#label-live-status.danger { color: #f0a29b; border-color: var(--danger); }

#export-dialog, #icon-library, #share-dialog {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 24px 80px #0008;
}
#export-dialog { width: min(480px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 20px; }
#share-dialog { max-height: calc(100% - 32px); padding: 20px; }
#export-dialog::backdrop, #icon-library::backdrop, #share-dialog::backdrop { background: #0009; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.dialog-heading h2 { margin: 0; font-size: 18px; letter-spacing: 0; text-transform: none; color: var(--text); }
.dialog-heading button { padding: 4px 9px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
#export-status { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
#export-status:empty { display: none; }
#export-status.danger { color: #f0c4c0; }

.status {
  grid-column: 1 / -1;
  display: flex;
  gap: 28px;
  align-items: center;
  padding: 8px 18px;
  border-top: 1px solid var(--line);
  background: #171512;
  font-variant-numeric: tabular-nums;
}
.status span { color: var(--muted); margin-right: 8px; }
.status p { margin: 0 0 0 auto; }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: 10px; }
  .top-actions { flex-wrap: wrap; }
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(220px, 38vh) minmax(240px, 1fr) auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .status { flex-wrap: wrap; gap: 10px; }
  .status p { margin: 0; width: 100%; }
}
