/* Thumbnail fonts, self-hosted (SIL Open Font License, see fonts/OFL-*.txt) – no calls to Google */
@font-face { font-family: "Anton"; font-weight: 400; font-display: swap; src: url("fonts/anton-regular-latin.woff2") format("woff2"); }
@font-face { font-family: "Bangers"; font-weight: 400; font-display: swap; src: url("fonts/bangers-regular-latin.woff2") format("woff2"); }
@font-face { font-family: "Montserrat"; font-weight: 900; font-display: swap; src: url("fonts/montserrat-black-latin.woff2") format("woff2"); }

/* Arqen colours: near black, purple accent, cyan highlight (as in the Arqen thumbnails and logo) */
:root {
  color-scheme: light dark;
  --bg: #f4f4f7;
  --panel: #ffffff;
  --text: #15151c;
  --dim: #6b6b7b;
  --line: #e2e2ea;
  --accent: #6a4cf0;
  --accent-text: #ffffff;
  --highlight: #0a8fb8;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #07080d;
    --panel: #10111a;
    --text: #f4f4f7;
    --dim: #9b9bad;
    --line: #232435;
    --accent: #6a4cf0;
    --highlight: #2cc8f5;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}

header h1 { margin: 0; font-size: 18px; }
header p { margin: 4px 0 0; color: var(--dim); font-size: 14px; }

main {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  padding: 24px;
  align-items: start;
}

.panel {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
}

input[type="text"], textarea, select {
  font: inherit;
  font-weight: 400;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

textarea { resize: vertical; }

.group { display: flex; flex-direction: column; gap: 8px; }

.face-row { display: flex; gap: 12px; align-items: center; }
.face-row p { margin: 0 0 4px; font-size: 13px; color: var(--dim); }

#face-preview {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  background: repeating-conic-gradient(#d4d4d8 0 25%, #fafafa 0 50%) 0 0 / 16px 16px;
  flex: none;
}

fieldset {
  margin: 0;
  padding: 8px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend { font-size: 13px; font-weight: 600; padding: 0 4px; }

.headlines { display: flex; flex-direction: column; gap: 6px; }

button { font: inherit; cursor: pointer; }

.primary-button {
  padding: 10px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.primary-button:hover { filter: brightness(1.1); }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  font-size: 13px;
  text-decoration: underline;
  text-align: left;
}

.tip { margin: 0; font-size: 12px; color: var(--dim); }

/* Gallery: card width = real display width (default Large) */
.gallery {
  --width: 560px;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--width));
  gap: 28px 20px;
}

.card { margin: 0; }

.card canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  touch-action: pan-y;
}

.card figcaption { padding-top: 8px; }

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-channel { margin: 2px 0 4px; font-size: 12px; color: var(--dim); }

.gallery.compact { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 12px 20px; }
.compact .card { display: flex; gap: 10px; align-items: flex-start; }
.compact .card canvas { width: var(--width); flex: none; border-radius: 8px; }
.compact .card figcaption { padding-top: 0; }

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; padding: 16px; }
  .panel { position: static; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(min(var(--width), 100%), 1fr)); }
  .gallery.compact { grid-template-columns: 1fr; }
}

/* Icons */
.icon-list { display: flex; flex-direction: column; gap: 6px; }
.icon-list:empty { display: none; }
.icon-row { display: flex; align-items: center; gap: 8px; }
.icon-row canvas { width: 32px; height: 32px; flex: none; border-radius: 4px; background: var(--bg); }
.icon-row input[type="range"] { flex: 1; min-width: 0; }
.card canvas.over-icon { cursor: grab; }
.card canvas.dragging { cursor: grabbing; touch-action: none; }

/* Cutout editor */
#editor, #frames {
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
}

#editor[open], #frames[open] { display: flex; flex-direction: column; gap: 12px; }
#editor::backdrop, #frames::backdrop { background: rgb(0 0 0 / 0.6); }

.editor-header h2 { margin: 0; font-size: 16px; }
.editor-header p { margin: 4px 0 0; font-size: 13px; color: var(--dim); }

.editor-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.editor-tools button, .editor-footer button:not(.primary-button) {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.editor-tools button:disabled { opacity: 0.4; cursor: default; }
.editor-toggle { display: flex; }
.editor-toggle button:first-child { border-radius: 8px 0 0 8px; }
.editor-toggle button:last-child { border-radius: 0 8px 8px 0; border-left: 0; }
.editor-toggle button.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.editor-size { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

.editor-surface {
  position: relative;
  display: flex;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
  border-radius: 8px;
}
.editor-surface[data-background="checker"] { background: repeating-conic-gradient(#d4d4d8 0 25%, #fafafa 0 50%) 0 0 / 20px 20px; }
.editor-surface[data-background="dark"] { background: #111114; }
.editor-surface[data-background="light"] { background: #d4ff3a; }

.editor-canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 260px);
  touch-action: none;
  cursor: none;
}

.editor-cursor {
  position: absolute;
  top: 0;
  left: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #000;
  pointer-events: none;
}

.frames-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.frame {
  position: relative;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 6px;
  background: #000;
  overflow: hidden;
  cursor: pointer;
}
.frame canvas { display: block; width: 100%; height: auto; }
.frame span { position: absolute; right: 4px; bottom: 4px; padding: 1px 5px; border-radius: 4px; background: rgb(0 0 0 / 0.7); color: #fff; font-size: 11px; }
.frame[aria-pressed="true"] { border-color: var(--highlight); }
.frames-scrub { display: flex; flex-direction: column; gap: 8px; align-items: center; }
#frames-preview { width: min(100%, 480px); height: auto; border-radius: 8px; background: #000; }
.frames-slider { display: flex; gap: 10px; align-items: center; width: min(100%, 480px); }
.frames-slider input { flex: 1; }
#frames-clock { font-size: 13px; color: var(--dim); min-width: 3.5em; text-align: right; }
.frames-grid:empty { display: none; }

.editor-footer { display: flex; justify-content: flex-end; gap: 8px; }
.editor-footer .primary-button { padding: 8px 20px; }

/* File pickers: our own button and text instead of the browser's (which follows the OS language) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}
.file-picker { position: relative; display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.file-button {
  flex: none;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.file-picker:hover .file-button { border-color: var(--dim); }
.file-picker input:focus-visible + .file-button { outline: 2px solid var(--highlight); outline-offset: 2px; }
.file-picker input:disabled + .file-button { opacity: 0.4; }
.file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--dim); }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; letter-spacing: 0.01em; }
.brand img { flex: none; width: 36px; height: 36px; }
.brand span { color: var(--highlight); }

/* Keyboard focus in Arqen cyan */
:focus-visible { outline: 2px solid var(--highlight); outline-offset: 2px; }
input[type="range"] { accent-color: var(--accent); }

/* Palette picker */
.group-title { font-size: 13px; font-weight: 600; }
.palettes { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.swatch {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--dim);
  font-size: 11px;
  text-align: center;
}
.swatch-color {
  position: relative;
  display: block;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  outline: 2px solid transparent;
  outline-offset: 2px;
}
.swatch-color::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--swatch-accent);
  box-shadow: 0 0 0 2px rgb(0 0 0 / 0.35);
}
.swatch[aria-checked="true"] { color: var(--text); font-weight: 600; }
.swatch[aria-checked="true"] .swatch-color { outline-color: var(--highlight); }
.swatch-custom .swatch-color {
  background: conic-gradient(from 90deg, #ff5f6d, #ffc371, #7cff3f, #2cc8f5, #7b5cff, #ff5f6d);
}

.custom-colors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.custom-colors[hidden] { display: none; }
.color-field { font-weight: 400; font-size: 12px; }
.color-field input { width: 100%; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.warning { grid-column: 1 / -1; margin: 0; font-size: 12px; color: #f5a524; }

.label-fields { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }
.label-fields[hidden] { display: none; }

/* Fields in the panel never grow wider than their column */
.panel input[type="text"], .panel textarea, .panel select { width: 100%; min-width: 0; box-sizing: border-box; }
.label-fields > label, .custom-colors > label { min-width: 0; }

/* Colours extracted from an image */
.extracted { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); }
.extracted[hidden] { display: none; }
.extracted span.dot { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line); flex: none; }

/* Header with account */
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.account { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.account[hidden] { display: none; }
.account-email { color: var(--dim); }
.account-balance { padding: 4px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-weight: 600; }
.account-balance:empty { display: none; }
.primary-button.small, .ghost-button.small { padding: 6px 14px; font-size: 13px; }
.ghost-button { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font-weight: 600; }
.notice { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; }
.notice[hidden] { display: none; }

/* Login and buy dialogs */
.small-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
}
.small-dialog::backdrop { background: rgb(0 0 0 / 0.6); }
.small-dialog h2 { margin: 0 0 10px; font-size: 18px; }
.dialog-reason { margin: 0 0 12px; font-size: 14px; color: var(--highlight); }
.dialog-reason[hidden] { display: none; }
.dialog-form { display: flex; flex-direction: column; gap: 10px; }
.dialog-form[hidden] { display: none; }
.dialog-form input { font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
#login-code { letter-spacing: 0.3em; font-size: 20px; text-align: center; }
.dialog-message { min-height: 1.2em; margin: 10px 0 0; font-size: 13px; color: var(--dim); }
.dialog-close { margin-top: 6px; text-align: right; }
.packs { display: grid; gap: 10px; margin: 12px 0 0; }
.pack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  text-align: left;
}
.pack:hover { border-color: var(--accent); }
.pack span { font-size: 13px; color: var(--dim); }
