/* `hidden` always hides, even on elements whose CSS sets a display. */
[hidden] { display: none !important; }

/* App-like: nothing scrolls, zooms, selects or pops up a long-press menu. */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font: 16px -apple-system, system-ui, sans-serif;
  background: #fff;
}
body {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---- the bar ---- */
#bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  background: #3F48CC; /* Paint's indigo, same as the app icon rim */
}
#bar button, .pop button {
  font: inherit;
  color: #222;
  min-width: 44px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
}
#bar button { color: #fff; }
#bar button.on {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.6);
}
#bar button:disabled { opacity: 0.35; }

/* Lucide icons (icons.svg): line icons in the button's text color. */
.i {
  width: 26px;
  height: 26px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#bar button { display: flex; align-items: center; justify-content: center; }
.spacer { flex: 1; }

.chip, .dot {
  display: inline-block;
  vertical-align: middle;
  border-radius: 50%;
  border: 2px solid #fff;
}
.chip { width: 24px; height: 24px; }

/* Lower-left: current tool name + a sample of what it would draw. */
#bar #toolBtn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px 0 8px;
  height: 46px;
  /* boxed, so it reads as the button that opens the tool menu */
  border: 1.5px solid rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.12);
}
#toolPreview, #previewIcon {
  width: 72px;
  height: 34px;
  background: #fff;
  border-radius: 6px;
}
#previewIcon { display: flex; align-items: center; justify-content: center; color: #444; }

/* Tool menu: a row per tool, a dot per size. */
#toolMenu {
  left: 8px;
  display: grid;
  grid-template-columns: auto repeat(5, 48px) auto;
  align-items: center;
  gap: 4px;
}
/* Row headers: tool buttons. The current tool gets the strong outline. */
#toolMenu .head {
  margin-right: 8px;
  border: 1px solid #bbb;
  color: #222;
}
#toolMenu .head.current {
  border: 2.5px solid #222;
  background: #f0f0f0;
}
#toolMenu button {
  width: 48px;
  height: 48px;
  min-width: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#toolMenu button.on { border: 3px solid #0a64d8; background: #e3eeff; }
#toolMenu button.last { border: 2px dotted #8fb0dc; }
#toolMenu .sz {
  display: block;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
#toolMenu .sz.erase { box-shadow: none; border: 2px dashed #666; box-sizing: border-box; }

/* ---- drawing area ---- */
#wrap {
  flex: 1;
  position: relative;
}
#stage, #hlGroup {
  position: absolute;
  inset: 0;
}
#stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- popovers ---- */
.pop {
  position: absolute;
  bottom: 6px; /* just above the bar */
  background: #fff;
  border: 1px solid #bbb;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  padding: 8px;
  z-index: 10;
}

#palette {
  display: flex;
  gap: 14px;
}
#palette .side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
#palette .swatches {
  display: grid;
  grid-template-columns: repeat(10, 44px);
  gap: 6px;
}
#palette .label { margin: 10px 0 4px; font-size: 14px; color: #555; }
#palette button {
  width: 44px;
  height: 44px;
  min-width: 0;
  padding: 0;
  border-radius: 8px;
  border: 1px solid #999;
}
#palette button.on { outline: 3px solid #0a64d8; outline-offset: 2px; }
#palette button.current { width: 76px; height: 76px; border-radius: 10px; }
#palette button.shade {
  width: 76px;
  height: 36px;
  border-color: #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 20px;
}
#palette button.shade:disabled { opacity: 0.35; }
#palette .ramp { width: 34px; height: 16px; border-radius: 8px; border: 1.5px solid #222; }

/* Eraser modes (from the color button while erasing): Area and Object. */
#eraserMenu { display: flex; gap: 8px; }
#eraserMenu button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 84px;
  height: 72px;
  border: 1px solid #ccc;
}
#eraserMenu button.on { border: 3px solid #0a64d8; background: #e3eeff; }
#eraserMenu canvas { border-radius: 4px; }
#palette .any {
  position: relative;
  width: 44px;
  height: 44px;
  box-sizing: border-box;
  border-radius: 8px;
  border: 1px solid #999;
  background: conic-gradient(#f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}
#palette .any input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
}

#menu {
  right: 8px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 200px;
}
#menu button, #menu label {
  text-align: left;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}
#menu input { width: 20px; height: 20px; margin: 0 0 0 auto; }
#menu .i { width: 22px; height: 22px; color: #444; }
#menu .about {
  font-weight: 700;
  color: #3F48CC;
  white-space: nowrap;
  border-bottom: 1px solid #ddd;
  border-radius: 8px 8px 0 0;
  margin-bottom: 4px;
}

#menu .about .i { color: #3F48CC; }
/* Clear: red, the iOS convention for "this removes things" (it's undoable) */
#menu .danger, #menu .danger .i { color: #d62828; }

/* About box */
#about {
  max-width: 520px;
  width: calc(100% - 48px);
  border: none;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  line-height: 1.45;
  -webkit-user-select: text;
  user-select: text;
}
#about .inner { padding: 8px 24px 20px; }
#about::backdrop { background: rgba(0, 0, 0, 0.35); }
#about h2 { color: #3F48CC; }
#about ul { padding-left: 1.2em; }
#about li { margin: 0.4em 0; }
#about .fine { color: #666; font-size: 14px; }
#about a { color: #3F48CC; }
#about form { text-align: right; }
#about form button {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: #3F48CC;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
}

#toast {
  position: absolute;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  background: rgba(30, 30, 30, 0.88);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  max-width: 80%;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 20;
}
#toast.show { opacity: 1; }

/* ---- Phones ----
   iPhone screens have big rounded corners right where the bar's end buttons
   sit, so pull the ends inward and make things a bit more compact to fit. */
@media (max-width: 540px) {
  #palette .swatches { grid-template-columns: repeat(5, 44px); }
  #bar {
    padding-left: 44px; /* clear of the rounded screen corners */
    padding-right: 44px;
    gap: 2px;
  }
  #bar button { min-width: 36px; padding: 0 5px; }
  #bar #toolBtn { gap: 5px; padding: 0 4px 0 5px; }
  #toolPreview, #previewIcon { width: 50px; }

  /* Paint palette: still 10 across, smaller swatches */
  #palette { grid-template-columns: repeat(10, 30px); gap: 4px; padding: 6px; }
  #palette button, #palette .any { width: 30px; height: 30px; }

  /* Tool menu: slightly smaller cells */
  #toolMenu { grid-template-columns: auto repeat(5, 42px) auto; left: 22px; }
  #toolMenu button { width: 42px; height: 42px; }

  #menu { right: 22px; }
}

/* Staging copy (kirk.is/staging/...): an orange stripe so it's never mistaken for live. */
body.staging #bar { border-top: 5px solid #FF7F27; }
