:root {
  --bg: #eef2f7;
  --toolbar-bg: #6b46c1;
  --toolbar-bg-2: #553c9a;
  --btn-bg: #ffffff;
  --btn-active: #ffd166;
  --text-dark: #1a202c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-dark);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

#meta-row {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 8px 12px;
  background: #ffffff;
  border-bottom: 1px solid #dbe2ea;
  z-index: 10;
}

#meta-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
}

#meta-row input {
  font-size: 16px; /* keep at 16px+ so iOS Safari doesn't zoom in on focus */
  padding: 6px 10px;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  min-height: 36px;
  min-width: 120px;
  -webkit-user-select: text;
  user-select: text;
}

#meta-row input#class-input {
  min-width: 90px;
  width: 90px;
}

#toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: linear-gradient(180deg, var(--toolbar-bg), var(--toolbar-bg-2));
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  z-index: 10;
}

.group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: rgba(255,255,255,0.08);
  border-radius: 14px;
}

.tbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 56px;
  min-height: 48px;
  padding: 6px 8px;
  border: none;
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--text-dark);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease, background 0.15s ease;
}

.tbtn .icon { font-size: 20px; line-height: 1; }

.tbtn:active { transform: scale(0.92); }

.tbtn.active {
  background: var(--btn-active);
  box-shadow: inset 0 0 0 3px #b7791f;
}

.tbtn:disabled {
  opacity: 0.4;
  cursor: default;
}

.tbtn:disabled:active { transform: none; }

#color-group { gap: 5px; }

.swatch {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.8);
  cursor: pointer;
  display: block;
  position: relative;
  flex: 0 0 auto;
}

.swatch.selected {
  border-color: #ffd166;
  box-shadow: 0 0 0 2px #b7791f;
}

.custom-swatch {
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.custom-swatch input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  cursor: pointer;
}

.custom-swatch .plus {
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  pointer-events: none;
}

#canvas-wrap {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  background: #ffffff;
  overflow: hidden;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 45, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

#help-overlay[hidden] { display: none; }

#help-card {
  background: #fff;
  border-radius: 18px;
  padding: 22px 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

#help-card h2 {
  margin-top: 0;
  color: var(--toolbar-bg);
}

#help-card ul {
  padding-left: 0;
  list-style: none;
  font-size: 16px;
  line-height: 1.6;
}

#help-card li { margin-bottom: 10px; }

#help-close {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 8px;
  border: none;
  border-radius: 12px;
  background: var(--toolbar-bg);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  background: rgba(26, 32, 44, 0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
  z-index: 60;
  pointer-events: none;
}

#toast[hidden] { display: none; }
