:root {
  --ink: #1f2937;
  --muted: #667085;
  --line: #d7dce3;
  --panel: #ffffff;
  --soft: #f5f7fb;
  --accent: #ff3158;
  --accent-2: #2f8cff;
  --green: #20a464;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #e8edf4;
}

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

button,
.file-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

button:hover,
.file-button:hover {
  border-color: #aeb7c5;
}

button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

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

.rail,
.inspector {
  background: var(--soft);
  border-right: 1px solid var(--line);
  padding: 14px;
  overflow: auto;
}

.inspector {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #ff8b42);
  color: #fff;
  font-weight: 900;
  display: grid;
  place-items: center;
}

.brand span,
.statusbar,
.empty {
  color: var(--muted);
  font-size: 13px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.tool {
  aspect-ratio: 1;
  min-height: 42px;
  padding: 0;
  font-size: 20px;
  font-weight: 800;
}

.tool.active,
.stamp.active {
  background: #fff1f4;
  border-color: var(--accent);
  color: var(--accent);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.panel-title {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #4b5563;
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: #4b5563;
  margin-bottom: 10px;
}

input[type="color"] {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px;
  background: #fff;
}

input[type="range"],
select {
  width: 100%;
}

select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 0 8px;
}

.switches {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.switches label {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0;
}

.stamp-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.stamp {
  min-height: 36px;
  padding: 0;
  font-size: 19px;
}

.workspace {
  min-width: 0;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr) 36px;
}

.topbar,
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.statusbar {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

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

.file-button input {
  display: none;
}

.stage-shell {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 24px;
  background-color: #cfd7e3;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.5) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,.5) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,.5) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.5) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.stage-shell.white {
  background: #f8fafc;
}

.stage-shell.dark {
  background: #2b3544;
}

canvas {
  display: block;
  width: min(100%, 1280px);
  height: auto;
  margin: 0 auto;
  background: white;
  box-shadow: 0 18px 60px rgba(20, 30, 45, .24);
  border-radius: 6px;
  cursor: crosshair;
}

#textEditor {
  position: absolute;
  display: none;
  z-index: 5;
  min-width: 160px;
  min-height: 48px;
  border: 2px solid var(--accent-2);
  background: rgba(255,255,255,.88);
  color: var(--ink);
  padding: 4px 6px;
  resize: both;
  outline: 0;
}

.inspector button {
  width: 100%;
  margin-top: 8px;
}

.resize-hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.gallery-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gallery-heading .panel-title {
  margin-bottom: 0;
}

.inspector .text-button {
  width: auto;
  min-height: 28px;
  margin: 0;
  padding: 0 7px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.inspector .gallery-save {
  margin: 10px 0;
}

.gallery-grid {
  display: grid;
  gap: 10px;
}

.gallery-item {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0;
  display: block;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.inspector .gallery-open {
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  display: block;
  overflow: hidden;
  text-align: left;
  border: 0;
  border-radius: 0;
}

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #eef2f7;
}

.gallery-meta {
  display: block;
  padding: 7px 9px;
  color: var(--muted);
  font-size: 11px;
}

.inspector .gallery-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  min-height: 28px;
  margin: 0;
  padding: 0;
  border-color: rgba(255,255,255,.75);
  background: rgba(31,41,55,.78);
  color: white;
}

.gallery-empty {
  padding: 12px 4px 4px;
  text-align: center;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
    min-height: 100vh;
  }

  .rail,
  .inspector {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .tool-grid,
  .stamp-grid {
    grid-template-columns: repeat(10, minmax(36px, 1fr));
  }

  .workspace {
    min-height: 70vh;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}
