:root {
  color-scheme: dark;
  --ink: #eef0f8;
  --muted: #a2a8bb;
  --canvas: #0b0d13;
  --surface: #151824;
  --surface-2: #1c2030;
  --line: #30374b;
  --accent: #ff4f70;
  --accent-strong: #ff6c88;
  --accent-ink: #26070f;
  --success: #6ae5ad;
  --warning: #ffc861;
  --danger: #ff8098;
  --focus: #a8d6ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, .35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -20%, rgba(255, 79, 112, .19), transparent 30rem),
    radial-gradient(circle at 85% 0%, rgba(85, 128, 255, .13), transparent 31rem),
    var(--canvas);
}

button, input, textarea, select { font: inherit; }

button { cursor: pointer; }

button:disabled, input:disabled, textarea:disabled, select:disabled { cursor: not-allowed; opacity: .48; }

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

code {
  padding: .08rem .28rem;
  border-radius: .3rem;
  color: #ffe1e7;
  background: rgba(255, 255, 255, .09);
  font-size: .91em;
}

.app-shell { max-width: 2160px; min-height: 100vh; margin: 0 auto; padding: clamp(12px, 2vw, 30px); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 4px 18px;
}

.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }

.brand-mark {
  display: grid;
  width: 45px;
  height: 45px;
  flex: 0 0 45px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 14px 14px 3px 14px;
  color: var(--accent-ink);
  background: var(--accent);
  box-shadow: 5px 5px 0 rgba(255, 255, 255, .17);
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-weight: 800;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.15rem, 2vw, 1.45rem); letter-spacing: -.035em; }
h2 { font-size: .99rem; letter-spacing: -.018em; }
.brand p { margin-top: 3px; color: var(--muted); font-size: .77rem; }

.connection { display: flex; align-items: center; justify-content: flex-end; gap: 9px; color: var(--muted); font-size: .78rem; text-align: right; }
.status-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 100%; background: var(--muted); box-shadow: 0 0 0 4px rgba(162, 168, 187, .12); }
.status-dot.status-ready { background: var(--success); box-shadow: 0 0 0 4px rgba(106, 229, 173, .13); }
.status-dot.status-error { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 128, 152, .13); }
.status-dot.status-busy { background: var(--warning); box-shadow: 0 0 0 4px rgba(255, 200, 97, .13); }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
  padding: 10px 13px;
  border: 1px solid #364260;
  border-radius: 12px;
  color: #cbd7f3;
  background: rgba(52, 77, 126, .15);
  font-size: .78rem;
  line-height: 1.4;
}
.notice span { color: #a8d6ff; font-size: 1.2rem; line-height: .9; }

.workspace {
  display: grid;
  grid-template-columns: minmax(292px, 360px) minmax(480px, 1fr) minmax(254px, 330px);
  gap: 16px;
  align-items: start;
}

.control-panel, .activity-panel, .editor-stage {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(155deg, rgba(31, 35, 51, .95), rgba(17, 20, 30, .96));
  box-shadow: var(--shadow);
}

.control-panel { overflow: hidden; }
.panel-section { padding: 16px; border-bottom: 1px solid var(--line); }
.panel-section:last-child { border-bottom: 0; }

.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.eyebrow { display: block; margin-bottom: 3px; color: #ff9caf; font-size: .64rem; font-weight: 750; letter-spacing: .095em; text-transform: uppercase; }
.format-chip { padding: 3px 7px; border: 1px solid #424b64; border-radius: 999px; color: #c4cadb; font-size: .62rem; font-weight: 700; letter-spacing: .045em; white-space: nowrap; }

.button {
  min-height: 35px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--ink);
  background: transparent;
  font-size: .76rem;
  font-weight: 730;
  line-height: 1.1;
  transition: transform .16s ease, background .16s ease, border-color .16s ease;
}
.button:not(:disabled):hover { transform: translateY(-1px); }
.button-primary { width: 100%; border-color: #ff6985; color: #320911; background: linear-gradient(135deg, var(--accent-strong), var(--accent)); }
.button-secondary { border-color: #49526b; background: #252a3a; }
.button-secondary:not(:disabled):hover { background: #30374b; }
.button-quiet { min-height: auto; padding: 5px 7px; color: #c7ccdc; font-size: .68rem; }
.button-quiet:not(:disabled):hover { color: white; background: rgba(255,255,255,.08); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.full-width { width: 100%; margin-top: 8px; border: 1px solid #3f485e; }

.help { margin-top: 9px; color: var(--muted); font-size: .71rem; line-height: 1.45; }
.layer-summary { min-height: 46px; margin-top: 12px; padding: 9px; border: 1px dashed #46506a; border-radius: 9px; color: #cdd2df; background: rgba(0, 0, 0, .14); font-size: .71rem; line-height: 1.4; }
.layer-summary.is-valid { border-color: rgba(106, 229, 173, .5); color: #b8f5d4; }
.layer-summary.is-invalid { border-color: rgba(255, 128, 152, .55); color: #ffc1ce; }

.file-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px;
  border: 1px dashed #545f7c;
  border-radius: 9px;
  color: #d9ddec;
  background: rgba(0, 0, 0, .12);
  font-size: .74rem;
  font-weight: 650;
}
.file-control input { width: 122px; max-width: 44%; color: #bfc5d5; font-size: .65rem; }

.text-form { display: grid; gap: 9px; }
.text-form label, .stroke-box label { display: grid; gap: 5px; color: #cfd4e2; font-size: .68rem; font-weight: 680; }
input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  min-width: 0;
  border: 1px solid #424a61;
  border-radius: 7px;
  color: #f4f5fb;
  background: #10131d;
  padding: 7px 8px;
  font-size: .77rem;
}
textarea { resize: vertical; min-height: 60px; line-height: 1.35; }
select { appearance: auto; }
input[type="number"] { padding-right: 3px; }
.form-grid { display: grid; gap: 8px; }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.four-cols { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.color-field { display: flex; align-items: center; gap: 7px; height: 33px; padding: 3px 7px; border: 1px solid #424a61; border-radius: 7px; background: #10131d; }
.color-field input { width: 26px; height: 24px; padding: 0; border: 0; background: none; }
.color-field output { color: #d8dceb; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem; font-weight: 500; }
.stroke-box { display: grid; gap: 8px; margin: 0; padding: 9px; border: 1px solid #3c455d; border-radius: 9px; }
.stroke-box legend { padding: 0 4px; color: #ffb0bd; font-size: .68rem; font-weight: 750; }
.checkbox-label { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 7px !important; }
.checkbox-label input { width: 15px; height: 15px; accent-color: var(--accent); }

.editor-stage { display: grid; grid-template-rows: auto minmax(520px, calc(100vh - 190px)) auto; overflow: hidden; }
.stage-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 62px; padding: 12px 15px; border-bottom: 1px solid var(--line); }
.stage-bar strong { display: block; overflow: hidden; max-width: 42vw; text-overflow: ellipsis; white-space: nowrap; font-size: .83rem; }
.stage-state { padding: 5px 8px; border-radius: 999px; color: #a8d6ff; background: rgba(121, 177, 237, .13); font-size: .66rem; font-weight: 720; text-align: right; }
.photopea-wrap { position: relative; min-height: 0; background: #171717; }
#photopea-frame { display: block; width: 100%; height: 100%; border: 0; background: #171717; }
.frame-cover { position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; gap: 10px; padding: 30px; color: #e7e9f2; background: linear-gradient(135deg, #141722, #0e1017); text-align: center; }
.frame-cover.is-hidden { display: none; }
.frame-cover strong { font-size: .93rem; }
.frame-cover p { max-width: 32rem; color: var(--muted); font-size: .77rem; line-height: 1.45; }
.frame-actions { display: none; }
.frame-cover.is-error .frame-actions { display: block; }
.frame-cover.is-error .frame-actions .button { min-height: 39px; }
.loader { width: 27px; height: 27px; border: 3px solid #49536d; border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
.frame-cover.is-error .loader { border-color: rgba(255, 128, 152, .26); border-top-color: var(--danger); animation: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.stage-tip { padding: 9px 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: .69rem; line-height: 1.4; }

.activity-panel { display: flex; flex-direction: column; max-height: calc(100vh - 145px); padding: 15px; position: sticky; top: 12px; }
.operation-log { display: grid; gap: 7px; overflow: auto; margin: 0; padding: 0; list-style: none; }
.operation-log:empty::after { content: "Журнал пока пуст."; color: var(--muted); font-size: .75rem; }
.log-entry { display: grid; grid-template-columns: auto 1fr; gap: 7px; padding: 8px; border-left: 2px solid #4c566e; border-radius: 0 7px 7px 0; background: rgba(0, 0, 0, .16); font-size: .7rem; line-height: 1.35; }
.log-entry time { color: #8e96aa; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .62rem; }
.log-entry.success { border-left-color: var(--success); }
.log-entry.warning { border-left-color: var(--warning); }
.log-entry.error { border-left-color: var(--danger); color: #ffd1da; }
.limitations { margin-top: 13px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: .68rem; line-height: 1.42; }
.limitations summary { cursor: pointer; color: #d9ddeb; font-weight: 700; }
.limitations ul { display: grid; gap: 6px; margin: 8px 0 0; padding-left: 17px; }
.diagnostics { margin-top: 13px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: .68rem; line-height: 1.42; }
.diagnostics summary { cursor: pointer; color: #d9ddeb; font-weight: 700; }
.diagnostics p { margin: 8px 0; }
.diagnostic-summary { display: block; max-height: 180px; overflow: auto; padding: 8px; border: 1px solid #3d465c; border-radius: 7px; color: #cfd7ea; background: rgba(0, 0, 0, .2); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .62rem; line-height: 1.45; white-space: pre-wrap; }

@media (max-width: 1320px) {
  .workspace { grid-template-columns: minmax(292px, 350px) minmax(450px, 1fr); }
  .activity-panel { grid-column: 1 / -1; max-height: 250px; position: static; }
  .operation-log { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app-shell { padding: 10px; }
  .topbar { align-items: flex-start; gap: 10px; padding-bottom: 12px; }
  .connection { max-width: 155px; flex-wrap: wrap; }
  .workspace { grid-template-columns: 1fr; gap: 11px; }
  .control-panel { order: 1; }
  .editor-stage { order: 2; grid-template-rows: auto minmax(465px, 64svh) auto; }
  .activity-panel { order: 3; grid-column: auto; max-height: none; }
  .operation-log { grid-template-columns: 1fr; max-height: 260px; }
  .stage-bar strong { max-width: 52vw; }
}

@media (max-width: 470px) {
  .app-shell { padding: 8px; }
  .brand-mark { width: 38px; height: 38px; flex-basis: 38px; font-size: 1.2rem; }
  .brand p { display: none; }
  .connection { max-width: 140px; justify-content: flex-end; font-size: .66rem; }
  .notice { margin-bottom: 10px; padding: 8px 9px; font-size: .7rem; }
  .panel-section { padding: 13px; }
  .four-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .editor-stage { grid-template-rows: auto minmax(440px, 59svh) auto; border-radius: 13px; }
  .stage-bar { min-height: 54px; padding: 9px 11px; }
  .stage-bar strong { max-width: 49vw; font-size: .74rem; }
  .stage-state { max-width: 35vw; font-size: .6rem; }
}
