:root {
  --bg: #2b2d6e;
  --panel: #383b8a;
  --panel-2: #4a4ea6;
  --text: #fffdf7;
  --muted: #cfd0f5;
  --accent: #ffd23f;
  --accent-text: #2b2d6e;
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 "Trebuchet MS", ui-rounded, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
h1 { margin: 0; line-height: 1.15; }

/* ---------- shared buttons ---------- */
.chip-button {
  min-height: 48px; padding: .45em 1.2em;
  border: 0; border-radius: 999px;
  background: var(--panel-2); font-weight: 700;
}
.chip-button.accent { background: var(--accent); color: var(--accent-text); }
.icon-button {
  width: 48px; height: 48px; flex: none;
  border: 0; border-radius: 14px; background: var(--panel-2); font-size: 1.4rem;
}
.icon-button:disabled { opacity: .35; cursor: default; }

/* ---------- gallery ---------- */
.home { max-width: 1100px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 32px; }
.home-head { display: flex; align-items: center; gap: 14px; }
.home-logo { width: 64px; height: 64px; }
.home-head h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); }
.home-note { color: var(--muted); margin: 10px 0 20px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.card {
  position: relative; aspect-ratio: 4 / 3; padding: 0; overflow: hidden;
  border: 0; border-radius: var(--radius); background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25);
}
.card-open { width: 100%; height: 100%; padding: 0; border: 0; background: none; }
.card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.new-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  background: var(--accent); color: var(--accent-text); font-size: 1.1rem;
}
.big-plus { font-size: 3rem; line-height: 1; font-weight: 700; }
.card-delete {
  position: absolute; top: 6px; right: 6px; width: 38px; height: 38px;
  border: 0; border-radius: 50%; background: rgba(43, 45, 110, .8); font-size: 1.1rem;
}
.card-badge {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px;
  background: rgba(43, 45, 110, .85); font-size: .75rem;
}

/* ---------- easel ---------- */
.editor { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
}
.spacer { flex: 1; }
.save-status { color: var(--muted); font-size: .9rem; }
.workspace { flex: 1; min-height: 0; display: flex; gap: 8px; padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); }
.tools { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.tool {
  width: 72px; min-height: 64px; flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 3px solid transparent; border-radius: 16px; background: var(--panel); font-size: 1.7rem;
}
.tool span { font-size: .72rem; font-weight: 700; margin-top: 2px; }
.tool[aria-pressed="true"] { border-color: var(--accent); background: var(--panel-2); }
.stage { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; }
#canvas {
  background: #fff; border-radius: 10px; box-shadow: 0 4px 0 rgba(0, 0, 0, .25);
  touch-action: none; cursor: crosshair;
}

.tray {
  display: flex; align-items: center; gap: 14px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--panel-2) transparent;
  padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}
.sizes { display: flex; gap: 6px; flex: none; padding-right: 14px; border-right: 2px solid var(--panel-2); }
.size {
  width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
  border: 3px solid transparent; border-radius: 14px; background: var(--panel);
}
.size i { display: block; border-radius: 50%; background: var(--text); }
.size[aria-pressed="true"] { border-color: var(--accent); }
.swatches { display: flex; gap: 8px; flex: none; }
.swatch {
  width: 44px; height: 44px; flex: none;
  border: 3px solid rgba(255, 255, 255, .35); border-radius: 50%;
}
.swatch[aria-pressed="true"] { border-color: var(--accent); transform: scale(1.15); box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--accent); }
.stamps .swatch { background: var(--panel); border-color: transparent; font-size: 1.6rem; line-height: 1; padding: 0; }
.stamps .swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: none; }

/* Phones held upright: the tools move above the picture. */
@media (max-aspect-ratio: 1/1) {
  .workspace { flex-direction: column; }
  .tools { flex-direction: row; overflow-x: auto; overflow-y: visible; }
  .tool { flex: 1; width: auto; min-width: 56px; min-height: 58px; }
  .tray { flex-direction: column; gap: 10px; overflow: visible; }
  .sizes { padding-right: 0; border-right: 0; }
  .swatches { flex: initial; flex-wrap: wrap; justify-content: center; }
}

/* ---------- dialog and toast ---------- */
.ask { border: 0; border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 20px; max-width: min(360px, calc(100vw - 32px)); }
.ask::backdrop { background: rgba(0, 0, 0, .5); }
.ask p { margin: 0 0 16px; font-size: 1.15rem; font-weight: 700; text-align: center; }
.ask-buttons { display: flex; gap: 12px; justify-content: center; }
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: #15163a; color: var(--text); box-shadow: 0 6px 20px rgba(0, 0, 0, .4); z-index: 10;
}
