:root {
  --ink: #2c2a33;
  --paper: #f6f1e7;
  --panel: rgba(246, 241, 231, 0.94);
  --line: rgba(44, 42, 51, 0.14);
  --accent: #3f8c99;
  --danger: #c4553d;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #a9cdd6; font-family: var(--font); color: var(--ink); }
#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }

#loading {
  position: fixed; inset: 0; display: grid; place-items: center; background: #a9cdd6;
  font-size: 22px; letter-spacing: 1px; color: #fff; z-index: 50; transition: opacity .6s;
}
#loading.done { opacity: 0; pointer-events: none; }
.ld { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.ld-title { font-size: 40px; font-weight: 700; letter-spacing: 4px; text-shadow: 0 2px 10px rgba(0,0,0,.2); }
.ld-bar { width: 240px; height: 8px; border-radius: 4px; background: rgba(255,255,255,.35); overflow: hidden; }
.ld-bar i { display: block; height: 100%; width: 0; border-radius: 4px; background: #fff; transition: width .35s ease; }
#ldText { font-size: 15px; letter-spacing: .5px; opacity: .9; }

#title { position: fixed; left: 14px; top: 14px; pointer-events: none; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,.25); }
#title h1 { margin: 0; font-size: 28px; letter-spacing: 2px; font-weight: 700; }
#title p { margin: 2px 0 0; font-size: 13px; opacity: .9; }
#logo { height: 44px; padding: 0 12px; border-radius: 12px; background: var(--panel); box-shadow: 0 3px 12px rgba(0,0,0,.15); display: grid; place-items: center; }
#logo svg { height: 17px; width: auto; display: block; fill: var(--ink); }

#topright { position: fixed; right: 14px; top: 14px; display: flex; gap: 8px; z-index: 20; }
.round {
  width: 44px; height: 44px; border-radius: 12px; border: none; background: var(--panel);
  display: grid; place-items: center; font-size: 20px; font-weight: 700; box-shadow: 0 3px 12px rgba(0,0,0,.15);
}
.round:hover { background: #fff; }

#panel {
  position: fixed; right: 14px; top: 66px; width: 260px; max-height: calc(100% - 160px); overflow: auto;
  background: var(--panel); border-radius: 16px; padding: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
  z-index: 20; transition: transform .2s, opacity .2s;
}
#panel.hidden { transform: translateX(20px); opacity: 0; pointer-events: none; }
.row { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; opacity: .6; margin-bottom: 6px; }
.label small { text-transform: none; letter-spacing: 0; margin-left: 4px; }
.tile {
  border: none; border-radius: 10px; background: #fff; padding: 8px 6px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 13px; box-shadow: 0 1px 0 var(--line);
}
.tile:hover { background: #eef6f7; }
.tile:disabled { opacity: .4; cursor: default; }
.tile .ico { font-size: 22px; line-height: 1; }
.tile small { font-size: 11px; opacity: .55; }
.tile.small { font-size: 12px; padding: 9px 4px; }
.tile.danger { color: var(--danger); }

.toggle { display: flex; align-items: center; justify-content: space-between; cursor: pointer; font-size: 14px; }
.toggle input { display: none; }
.toggle i { width: 40px; height: 22px; border-radius: 11px; background: #cfc8bb; position: relative; transition: background .2s; }
.toggle i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .2s; }
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { left: 21px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: #e7e0d3; border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { border: none; background: transparent; border-radius: 8px; padding: 7px 2px; font-size: 12px; }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.two-seg { grid-template-columns: repeat(2, 1fr); }
.seg.four-txt { grid-template-columns: repeat(4, 1fr); }
.seg.four-txt button { font-size: 11px; padding: 7px 1px; }
.seg.five-ico { grid-template-columns: repeat(2, 1fr); }
.seg.five-ico button.soon { opacity: 0.5; cursor: default; }
.seg.five-ico button { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px; font-size: 10.5px; line-height: 1.15; padding: 6px 2px; min-width: 0; text-align: center; hyphens: manual; }
.seg.five-ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.seg.five-ico button.on svg { stroke: var(--accent); }
.seg button:focus { outline: none; }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.seg.four { grid-template-columns: repeat(4, 1fr); margin-bottom: 6px; }
.seg.four button { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; padding: 6px 2px; }
.seg.four svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }
.seg.four button.on svg { stroke: var(--accent); }
#gridSizes { margin-bottom: 6px; }
.wide { width: 100%; border: none; border-radius: 8px; background: #fff; padding: 7px; font-size: 12px; margin-bottom: 8px; }
.wide:hover { background: #eef6f7; }
.wide:disabled { opacity: .4; cursor: default; }

.slider { display: grid; grid-template-columns: 82px 1fr; align-items: center; font-size: 13px; margin: 4px 0; }
.slider input { width: 100%; accent-color: var(--accent); }
.presets { display: flex; gap: 6px; margin-top: 6px; }
.presets button { flex: 1; border: none; border-radius: 8px; background: #fff; padding: 6px 2px; font-size: 12px; }
.presets button:hover { background: #eef6f7; }

#bottom { position: fixed; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; pointer-events: none; z-index: 10; padding: 0 12px; }
/* одна панель: палитра | разделитель | две одинаковые кнопки */
#dock { display: flex; align-items: center; gap: 8px; background: var(--panel); padding: 8px; border-radius: 18px; box-shadow: 0 4px 16px rgba(0,0,0,.15); pointer-events: auto; max-width: 100%; }
#paletteWrap { position: relative; display: flex; align-items: center; min-width: 0; }
#palette { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 6px; padding: 0 2px; }
.sw { width: 28px; height: 28px; border-radius: 8px; border: 2px solid rgba(0,0,0,.12); padding: 0; transition: transform .12s; }
.sw:hover { transform: translateY(-2px); }
.sw.on { border: 3px solid var(--ink); transform: translateY(-3px) scale(1.08); }
#paletteHint { position: absolute; left: 50%; top: -30px; transform: translateX(-50%); font-size: 12px; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.35); white-space: nowrap; pointer-events: none; }
#palette.multi .sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--ink); }
#palette.rand .sw { transform: translateY(-2px); box-shadow: 0 0 0 2px rgba(255,255,255,.85); }
.dock-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 0; }
.tool {
  width: 72px; height: 52px; border: none; border-radius: 12px; background: rgba(255,255,255,.7);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; padding: 4px;
}
.tool svg { width: 20px; height: 20px; }
.tool svg circle { fill: currentColor; }
.tool:hover { background: #fff; }
#btnRandColor.on { background: var(--accent); color: #fff; }
#btnErase.on { background: var(--danger); color: #fff; }

#help { position: fixed; inset: 0; background: rgba(30, 40, 50, .35); display: grid; place-items: center; z-index: 40; padding: 16px; }
#help.hidden { display: none; }
#help .card { background: var(--paper); border-radius: 18px; padding: 20px 24px; max-width: 460px; max-height: 100%; overflow: auto; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
#help h2 { margin: 0 0 8px; }
#help ul { padding-left: 18px; line-height: 1.6; font-size: 14px; }
#help .tip { font-size: 13px; opacity: .75; }
#help .tile { width: 100%; margin-top: 8px; background: var(--accent); color: #fff; font-size: 15px; padding: 10px; }

#toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -80px); background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 10px; font-size: 14px; transition: transform .25s; z-index: 60; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }

@media (max-width: 600px) {
  #title h1 { font-size: 22px; }
  #title p { display: none; }

  .sw { width: 24px; height: 24px; }
  .tool { width: 58px; font-size: 11px; }
}
