:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #1b2028;
  --muted: #6c7480;
  --line: #d8dde5;
  --soft-line: #e7ebf0;
  --accent: #ef3333;
  --blue: #2563eb;
  --active: #1f2d42;
  --shadow: 0 18px 55px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: 10px;
}

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 20px);
  padding: 20px;
  border: 1px solid #e5eaf2;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 14px;
  min-height: 0;
}

.canvas-side {
  display: grid;
  grid-template-rows: auto auto minmax(360px, 1fr);
  gap: 10px;
  min-width: 0;
}

.app-header,
.topbar,
.image-actions,
.side-header,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header {
  justify-content: flex-start;
}

.app-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  overflow: hidden;
  border: 1px solid #d9e6f7;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
}

.app-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand {
  min-width: 160px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

p,
#statusText {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tools {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: 1px solid #e7edf6;
  border-radius: 12px;
  background: #f8fbff;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.tool,
.image-button,
.add-button,
.primary-button,
.download-link {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: 7px;
  place-items: center;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid #dfe6f0;
  border-radius: 8px;
  background: #fff;
  color: var(--active);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.button-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary-button .button-icon {
  stroke-width: 2.2;
}

.tool.is-active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.tool-group .tool {
  border-color: transparent;
  border-radius: 6px;
}

.shape-tool {
  width: 42px;
  min-width: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.shape-icon {
  content: "";
  display: block;
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  border: 2.2px solid currentColor;
  color: var(--active);
}

.shape-tool.is-active .shape-icon {
  color: #fff;
}

.shape-icon-circle {
  border-radius: 999px;
}

.shape-icon-rect {
  border-radius: 3px;
}

.color-group {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.size-control {
  display: grid;
  grid-template-columns: auto 88px 22px;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--active);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.size-control input {
  width: 88px;
  accent-color: var(--active);
}

.size-control output {
  color: var(--muted);
  text-align: right;
}

.swatch {
  width: 26px;
  height: 26px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--line);
}

.swatch-black {
  background: #111;
}

.swatch-white {
  background: #fff;
}

.swatch.is-active {
  box-shadow: 0 0 0 3px #1f2b3d;
}

.image-button input {
  display: none;
}

.image-actions {
  padding: 0 2px;
}

.primary-button {
  border-color: #2563eb;
  background: linear-gradient(135deg, #2563eb, #38a1ff);
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.16);
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 360px;
  border: 1px solid #dfe6f0;
  border-radius: 14px;
  background:
    linear-gradient(45deg, #e6ebf1 25%, transparent 25%),
    linear-gradient(-45deg, #e6ebf1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e6ebf1 75%),
    linear-gradient(-45deg, transparent 75%, #e6ebf1 75%);
  background-color: #f9fafc;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  box-shadow: var(--shadow);
}

.remove-image-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 8;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid #dfe6f0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #334155;
  font-size: 24px;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.14);
}

.remove-image-button:disabled {
  display: none;
}

canvas,
.stamp-layer {
  position: absolute;
  display: block;
  max-width: 100%;
  max-height: 100%;
}

#drawCanvas {
  cursor: crosshair;
  touch-action: none;
  z-index: 2;
}

.stamp-layer {
  z-index: 3;
  pointer-events: none;
}

.stamp {
  position: absolute;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.2);
}

.stamp.is-linked {
  width: 34px;
  height: 34px;
  font-size: 18px;
  border-width: 3px;
  box-shadow:
    0 0 0 5px rgba(224, 49, 49, 0.22),
    0 5px 16px rgba(0, 0, 0, 0.28);
}

.drop-hint {
  z-index: 4;
  display: grid;
  gap: 5px;
  justify-items: center;
  min-width: 210px;
  padding: 24px 28px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  text-align: center;
  pointer-events: none;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.14);
}

.drop-hint[hidden] {
  display: none;
}

.drop-hint strong {
  color: var(--ink);
  font-size: 15px;
}

.text-side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  min-width: 0;
  padding: 16px;
  border: 1px solid #e7edf6;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.issue-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.issue {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: #fbfcfe;
}

.issue.is-selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.issue-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-family: ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  font-weight: 700;
}

.issue textarea {
  width: 100%;
  min-height: 118px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  line-height: 1.55;
}

.hint-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid #cfe0ff;
  border-radius: 12px;
  background: #f6f9ff;
  color: #2563eb;
  font-size: 12px;
  line-height: 1.35;
}

.hint-card strong {
  color: #1d4ed8;
  font-size: 13px;
}

@media (max-width: 980px) {
  .workbench {
    grid-template-columns: 1fr;
  }

  .text-side {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .tools {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .canvas-side,
  .text-side {
    padding: 11px;
  }

  .image-actions,
  .side-header {
    align-items: stretch;
    flex-direction: column;
  }

  .tool,
  .image-button,
  .add-button {
    min-height: 38px;
  }
}
