:root {
  --bg: #f5f0e8;
  --panel: #fffaf2;
  --ink: #262422;
  --muted: #7f756b;
  --line: #ded5ca;
  --dark: #1f1d1b;
  --cream: #fffaf2;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

button,
input {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
}

.stage-pane {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
  padding: 28px;
}

.topbar,
.stage-footer,
.control-head,
.top-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.kicker,
.stage-footer,
.control-head,
.mini-label,
.range-value {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
}

.kicker {
  margin: 0 0 8px;
}

.brand-logo {
  display: block;
  width: 248px;
  max-width: min(58vw, 248px);
  height: auto;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.icon-button,
.line-button,
.template,
.export {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  padding: 10px 12px;
  font-size: 12px;
  background: rgba(255, 250, 242, 0.64);
}

.canvas-frame {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--dark);
  border: 1px solid #171513;
  padding: 20px;
}

.floating-photo-tools {
  position: absolute;
  right: 32px;
  bottom: 32px;
  z-index: 4;
  display: none;
  grid-template-columns: auto;
  gap: 8px;
  padding: 8px;
  background: rgba(31, 29, 27, 0.78);
  border: 1px solid rgba(255, 250, 242, 0.2);
  backdrop-filter: blur(14px);
}

.split-handle {
  position: absolute;
  left: 0;
  z-index: 3;
  display: none;
  height: 0;
  border-top: 1px solid rgba(255, 250, 242, 0.82);
  transform: translateY(-1px);
  cursor: ns-resize;
}

.split-handle.visible {
  display: block;
}

.split-handle button {
  position: absolute;
  left: 12px;
  top: 0;
  min-width: 86px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid rgba(255, 250, 242, 0.36);
  background: rgba(31, 29, 27, 0.82);
  color: var(--cream);
  cursor: ns-resize;
  font-size: 12px;
  transform: translateY(-50%);
  backdrop-filter: blur(14px);
}

.split-handle.dragging button {
  background: var(--cream);
  color: var(--dark);
}

.floating-photo-tools.visible {
  display: grid;
}

.tool-buttons {
  display: none;
  grid-template-columns: repeat(4, 40px) 52px 54px;
  gap: 8px;
}

.floating-photo-tools.expanded .tool-buttons {
  display: grid;
}

.floating-photo-tools button,
.tool-toggle {
  display: grid;
  place-items: center;
  min-width: 40px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(255, 250, 242, 0.28);
  background: rgba(255, 250, 242, 0.08);
  color: var(--cream);
  cursor: pointer;
  font-size: 13px;
}

.floating-photo-tools button:hover {
  background: rgba(255, 250, 242, 0.18);
}

.floating-photo-tools button.active {
  background: var(--cream);
  color: var(--dark);
}

.canvas-frame.dragging .upload-mask,
.canvas-frame.dragging {
  border-color: var(--cream);
}

#artboard {
  display: block;
  width: min(58vh, 100%);
  max-width: 540px;
  height: auto;
  background: #efe6da;
  box-shadow: 0 28px 72px rgba(0, 0, 0, 0.32);
  touch-action: none;
}

.canvas-frame.has-photo #artboard {
  cursor: grab;
}

.canvas-frame.picking #artboard {
  cursor: crosshair;
}

.canvas-frame.panning #artboard {
  cursor: grabbing;
}

.upload-mask {
  position: absolute;
  inset: 20px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  color: var(--cream);
  border: 1px dashed rgba(255, 250, 242, 0.46);
  background: rgba(31, 29, 27, 0.78);
  cursor: pointer;
}

.upload-mask.hidden {
  display: none;
}

.upload-mask:focus-within,
.solid-button:focus-within,
.mobile-tools label:focus-within,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.upload-mask input,
.solid-button input,
.mobile-tools input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-plus {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid currentColor;
  font-size: 30px;
}

.upload-mask strong {
  font-size: 18px;
}

.upload-mask small {
  color: rgba(255, 250, 242, 0.72);
}

.editor-pane {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 28px 24px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.editor-tabs {
  display: none;
}

.control {
  display: grid;
  gap: 10px;
}

.button-grid,
.template-grid,
.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.template-grid {
  grid-template-columns: repeat(3, 1fr);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
}

.segmented-control button {
  min-height: 36px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button.active {
  background: var(--dark);
  color: var(--cream);
}

.solid-button,
.line-button,
.template,
.export {
  position: relative;
  display: block;
  padding: 11px 12px;
  text-align: center;
  font-size: 12px;
}

.solid-button,
.export,
.template.active {
  background: var(--dark);
  border-color: var(--dark);
  color: var(--cream);
}

.text-field {
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.text-field:focus {
  border-bottom-color: var(--ink);
}

.palette {
  display: grid;
  gap: 8px;
}

.palette-empty {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.palette button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.palette button.active {
  font-weight: 700;
}

.palette button.active .swatch {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.swatch {
  height: 28px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.hex {
  color: var(--muted);
  font-size: 12px;
}

.range {
  width: 100%;
  accent-color: var(--dark);
}

.range-value {
  display: block;
  margin-top: 4px;
}

.export {
  width: 100%;
  margin-top: 0;
  padding: 15px 16px;
  letter-spacing: 0.12em;
}

.desktop-export {
  order: 20;
  margin-top: 0;
}

.mobile-export,
.mobile-tools {
  display: none;
}

.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 20;
  width: min(560px, calc(100vw - 32px));
  padding: 18px 24px;
  background: var(--dark);
  color: var(--cream);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.26);
  transform: translate(-50%, calc(-50% + 16px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}

@media (max-width: 860px) {
  body {
    padding-bottom: 0;
  }

  .app {
    min-height: auto;
    display: block;
  }

  .stage-pane {
    min-height: auto;
    padding: 16px;
    gap: 12px;
  }

  h1 {
    font-size: 28px;
  }

  .top-actions {
    display: none;
  }

  .canvas-frame {
    padding: 14px;
  }

  #artboard {
    width: min(88vw, 460px);
  }

  .stage-footer {
    min-height: 42px;
  }

  .editor-pane {
    display: grid;
    gap: 14px;
    padding: 20px 16px 28px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .desktop-export {
    display: block;
    margin: 0;
    order: 0;
  }

  .mobile-export,
  .mobile-tools {
    display: none;
  }

  .editor-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border: 1px solid var(--line);
  }

  .editor-tabs button {
    min-height: 40px;
    border: 0;
    border-right: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    font-size: 12px;
    cursor: pointer;
  }

  .editor-tabs button:last-child {
    border-right: 0;
  }

  .editor-tabs button.active {
    background: var(--dark);
    color: var(--cream);
  }

  .control[data-panel] {
    display: none;
  }

  .control[data-panel].active {
    display: grid;
  }
}

@media (max-width: 430px) {
  .stage-pane {
    padding: 12px;
  }

  .canvas-frame {
    padding: 10px;
  }

  .upload-mask {
    inset: 10px;
  }

  .floating-photo-tools {
    right: 18px;
    bottom: 18px;
    gap: 6px;
  }

  .tool-buttons {
    grid-template-columns: repeat(4, 36px) 48px 50px;
    gap: 6px;
  }

  .floating-photo-tools button {
    min-width: 36px;
    height: 32px;
    padding: 0 8px;
  }

  .template-grid,
  .two-cols {
    grid-template-columns: 1fr;
  }
}
