:root {
  --bg: #1b1d22;
  --panel: #24272e;
  --panel2: #2c3038;
  --border: #3a3f4a;
  --text: #e8eaed;
  --muted: #9aa0ac;
  --accent: #5b8cff;
  --c1: #ff5c5c;
  --c2: #4caf50;
  --c3: #4aa3ff;
  --c4: #ffb84a;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.topbar {
  flex: 0 0 auto;
  _display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar .brand-name {
  font-size: 32px;
  text-align: center;
  font-weight: 700;
  letter-spacing: .01em;
}

.topbar .brand-name .accent {
  color: var(--accent);
}

.topbar .brand-tag {
  font-size: 12.5px;
  color: var(--muted);
}

/* App row (sidebar + canvas area) */
.app {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

aside {
  width: 300px;
  flex: 0 0 300px;
  background: var(--panel);
  padding: 20px;
  overflow-y: auto;
}

aside.gallery-aside {
  border-right: 1px solid var(--border);
}

aside.options-aside {
  border-left: 1px solid var(--border);
}

.step {
  margin-bottom: 20px;
}

.step h2,
.aside-title {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 0 0 8px;
}

.filebtn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}

.filebtn:hover {
  border-color: var(--accent);
}

.filebtn small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
  font-weight: normal;
}

input[type=file] {
  display: none;
}

button.action {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 6px;
}

button.action:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover {
  opacity: .92;
}

button.primary:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 4px;
}

.segbtn {
  flex: 1;
  padding: 8px 6px;
  background: var(--panel2);
  color: var(--muted);
  border: none;
  cursor: pointer;
  font-size: 12px;
  border-right: 1px solid var(--border);
}

.segbtn:last-child {
  border-right: none;
}

.segbtn.active {
  background: var(--accent);
  color: #fff;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

input[type=range] {
  flex: 1;
  accent-color: var(--accent);
}

.qval {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  width: 42px;
  text-align: right;
  color: var(--muted);
}

footer.hint {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 6px;
}

.bgrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 12.5px;
}

.bgrow input[type=color] {
  width: 36px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.subhead {
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 4px;
}

main {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.viewport {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: flex;
  padding: 30px;
}

.stage-wrap {
  position: relative;
  margin: auto;
  line-height: 0;
  flex: 0 0 auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  border-radius: 4px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #33363d 25%, transparent 25%),
    linear-gradient(-45deg, #33363d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #33363d 75%),
    linear-gradient(-45deg, transparent 75%, #33363d 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

canvas {
  display: block;
}

.placeholder {
  color: var(--muted);
  font-size: 14px;
  padding: 60px 80px;
  text-align: center;
}

.zoom-bar {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 5;
  display: none;
  align-items: center;
  gap: 2px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}

.zoom-bar button {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 6px;
  font-size: 16px;
  line-height: 1;
}

.zoom-bar button:hover {
  background: rgba(255, 255, 255, .1);
}

.zoom-bar .zlabel {
  font-size: 12px;
  color: var(--muted);
  width: 46px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.zoom-bar .zlabel:hover {
  color: var(--text);
}

.export-fab {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 5;
  padding: 12px 32px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

.export-fab:hover {
  opacity: .92;
}

.export-fab:disabled {
  opacity: .4;
  cursor: not-allowed;
}

svg.guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

svg.guide polygon {
  fill: rgba(91, 140, 255, .08);
  stroke: #fff;
  stroke-width: 1;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
}

.handle {
  position: absolute;
  width: 36px;
  height: 36px;
  margin: -18px 0 0 -18px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  border-radius: 50%;
}

.handle:hover {
  background: rgba(255, 255, 255, .10);
}

.handle:active {
  cursor: grabbing;
}

.handle::before,
.handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  background: currentColor;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6);
}

.handle::before {
  width: 13px;
  height: 1px;
  transform: translate(-50%, -50%);
}

.handle::after {
  width: 1px;
  height: 13px;
  transform: translate(-50%, -50%);
}

.handle i {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 3px;
  height: 3px;
  margin: -1.5px 0 0 -1.5px;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .6);
  font-style: normal;
}

.handle span {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(6px, -22px);
  font-size: 10px;
  font-weight: 700;
  color: currentColor;
  background: rgba(0, 0, 0, .55);
  border-radius: 3px;
  padding: 1px 4px;
  line-height: 1.4;
  pointer-events: none;
}

/* Footer */
.sitefooter {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

.sitefooter .footer-links a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 18px;
}

.sitefooter .footer-links a:hover {
  color: var(--text);
  text-decoration: underline;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 30px;
  display: flex;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.modal a {
  color: var(--accent);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.modal-head h3 {
  margin: 0;
  font-size: 15px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}

.modal-close:hover {
  background: rgba(255, 255, 255, .08);
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-body p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 10px;
}

/* Gallery */
.gallery-aside h2 {
	font-size: 12.5px;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--muted);
	margin: 0 0 8px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  min-height: 40px;
}

.gallery-item {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  text-align: center;
  padding-bottom: 8px;
}

.gallery-item:hover {
  border-color: var(--accent);
}

.gallery-item img {
  width: 100%;
  height: 92px;
  object-fit: cover;
  background: #111;
  display: block;
}

.gallery-item span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  padding: 0 6px;
}

.gallery-empty {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.gallery-grid {
  min-height: 40px;
}

.mobile-warning {
  display: none;
}

@media screen and (max-width: 1100px) {

  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  .mobile-warning {
    display: block;
    text-align: center;
  }

  .app {
    pointer-events: none;
    filter: blur(5px);
  }
}