:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #64748b;
  --line: #d8dee6;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

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

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 18px;
  font-weight: 700;
}

.mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
}

button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: #9aa8b8;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-strong);
}

.group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

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

.group button:last-child:nth-child(3) {
  grid-column: 1 / -1;
}

.modeGroup button:last-child:nth-child(3) {
  grid-column: auto;
}

.seg.active {
  border-color: var(--accent);
  background: #e8f4f2;
  color: var(--accent-strong);
  font-weight: 700;
}

.field {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.field input[type="color"] {
  width: 100%;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.field input[type="range"] {
  min-width: 0;
}

output {
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.status {
  min-height: 58px;
  margin: auto 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status.error {
  border-color: #f1b6af;
  color: var(--danger);
  background: #fff4f2;
}

.status.ok {
  border-color: #9bd3c8;
  color: var(--accent-strong);
  background: #eefaf8;
}

.stageWrap {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 100vh;
  padding: 28px;
  overflow: auto;
  background:
    linear-gradient(45deg, #e7ebf0 25%, transparent 25%),
    linear-gradient(-45deg, #e7ebf0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e7ebf0 75%),
    linear-gradient(-45deg, transparent 75%, #e7ebf0 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.canvasHost {
  position: relative;
  display: block;
  width: fit-content;
  height: fit-content;
  max-width: min(100%, calc(100vw - 316px));
  max-height: calc(100vh - 56px);
}

canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 56px);
  background: #fff;
  border-radius: 6px;
  box-shadow: var(--shadow);
  touch-action: none;
}

.overlayLayer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.textEditor {
  position: absolute;
  z-index: 5;
  min-width: 80px;
  min-height: 42px;
  padding: 8px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  outline: 2px solid #fff;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  resize: both;
  overflow: hidden;
  line-height: 1.25;
  pointer-events: auto;
}

.emptyState {
  position: absolute;
  inset: 28px;
  display: grid;
  place-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.emptyIcon {
  margin: 0 auto 6px;
  width: 74px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  font-weight: 700;
}

.emptyState small {
  display: block;
  font-size: 13px;
}

.hasImage .emptyState {
  display: none;
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand,
  .status {
    grid-column: 1 / -1;
  }

  .stageWrap {
    min-height: calc(100vh - 310px);
    padding: 16px;
  }

  .canvasHost {
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 342px);
  }

  canvas {
    max-height: calc(100vh - 342px);
  }
}
