:root {
  --bg: #f4f3f1;
  --panel: #ffffff;
  --stage: #e3e1dd;
  --line: #d5d2cc;
  --text: #1f1d1a;
  --dim: #6b665e;
  --accent: #d9480f;
  --accent-text: #ffffff;
  --check-a: #ffffff;
  --check-b: #dddad4;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel: #202225;
    --stage: #111213;
    --line: #34373c;
    --text: #e9e7e3;
    --dim: #9a968e;
    --accent: #ff7a3d;
    --accent-text: #1a0d05;
    --check-a: #3a3d42;
    --check-b: #2b2e32;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, "Segoe UI", sans-serif;
}
header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
h1 { font-size: 15px; margin: 0 12px 0 0; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.mark {
  width: 18px; height: 18px; border-radius: 4px; background: var(--accent);
  box-shadow: inset 0 0 0 4px var(--accent), inset 0 0 0 6px var(--accent-text);
}
.grow { flex: 1; }
button, select, input[type=text] {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--dim); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.on { border-color: var(--accent); color: var(--accent); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
a.quiet { color: var(--dim); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 330px; }
#stage { position: relative; background: var(--stage); min-height: 0; display: flex; flex-direction: column; }
#view { flex: 1; min-height: 0; width: 100%; display: block; touch-action: none; outline: none; }
#empty {
  position: absolute; inset: 0 0 28px 0; display: grid; place-items: center;
  padding: 24px; text-align: center; color: var(--dim); pointer-events: none;
}
#empty > div { max-width: 460px; }
#empty button { pointer-events: auto; }
#empty .big { font-size: 17px; color: var(--text); }
#stage.drop::after {
  content: ""; position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 10px; pointer-events: none;
}
#three {
  position: absolute; inset: 0 0 28px 0; z-index: 5; display: none; flex-direction: column; background: var(--stage);
}
#three .bar { display: flex; gap: 6px; align-items: center; padding: 8px; flex-wrap: wrap; }
#three .bar .what { color: var(--dim); font-size: 12px; margin-right: 2px; }
#three .bar button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
#three .bar .check { margin: 0 0 0 8px; }
#three canvas { flex: 1; min-height: 0; width: 100%; touch-action: none; cursor: grab; }
#three .note { text-align: center; padding: 0 8px; }
#tools {
  position: absolute; left: 8px; top: 8px; display: none; gap: 4px; align-items: center; flex-wrap: wrap;
  padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 8px rgb(0 0 0 / .18); max-width: calc(100% - 16px);
}
#tools button { background: none; border-color: transparent; padding: 4px 9px; }
#tools button:hover { border-color: var(--line); }
#tools button.on { background: var(--accent); color: var(--accent-text); }
#tools button:disabled { opacity: .4; cursor: default; }
#tools label { display: flex; align-items: center; gap: 6px; padding: 0 6px; font-size: 12px; color: var(--dim); }
#tools input[type=range] { width: 90px; accent-color: var(--accent); }
#tagbar {
  position: absolute; left: 0; top: 0; display: none; gap: 3px; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 2px 10px rgb(0 0 0 / .3); white-space: nowrap;
}
#tagbar button { padding: 3px 9px; font-size: 12px; font-weight: 600; background: none; border-color: var(--c, var(--line)); }
#tagbar button:hover, #tagbar button.on { background: var(--c, var(--line)); color: #fff; }
#tagbar button.x { font-weight: 400; color: var(--dim); }
#sheets { display: flex; gap: 6px; padding: 0 8px; overflow-x: auto; }
#sheets:empty { display: none; }
#sheets .sheet {
  display: flex; align-items: center; gap: 6px; padding: 3px 4px 3px 8px; margin: 6px 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; font-size: 12px; cursor: pointer;
  max-width: 220px;
}
#sheets .sheet.on { border-color: var(--accent); }
#sheets .sheet span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sheets .sheet button { border: 0; background: none; padding: 0 4px; color: var(--dim); }
#status {
  display: flex; gap: 12px; padding: 5px 10px; font-size: 12px; color: var(--dim);
  background: var(--panel); border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden;
}
#toast {
  position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 7px 14px; border-radius: 6px;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%;
}
#toast.show { opacity: 1; }

aside { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding-bottom: 16px; }
aside section { padding: 12px 14px 4px; border-bottom: 1px solid var(--line); }
aside section:last-child { border-bottom: 0; }
h2 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); margin: 0 0 8px; }
.row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.slider { display: grid; grid-template-columns: auto 1fr auto; margin-bottom: 8px; }
.slider .info { justify-self: start; }
.slider output { color: var(--dim); font-variant-numeric: tabular-nums; }
.slider input { grid-column: 1 / -1; width: 100%; margin: 4px 0 0; accent-color: var(--accent); }
.field { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.field input[type=text], .field select { flex: 1; min-width: 0; }
input[type=checkbox] { accent-color: var(--accent); margin: 0; }
input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.info {
  display: inline-grid; place-items: center; flex: none; width: 15px; height: 15px; margin-left: 6px;
  border: 1px solid var(--dim); border-radius: 50%; color: var(--dim); cursor: help;
  font: italic 600 10px/1 Georgia, serif; text-transform: none; letter-spacing: 0; vertical-align: 1px;
}
.info:hover, .info:focus-visible { color: var(--accent); border-color: var(--accent); }
#tip {
  position: fixed; z-index: 10; display: none; max-width: 300px; padding: 7px 10px;
  background: var(--text); color: var(--bg); border-radius: 6px; font-size: 12px; line-height: 1.4;
  box-shadow: 0 3px 12px rgb(0 0 0 / .35); pointer-events: none;
}
#aiNote:empty { display: none; }
#aiNote { color: var(--accent); }
.note { color: var(--dim); font-size: 12px; margin: 0 0 8px; }

#tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.tile {
  position: relative; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; padding: 0;
  overflow: hidden; display: block; width: 100%;
  background: repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 0 0 / 14px 14px;
}
.tile.empty { background: var(--bg); }
.tile.on { border-color: var(--c); box-shadow: 0 0 0 2px var(--c); }
.tile canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.tile .name {
  position: absolute; left: 0; top: 0; padding: 1px 6px; font-size: 11px; font-weight: 600;
  background: var(--c); color: #fff; border-bottom-right-radius: 6px;
}
.tile kbd { position: absolute; right: 5px; top: 3px; font: 11px ui-monospace, monospace; color: var(--dim); }
.tile .acts { position: absolute; right: 3px; bottom: 3px; display: flex; gap: 3px; }
.tile:not(.full) .acts [data-act=save], .tile:not(.full) .acts [data-act=clear] { display: none; }
.tile .acts [data-act=from] { opacity: .75; }
.tile.full .acts [data-act=from] { display: none; }   /* a full view: click it, or empty it first */
.tile .src {
  position: absolute; left: 0; right: 0; bottom: 24px; text-align: center; font-size: 10px; line-height: 14px;
  background: var(--panel); color: var(--text); opacity: .9;
}
.tile .src:empty { display: none; }
#derive {
  display: none; flex-direction: column; padding: 8px 10px 0; margin-bottom: 8px;
  border: 1px solid var(--accent); border-radius: 8px;
}
#derive b { text-transform: capitalize; }
#derive .check { margin-bottom: 0; }
#derive select { padding: 3px 6px; }
.tile .acts span {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 11px; line-height: 18px;
}
.tile .acts span:hover { border-color: var(--text); }

@media (max-width: 760px) {
  body { height: auto; min-height: 100%; }
  main { grid-template-columns: 1fr; }
  #stage { height: 62vh; }
  aside { border-left: 0; border-top: 1px solid var(--line); }
  #hint, a.quiet { display: none; }
}
