/* Collage Studio — Windows 11 (Fluent) inspired styling. Light and dark. */

:root {
  --font-ui: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --bg: #f3f3f3;
  --panel: #fbfbfb;
  --panel-2: #ffffff;
  --stage: #e6e7ea;
  --border: #e0e0e0;
  --border-strong: #c8c8c8;
  --text: #1b1b1b;
  --text-2: #5c5c5c;
  --text-3: #8a8a8a;
  --accent: #0f6cbd;
  --accent-hover: #115ea3;
  --accent-text: #ffffff;
  --accent-soft: #e8f1fb;
  --danger: #c42b1c;
  --hover: rgba(0, 0, 0, 0.05);
  --pressed: rgba(0, 0, 0, 0.09);
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --radius-sm: 5px;
  --focus: 0 0 0 2px var(--panel-2), 0 0 0 4px var(--accent);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202020;
    --panel: #2b2b2b;
    --panel-2: #323232;
    --stage: #1a1a1a;
    --border: #3a3a3a;
    --border-strong: #505050;
    --text: #f3f3f3;
    --text-2: #c5c5c5;
    --text-3: #9a9a9a;
    --accent: #4cc2ff;
    --accent-hover: #62cdff;
    --accent-text: #000000;
    --accent-soft: #1f3a4d;
    --hover: rgba(255, 255, 255, 0.06);
    --pressed: rgba(255, 255, 255, 0.1);
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 var(--font-ui);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.icon { flex: none; display: block; }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr) 312px;
  grid-template-rows: auto minmax(0, 1fr) 132px;
  grid-template-areas: "toolbar toolbar toolbar" "pages stage inspector" "tray tray inspector";
  height: 100vh;
}
.toolbar { grid-area: toolbar; }
.pages { grid-area: pages; }
.stage { grid-area: stage; }
.inspector { grid-area: inspector; }
.tray { grid-area: tray; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 5px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel-2); cursor: pointer; white-space: nowrap;
  transition: background 0.1s;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--pressed); }
.btn:disabled { opacity: 0.45; cursor: default; background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 44px; padding: 10px 20px; font-size: 15px; font-weight: 600; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.icon-only { padding: 5px; min-width: 32px; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 64px; height: 52px; padding: 4px 8px;
  border: 0; border-radius: var(--radius-sm); background: transparent; cursor: pointer;
  font-size: 12px; color: var(--text);
}
.tool:hover { background: var(--hover); }
.tool:active { background: var(--pressed); }
.tool:disabled { opacity: 0.4; cursor: default; background: transparent; }
.tool .dot { position: absolute; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--panel-2); }
.seg > button { border: 0; background: transparent; padding: 5px 10px; min-height: 30px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.seg > button + button { border-left: 1px solid var(--border); }
.seg > button:hover { background: var(--hover); }
.seg > button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.seg.full { display: flex; }
.seg.full > button { flex: 1; justify-content: center; }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 8px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.toolbar .sep { width: 1px; height: 32px; background: var(--border); margin: 0 6px; }
.toolbar .spacer { flex: 1; }
.toolbar .title-input {
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-sm);
  padding: 5px 8px; font-size: 15px; font-weight: 600; text-align: center; min-width: 120px; max-width: 320px;
}
.toolbar .title-input:hover { border-color: var(--border); }
.toolbar .title-input:focus { border-color: var(--accent); background: var(--panel-2); }
.toolbar .dirty-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: -2px; }
.tool-wrap { position: relative; }
.brand { display: flex; align-items: center; gap: 8px; padding: 0 10px 0 4px; font-weight: 600; }
.brand img { width: 26px; height: 26px; border-radius: 6px; }

/* ---------- pages strip ---------- */
.pages {
  display: flex; flex-direction: column; gap: 8px; padding: 10px 10px 12px;
  background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto;
}
.pages h2, .inspector h2, .tray h2 { font-size: 12px; font-weight: 600; color: var(--text-2); margin: 0; text-transform: uppercase; letter-spacing: 0.04em; }
.page-thumb {
  position: relative; display: block; width: 100%; padding: 6px; border: 2px solid transparent;
  border-radius: var(--radius); background: transparent; cursor: pointer;
}
.page-thumb:hover { background: var(--hover); }
.page-thumb[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.page-thumb canvas { display: block; margin: 0 auto; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); background: #fff; }
.page-thumb .num { display: block; text-align: center; font-size: 12px; color: var(--text-2); margin-top: 4px; }
.page-thumb .actions { position: absolute; top: 4px; right: 4px; display: none; gap: 2px; }
.page-thumb:hover .actions, .page-thumb:focus-within .actions { display: flex; }
.page-thumb .actions button { width: 26px; height: 26px; padding: 0; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 4px; background: var(--panel-2); cursor: pointer; }
.page-thumb.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.page-thumb.drop-after { box-shadow: 0 3px 0 var(--accent); }

/* ---------- stage ---------- */
.stage { position: relative; background: var(--stage); overflow: hidden; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; outline: none; }
.stage.drop-files::after {
  content: "Drop photos to add them"; position: absolute; inset: 12px; display: grid; place-items: center;
  border: 3px dashed var(--accent); border-radius: 12px; font-size: 18px; font-weight: 600; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent); pointer-events: none;
}
.stage-hud { position: absolute; inset: 0; pointer-events: none; }
.stage-hud > * { pointer-events: auto; }
.zoom-bar {
  position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 2px;
  padding: 3px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.zoom-bar output { min-width: 48px; text-align: center; font-size: 12px; color: var(--text-2); }
.crop-bar {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-radius: var(--radius); background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.crop-bar input[type=range] { width: 160px; }
.crop-bar span { white-space: nowrap; }
.text-editor {
  position: absolute; margin: 0; border: 0; outline: 2px dashed var(--accent); outline-offset: 0;
  background: transparent; resize: none; overflow: hidden; white-space: pre-wrap; word-break: break-word;
  transform-origin: center center; caret-color: var(--accent);
}
.drag-ghost {
  position: fixed; z-index: 1000; pointer-events: none; width: 96px; height: 72px; border-radius: 6px;
  object-fit: cover; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35); opacity: 0.9; transform: translate(-50%, -50%) rotate(-3deg);
}

/* ---------- inspector ---------- */
.inspector {
  background: var(--panel); border-left: 1px solid var(--border); overflow-y: auto;
  display: flex; flex-direction: column;
}
.panel-head { padding: 14px 16px 6px; display: flex; align-items: center; gap: 8px; }
.panel-head h1 { font-size: 16px; margin: 0; font-weight: 600; flex: 1; }
.section { padding: 10px 16px 14px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.section:first-of-type { border-top: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row > label, .field > label { color: var(--text-2); font-size: 13px; }
.row.wrap { flex-wrap: wrap; }
.grid-btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(58px, 1fr)); gap: 6px; }
.grid-btns .btn { flex-direction: column; gap: 3px; padding: 6px 4px; font-size: 12px; min-height: 52px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.slider { display: grid; grid-template-columns: 22px 1fr 44px; align-items: center; gap: 8px; }
.slider label { color: var(--text-2); font-size: 13px; grid-column: 1 / -1; margin-bottom: -6px; }
.slider .icon { color: var(--text-2); }
.slider output { font-size: 12px; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--text-3); margin: 0; }
.hint a { color: var(--accent); }
textarea.text-input {
  width: 100%; min-height: 72px; resize: vertical; padding: 8px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--panel-2);
}
textarea.text-input:focus, .num-input:focus { border-color: var(--accent); outline: none; }
.num-input { width: 64px; padding: 4px 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel-2); }
.shapes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.shapes button {
  aspect-ratio: 1; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel-2); cursor: pointer; color: var(--text-2);
}
.shapes button:hover { background: var(--hover); }
.shapes button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.shapes svg { width: 100%; height: 100%; display: block; }
.swatches { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.2); cursor: pointer; padding: 0;
  position: relative;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.swatch.none { background: linear-gradient(135deg, #fff 45%, #d13438 45%, #d13438 55%, #fff 55%); }
.swatch.custom { overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.swatch.custom input { position: absolute; inset: -8px; width: 40px; height: 40px; opacity: 0; cursor: pointer; }
.layout-preview { display: flex; align-items: center; gap: 12px; }
.layout-preview canvas { border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }

/* font picker */
.font-picker { position: relative; }
.font-picker > button { width: 100%; justify-content: space-between; font-size: 16px; min-height: 38px; }
.font-list {
  position: absolute; z-index: 50; left: 0; right: 0; top: calc(100% + 4px); max-height: 360px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px;
}
.font-list h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); margin: 8px 8px 2px; }
.font-list button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 10px; font-size: 19px; border-radius: 4px; cursor: pointer; }
.font-list button:hover, .font-list button:focus-visible { background: var(--hover); }
.font-list button[aria-selected="true"] { background: var(--accent-soft); }

/* ---------- tray ---------- */
.tray {
  display: flex; align-items: stretch; gap: 10px; padding: 8px 10px;
  background: var(--panel); border-top: 1px solid var(--border); min-width: 0;
}
.tray-actions { display: flex; flex-direction: column; gap: 6px; justify-content: center; flex: none; width: 128px; }
.tray-photos { display: flex; gap: 8px; overflow-x: auto; align-items: center; flex: 1; padding: 4px 2px; min-width: 0; }
.tray-empty { color: var(--text-3); display: flex; align-items: center; gap: 8px; padding: 0 12px; }
.tray.drop-files { outline: 3px dashed var(--accent); outline-offset: -4px; }
.tray.drop-remove { background: color-mix(in srgb, var(--danger) 10%, var(--panel)); outline: 3px dashed var(--danger); outline-offset: -4px; }
.tray-photo {
  position: relative; flex: none; height: 96px; border-radius: 6px; overflow: hidden;
  border: 2px solid transparent; background: var(--panel-2); cursor: grab;
}
.tray-photo:hover { border-color: var(--border-strong); }
.tray-photo img { height: 100%; display: block; pointer-events: none; }
.tray-photo .badge {
  position: absolute; left: 4px; bottom: 4px; display: flex; align-items: center; gap: 2px;
  background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 6px 1px 3px;
}
.tray-photo .remove {
  position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; display: none; place-items: center;
  padding: 0; border: 0; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; cursor: pointer;
}
.tray-photo:hover .remove, .tray-photo:focus-within .remove { display: grid; }

/* ---------- start screen ---------- */
.start { position: fixed; inset: 0; overflow-y: auto; background: var(--bg); display: flex; justify-content: center; }
.start-inner { width: min(960px, 100%); padding: 48px 24px; display: flex; flex-direction: column; gap: 28px; }
.start-hero { display: flex; align-items: center; gap: 20px; }
.start-hero img { width: 72px; height: 72px; border-radius: 16px; box-shadow: var(--shadow); }
.start-hero h1 { font-size: 32px; margin: 0; }
.start-hero p { margin: 4px 0 0; color: var(--text-2); font-size: 16px; }
.start-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid var(--accent);
}
.banner p { margin: 0; flex: 1; }
.recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.recent-card {
  display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); cursor: pointer; text-align: left; position: relative;
}
.recent-card:hover { border-color: var(--border-strong); background: var(--panel-2); }
.recent-card img { width: 100%; aspect-ratio: 4 / 5; object-fit: contain; background: var(--stage); border-radius: 4px; }
.recent-card strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-card small { color: var(--text-3); }
.recent-card .forget { position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; padding: 0; display: none; place-items: center; border: 0; border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff; cursor: pointer; }
.recent-card:hover .forget { display: grid; }
.start h2 { font-size: 16px; margin: 0 0 10px; }
.start-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: 36px; align-items: center; }
.start-intro { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.installed-only { display: none; }
.start-sample { width: 100%; height: auto; border-radius: 14px; box-shadow: var(--shadow); }
.features { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.features li { display: flex; align-items: center; gap: 12px; color: var(--text-2); font-size: 15px; }
.features .icon { color: var(--accent); }
@media (max-width: 820px) { .start-top { grid-template-columns: 1fr; } }
/* The installed app goes straight to work: no sales pitch. */
@media (display-mode: standalone), (display-mode: window-controls-overlay) {
  .promo { display: none !important; }
  .installed-only { display: inline; }
  .start-top { grid-template-columns: 1fr; }
}

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3); max-width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dlg-head { padding: 18px 22px 6px; }
.dlg-head h1 { margin: 0; font-size: 20px; }
.dlg-head p { margin: 4px 0 0; color: var(--text-2); }
.dlg-body { padding: 10px 22px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.dlg-foot { padding: 14px 22px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); background: var(--bg); border-radius: 0 0 12px 12px; }
.dlg-body h2 { font-size: 13px; margin: 0; color: var(--text-2); font-weight: 600; }
.size-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.size-tile, .layout-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2); cursor: pointer;
}
.size-tile:hover, .layout-tile:hover { background: var(--hover); }
.size-tile[aria-pressed="true"], .layout-tile[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.size-tile .shape { border: 1.5px solid var(--text-2); border-radius: 2px; background: var(--panel); }
.size-tile strong { font-size: 13px; font-weight: 600; }
.size-tile small { font-size: 11px; color: var(--text-3); }
.layout-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.layout-tile canvas { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); border-radius: 2px; }
.layout-tile span { font-size: 12px; color: var(--text-2); text-align: center; }
.custom-size { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; }
.choice {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel-2); cursor: pointer; flex: 1; min-width: 180px;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice strong { display: block; }
.choice small { color: var(--text-2); }

/* ---------- menus, toasts ---------- */
.menu {
  position: fixed; z-index: 2000; min-width: 200px; padding: 4px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; background: transparent;
  border-radius: 4px; text-align: left; cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.menu kbd { margin-left: auto; font: 12px var(--font-ui); color: var(--text-3); }
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 3000; align-items: center; }
.toast {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: var(--radius);
  background: #2b2b2b; color: #fff; box-shadow: var(--shadow); max-width: min(560px, calc(100vw - 32px));
  animation: toast-in 0.18s ease-out;
}
.toast.error { background: #a4262c; }
.toast button { background: transparent; border: 1px solid rgba(255, 255, 255, 0.5); color: #fff; border-radius: 4px; padding: 3px 10px; cursor: pointer; }
.progress { width: 100%; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width 0.2s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- print ---------- */
.print-root { display: none; }
@media print {
  body { background: #fff; overflow: visible; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block; }
  .print-root img { display: block; page-break-after: always; break-after: page; }
  .print-root img:last-child { page-break-after: auto; break-after: auto; }
}

/* ---------- screen-reader-only text ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- short windows (laptops at 150% scaling) ---------- */
@media (max-height: 760px) {
  .app { grid-template-rows: auto minmax(0, 1fr) 100px; }
  .tool { height: 44px; }
  .tray-photo { height: 72px; }
  .tray-actions .btn { min-height: 30px; padding: 3px 10px; }
}

/* ---------- narrow windows ---------- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 112px minmax(0, 1fr) 280px; }
  .tool { min-width: 52px; font-size: 11px; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr) 260px; grid-template-areas: "toolbar toolbar" "stage inspector" "tray inspector"; }
  .pages { display: none; }
  .tool span { display: none; }
  .tool { min-width: 40px; height: 40px; }
}
