:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d1c1d;
  --muted: #616061;
  --border: #e2e2e3;
  --accent: #4a154b;
  --accent-2: #1264a3;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 8px 24px rgba(0, 0, 0, .06);
  font-family: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.app-header {
  text-align: center;
  padding: 40px 20px 8px;
}
.app-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -.02em;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.app-header__marks { display: inline-flex; align-items: center; gap: 8px; }
.app-header__emojis { font-size: 22px; line-height: 1; }
.app-header__slack { display: inline-block; vertical-align: middle; }
.app-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

/* ---------- Layout ---------- */
.app-main {
  max-width: 600px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  display: grid;
  gap: 24px;
}

/* ---------- Panels (card shell shared by all three components) ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* 1 · Editor: image stage (left) + settings column (right) */
.panel--editor {
  display: grid;
  grid-template-columns: 1fr 210px;
  gap: 20px;
  align-items: stretch;
}

/* 2 · Text: short message + naming fields, left-aligned */
.panel--text {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  align-items: flex-start; /* align the labels (tops); fields can differ in height */
}

@media (max-width: 640px) {
  .panel--editor,
  .panel--text { grid-template-columns: 1fr; }
  /* Stacked: no box alongside to match, so use natural spacing. */
  .settings { justify-content: flex-start; gap: 18px; }
}

/* ---------- Settings column ---------- */
.settings {
  display: flex;
  flex-direction: column;
  /* Spread the five controls so they fill the editor box's height exactly,
     top- and bottom-aligned with it. gap is the minimum spacing. */
  justify-content: space-between;
  gap: 8px;
  transition: opacity .15s;
}
/* No image yet: nothing to act on, so the whole settings panel is inert. */
.settings.is-empty {
  opacity: .45;
  pointer-events: none;
}
.setting { display: flex; flex-direction: column; gap: 8px; }
.settings input[type="range"] {
  width: 100%;
  accent-color: var(--accent-2);
  cursor: pointer;
}
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.check input { accent-color: var(--accent-2); cursor: pointer; }

/* Color swatch + its control (slider / checkbox) on one row */
.setting-row { display: flex; align-items: center; gap: 12px; }
.setting-row .color-picker { width: 56px; flex: none; }
.setting-row input[type="range"] { flex: 1; }
.setting-row .check { flex: 1; }

/* Pickr button styled as a color bar/swatch */
.color-picker { width: 100%; }
.color-picker .pickr { width: 100%; }
/* Reserve the swatch's height: Pickr replaces this host on load, and a 0-height
   host until then would make the settings rows grow as each picker appears. */
.color-picker__host { min-height: 34px; }
.color-picker .pcr-button {
  width: 100%;
  height: 34px;
  border-radius: 8px;
  /* A darker border + inset ring so a white/light swatch stays visible on the white card. */
  border: 1px solid rgba(0, 0, 0, .22);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .05);
}
.color-picker .pcr-button::after,
.color-picker .pcr-button::before { border-radius: 7px; }

/* Disabled (transparent background) state — clearly inert */
.color-picker.is-disabled {
  opacity: .4;
  pointer-events: none;
  filter: grayscale(.3);
}

/* ---------- Slack-flavoured Pickr popover ---------- */
.pcr-app {
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .18), 0 0 0 1px rgba(29, 28, 29, .12);
  font-family: "Lato", -apple-system, BlinkMacSystemFont, sans-serif;
  width: 232px;
}
/* Rounded gradient + hue, like Slack's swatch tiles */
.pcr-app .pcr-color-palette,
.pcr-app .pcr-palette { border-radius: 8px; }
.pcr-app .pcr-palette::before { border-radius: 8px; }
.pcr-app .pcr-color-chooser .pcr-picker { box-shadow: 0 0 0 2px #fff, 0 0 1px 3px rgba(0, 0, 0, .3); }

/* Drop nano's redundant round preview and let the hue slider span the full width
   for a clean stacked layout (gradient → hue → swatches → hex). */
.pcr-app .pcr-color-preview { display: none !important; }
.pcr-app[data-theme="nano"] .pcr-selection .pcr-color-chooser {
  grid-area: 2 / 1 / 3 / 3;
  margin: 12px 0 0;
}
.pcr-app[data-theme="nano"] .pcr-selection { grid-template-rows: 8.5em auto; }

/* Swatches as a neat grid of rounded squares with a subtle hover pop */
.pcr-app .pcr-swatches {
  display: grid !important;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  margin-top: 14px;
}
.pcr-app .pcr-swatches button {
  width: 100%;
  height: 22px;
  flex: none;
  border-radius: 6px;
  transition: transform .08s ease;
}
.pcr-app .pcr-swatches button::after {
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}
.pcr-app .pcr-swatches button:hover { transform: scale(1.12); }

/* Hex input styled like a Slack text field */
.pcr-app .pcr-interaction { margin-top: 12px; }
.pcr-app .pcr-interaction .pcr-result {
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: none;
  background: #fff;
  color: var(--text);
  font: 700 13px "Lato", sans-serif;
  padding: 8px 10px;
}
.pcr-app .pcr-interaction .pcr-result:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 21, 75, .15);
}
.pcr-app .pcr-interaction .pcr-type.active {
  background: var(--accent);
  color: #fff;
}

.dropzone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fafafa;
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  color: var(--muted);
  transition: border-color .15s, background .15s, color .15s;
  /* No text selection while dragging to pan the image. */
  -webkit-user-select: none;
  user-select: none;
  /* Fixed height (not min-height): the box stays the same size in every state,
     so nothing below shifts. 50% bigger now that it's a pan/zoom surface. */
  height: 300px;
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent-2);
  color: var(--accent-2);
  outline: none;
}
.dropzone.is-dragover {
  border-color: var(--accent-2);
  background: #eef6fc;
  color: var(--accent-2);
}
.dropzone.has-image {
  border-style: solid;
  border-color: #c8e6c9;
  background: #f4fbf4;
  color: var(--text);
}
.dropzone__icon { opacity: .8; }
.dropzone__title { margin: 4px 0 0; font-weight: 700; font-size: 15px; }
.dropzone__hint { margin: 0; font-size: 13px; }
.dropzone__preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  display: none;
  /* Pointer/scroll events are handled on the dropzone; also blocks native img drag. */
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}
/* Once uploaded: drop the helper text; the square frame is the pan/zoom surface. */
.dropzone.has-image {
  padding: 12px;
  gap: 0;
  cursor: grab;
  touch-action: none; /* let touch-drag pan instead of scrolling the page */
}
.dropzone.has-image.is-grabbing { cursor: grabbing; }
.dropzone.has-image .dropzone__icon,
.dropzone.has-image .dropzone__title,
.dropzone.has-image .dropzone__hint { display: none; }
/* The frame = the bounds of the final emoji. Size the element to the square image
   itself (clamped by max-width/height) so the border hugs it with no letterbox gap. */
.dropzone.has-image .dropzone__preview {
  display: block;
  width: auto;
  height: auto;
  border: 1px solid rgba(0, 0, 0, .28);
  border-radius: 3px;
}
/* Gesture hint, floated at the bottom so it doesn't shrink the frame. */
.dropzone__gesture {
  display: none;
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, .82);
  padding: 2px 8px;
  border-radius: 10px;
  pointer-events: none;
  white-space: nowrap;
}
.dropzone.has-image .dropzone__gesture { display: block; }

.field { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.field__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.field input,
.field textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
.field input:focus-visible,
.field textarea:focus-visible {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(18, 100, 163, .15);
}
.field textarea {
  resize: vertical;
  min-height: 38px;
  line-height: 1.4;
}
/* Short, fixed-width message field */
.field__short { width: 200px; max-width: 100%; }

/* Emoji name renders as a pill that hugs :name: (input auto-sizes via its size attr) */
.field__emoji-input {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  width: auto;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 9px;
  background: #fff;
}
.field__emoji-input:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(18, 100, 163, .15);
}
/* Ghost colons: faded, like Slack's auto-wrapped : characters around the name. */
.field__emoji-input span { color: #b7b8ba; font-weight: 400; }
.field__emoji-input input {
  border: none;
  flex: 0 0 auto;
  width: auto;       /* exact px width is set inline by the mirror measurement */
  min-width: 6px;
  padding: 9px 0;
}
.field__emoji-input input:focus-visible { box-shadow: none; }

/* ---------- Download button ---------- */
.download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 18px;
  /* Full-width row beneath the box + settings */
  grid-column: 1 / -1;
  width: 100%;
  border: none;
  border-radius: 8px;
  background: #007a5a;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.download-btn:hover { background: #148567; }
.download-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 122, 90, .3);
}
.download-btn:disabled {
  background: #dddddd;
  color: #9a9b9e;
  cursor: not-allowed;
}

/* ---------- Previews ---------- */
.previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 760px) {
  .previews { grid-template-columns: 1fr; }
}

.preview {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  /* Not overflow:hidden — tooltips need to escape the card. Inner pieces are
     rounded individually instead so the card corners stay clean. */
}
.preview__chrome {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}
.slack {
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}
.preview__dot { width: 10px; height: 10px; border-radius: 50%; }

/* Light Slack theme */
.preview--light .preview__chrome { background: #f8f8f8; color: var(--text); border-bottom: 1px solid var(--border); }
.preview--light .preview__dot { background: #2bac76; }

/* Dark Slack theme */
.preview--dark .preview__chrome { background: #16161a; color: #d1d2d3; border-bottom: 1px solid #2c2d30; }
.preview--dark .preview__dot { background: #2bac76; }

/* ---------- Slack message UI ---------- */
.slack {
  padding: 16px;
  font-size: 15px;
  line-height: 1.46;
}
.preview--light .slack { background: #ffffff; color: #1d1c1d; }
.preview--dark .slack { background: #1a1d21; color: #d1d2d3; }

.msg { display: flex; gap: 10px; }
.msg__avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #ddd url("assets/arnold.png") center / cover no-repeat;
}
.msg__body { min-width: 0; }
.msg__head { display: flex; align-items: baseline; gap: 8px; }
.msg__name { font-weight: 900; font-size: 15px; }
.preview--dark .msg__name { color: #f8f8f8; }
.msg__time { font-size: 12px; color: var(--muted); }
.preview--dark .msg__time { color: #9a9b9e; }
.msg__text { margin-top: 2px; overflow-wrap: anywhere; }
/* Render line breaks typed in the message box (scoped to the text span so the
   template's own indentation isn't preserved). */
.msg__text [data-text] { white-space: pre-wrap; }
/* Inline emoji flows with the text (not a flex item), so wrapping behaves naturally. */
.msg__text .emoji-host { margin: 0 2px; }

/* Reactions */
.msg__reactions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.reaction {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.preview--light .reaction--mine {
  background: #e8f5fa;
  border: 1px solid #1264a3;
  color: #1264a3;
}
.preview--dark .reaction--mine {
  background: rgba(29, 155, 209, .15);
  border: 1px solid #1d9bd1;
  color: #1d9bd1;
}
.reaction--add {
  padding: 0 7px;
  gap: 0;
}
.preview--light .reaction--add {
  background: #f8f8f8;
  border: 1px solid var(--border);
  color: var(--muted);
}
.preview--dark .reaction--add {
  background: rgba(255, 255, 255, .04);
  border: 1px solid #35373b;
  color: #9a9b9e;
}

/* ---------- Emoji rendering ---------- */
.emoji { object-fit: contain; display: inline-block; vertical-align: middle; }
/* display:block removes the inline baseline gap below the image, so the host's
   height equals the emoji and `vertical-align: middle` truly centers it on the text. */
.emoji--inline { width: 22px; height: 22px; display: block; }
.emoji--reaction { width: 16px; height: 16px; }
.emoji:not([src]) { opacity: 0; }

/* Empty state: dim emoji slots until an image is loaded */
.slack:not(.has-emoji) [data-emoji] { visibility: hidden; }

/* ---------- Hover tooltips ---------- */
.emoji-host { position: relative; display: inline-block; vertical-align: middle; }

.tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: #1d1c1d;
  color: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  z-index: 10;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease, transform .12s ease;
  white-space: nowrap;
}
/* Little pointer at the bottom of the bubble */
.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1d1c1d;
}
/* Reveal on hover/focus of the host — only once an image is present */
.slack.has-emoji .emoji-host:hover .tooltip,
.slack.has-emoji .emoji-host:focus-within .tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.tooltip__img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

/* Inline-text tooltip: big emoji + shortcode only */
.tooltip--inline { padding: 12px 18px; }
.tooltip__code {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  color: #d1d2d3;
}

/* Reaction tooltip: big emoji + "you reacted with :code:" */
.tooltip--reaction { width: 210px; white-space: normal; }
.tooltip__title {
  display: block;
  margin-top: 10px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}
.tooltip__sub {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  color: #d1d2d3;
}
.tooltip__sub [data-shortcode] { color: #fff; }
