@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/inter-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/inter-700.woff2') format('woff2');
}

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1d24;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-dark: #4338ca;
  --accent-fg: #fff;
  --accent-tint: rgba(79, 70, 229, .1);
  --border: #e5e7eb;
  --hover: rgba(0, 0, 0, .05);
  --preview-bg: #dfe2e8;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --toast-bg: #1a1d24;
  --toast-fg: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161a;
    --surface: #1f2127;
    --text: #e8e9ee;
    --muted: #9ba1ad;
    --accent: #a5b4fc;
    --accent-fg: #15161a;
    --accent-dark: #6d78f6;
    --accent-tint: rgba(129, 140, 248, .16);
    --border: #30333c;
    --hover: rgba(255, 255, 255, .07);
    --preview-bg: #0e0f12;
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, .15);
    --toast-bg: #e8e9ee;
    --toast-fg: #15161a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15161a;
  --surface: #1f2127;
  --text: #e8e9ee;
  --muted: #9ba1ad;
  --accent: #a5b4fc;
  --accent-fg: #15161a;
  --accent-dark: #6d78f6;
  --accent-tint: rgba(129, 140, 248, .16);
  --border: #30333c;
  --hover: rgba(255, 255, 255, .07);
  --preview-bg: #0e0f12;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, .15);
  --toast-bg: #e8e9ee;
  --toast-fg: #15161a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.view { height: 100%; }
[hidden] { display: none !important; }

.account-panel { padding: 20px; margin-bottom: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.account-panel h2 { margin: 0; font-size: 18px; }
.account-panel p { line-height: 1.55; overflow-wrap: anywhere; }
.account-panel p:empty { display: none; }
.account-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.account-actions .btn { min-height: 44px; white-space: normal; }
.account-actions [aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); box-shadow: inset 0 0 0 1px var(--accent); }
.account-form { display: grid; gap: 14px; max-width: 440px; margin-top: 20px; }
.account-form label { display: grid; gap: 6px; font-weight: 700; }
.account-form input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.account-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.account-form p { margin: 0; font-size: 14px; }
.autosave-note { flex: 0 0 auto; margin: 0; padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12px; line-height: 1.5; }
.recovery-panel { padding: 16px; margin-bottom: 20px; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--accent-tint); }
.recovery-panel h3 { margin: 0 0 8px; }
.recovery-panel p { line-height: 1.5; overflow-wrap: anywhere; }
@media (max-width: 480px) { .account-panel { padding: 16px; } .account-actions .btn { flex: 1 1 auto; } }

/* ---------- Galleri ---------- */

.app-header {
  padding: 36px 32px 8px;
  text-align: center;
}

.logo {
  margin: 0;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -1.5px;
}
.logo span { color: var(--accent); }

.tagline {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 15px;
  line-height: 1.5;
}

.install-area { margin-top: 12px; }
.install-area .btn { font-size: 15px; padding: 11px 26px; }
.install-tip {
  color: var(--muted);
  font-size: 14px;
  max-width: 64ch;
  margin: 0 auto;
  line-height: 1.5;
}

.gallery-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 32px 64px;
}

.gallery-main h2 {
  font-size: 18px;
  margin: 28px 0 16px;
}

/* Collapsed settings keep the original numbered editor usable on small screens. */
#site-settings { padding: 0 16px 20px; }
.settings-disclosure { margin: 0 16px 16px; border: 1px solid var(--border); border-radius: 9px; }
.settings-disclosure > summary { padding: 14px 12px; min-height: 48px; font-size: 14px; font-weight: 700; cursor: pointer; color: var(--text); }
.site-group { border-bottom: 1px solid var(--border); padding: 4px 0; }
.site-group > summary { font-weight: 700; font-size: 14px; cursor: pointer; min-height: 48px; padding: 14px 2px; overflow-wrap: anywhere; }
.site-group .site-group { margin: 0 4px 8px; }
.settings-note { font-size: 13px; line-height: 1.6; color: var(--muted); margin: 10px 0 16px; }
.settings-field { display: grid; gap: 7px; margin: 14px 0; font-size: 13px; font-weight: 600; }
.settings-field input, .settings-field textarea, .settings-field select { width: 100%; min-width: 0; min-height: 46px; padding: 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); font: 400 16px/1.5 Inter, sans-serif; }
.settings-field [aria-invalid=true] { border-color: var(--danger); outline-color: var(--danger); }
.settings-check { display: flex; gap: 12px; align-items: center; min-height: 46px; font-size: 14px; line-height: 1.5; cursor: pointer; }
.settings-check input { width: 20px; height: 20px; flex: 0 0 20px; accent-color: var(--accent); }
.site-group .btn { margin: 8px 0; white-space: normal; width: 100%; }
#export-review { max-height: 42vh; overflow-y: auto; padding-right: 12px; }
.section-head h2 { margin: 0; }
.projects-section { padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.projects-section .empty-note { margin-top: 12px; line-height: 1.5; }

.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 24px;
}

.template-card {
  container-type: inline-size;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform .15s ease, box-shadow .15s ease;
}
.template-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 24px rgba(0,0,0,.12);
}

.thumb {
  position: relative;
  height: 190px;
  overflow: hidden;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.thumb iframe {
  width: 1200px;
  height: 900px;
  border: 0;
  transform: scale(0.2375);
  transform-origin: top left;
  pointer-events: none;
}

.card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-title { font-weight: 700; font-size: 16px; line-height: 1.4; }
.card-cat {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 99px;
  padding: 2px 10px;
  width: fit-content;
}

.card-actions { margin-top: auto; display: grid; gap: 8px; }
@container (min-width: 320px) {
  .card-actions { grid-template-columns: 1fr 1fr; }
  .card-actions .btn { padding-inline: 8px; }
}
.storage-note { font-size: 14px; line-height: 1.5; color: var(--muted); }

/* ---------- Mina projekt ---------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.btn-small { font-size: 13px; padding: 6px 12px; }
.empty-note { color: var(--muted); font-size: 14px; margin: 4px 0 0; }

.project-list { display: flex; flex-direction: column; gap: 10px; }

.project-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.project-row .p-name { font-weight: 700; min-width: 0; overflow-wrap: anywhere; flex: 1; }
.project-row .p-meta { color: var(--muted); font-size: 13px; }
.project-row .p-actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }
.project-list:not(:empty) { margin-top: 16px; }
.project-row { box-shadow: none; }
.version-list { display: grid; gap: 12px; }
#versions-section { margin-top: 24px; }
.version-row { display: flex; align-items: center; gap: 16px; padding: 16px 0; border-top: 1px solid var(--border); }
.version-description { flex: 1; min-width: 0; }
.version-name { margin: 0 0 6px; font-size: 16px; overflow-wrap: anywhere; }
.version-meta { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
.version-row .btn { flex-shrink: 0; white-space: normal; }
.version-actions { display: flex; flex-wrap: wrap; gap: 10px; max-width: 440px; }
.version-download-status { font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; margin: 8px 0 0; }
.version-download-status:empty { display: none; }
.version-delete-name { font-weight: 700; overflow-wrap: anywhere; }
.version-delete-check { display: flex; align-items: center; gap: 12px; min-height: 48px; line-height: 1.5; cursor: pointer; }
.version-delete-check input { width: 20px; height: 20px; flex-shrink: 0; }
#versions-section > p { line-height: 1.6; }
@media (max-width: 900px) {
  .version-row { align-items: stretch; flex-direction: column; gap: 10px; }
  .version-row .btn { align-self: flex-start; }
}
@media (min-width: 641px) and (max-width: 1000px) {
  .project-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; }
  .project-row .p-meta { grid-column: 1; }
  .project-row .p-actions { grid-column: 2; grid-row: 1 / 3; }
}

@media (max-width: 640px) {
  .project-row { flex-wrap: wrap; }
  .project-row .p-name, .project-row .p-meta { flex-basis: 100%; }
  .project-row .p-actions { margin-left: 0; width: 100%; flex-wrap: wrap; }
}

@media (max-width: 760px) {
  .gallery-main { padding-left: 16px; padding-right: 16px; }
  .app-header { padding: 24px 16px 4px; }
  .logo { font-size: 34px; }
  .projects-section { padding: 16px; }
  .thumb { height: 170px; }
}

/* ---------- Knappar ---------- */

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); background: var(--hover); }
.btn-ghost.active { color: var(--accent); background: var(--accent-tint); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover, .btn-danger[data-armed] { background: var(--danger-bg); }
button:disabled { opacity: .6; cursor: wait; }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------- Editor ---------- */

#view-editor {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.editor-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.project-name-input {
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 10px;
  width: 240px;
  background: transparent;
  color: var(--text);
  min-width: 0;
  min-height: 44px;
}
.project-name-input:hover { border-color: var(--border); }
.project-name-input:focus { border-color: var(--accent); outline: none; background: var(--surface); }

.topbar-spacer { flex: 1; }
.device-toggle { display: flex; gap: 4px; margin-right: 8px; }
.save-status { font-size: 12px; color: var(--muted); }
.editor-more { position: relative; }
.editor-more summary { list-style: none; display: flex; align-items: center; }
.editor-more summary::-webkit-details-marker { display: none; }
.more-actions {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  display: grid; gap: 8px; padding: 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}

.page-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.page-tab {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  min-height: 44px;
}
.page-tab:hover { background: var(--bg); color: var(--text); }
.page-tab.active {
  color: var(--accent);
  background: var(--accent-tint);
  border-color: var(--accent);
}

.editor-body {
  flex: 1;
  display: flex;
  min-height: 0;
  min-width: 0;
}

.editor-panel {
  width: 340px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 18px;
}

.panel-intro { margin-bottom: 18px; }
.panel-intro strong { font-size: 15px; }
.panel-intro p { color: var(--muted); font-size: 13px; margin: 6px 0 0; line-height: 1.5; }

.slot-field {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.slot-field.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}

.slot-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.slot-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.slot-label { font-size: 13px; font-weight: 600; }
.slot-type { margin-left: auto; font-size: 11px; color: var(--muted); }

.slot-field input[type="text"],
.slot-field textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  resize: vertical;
  min-height: 44px;
  background: var(--bg);
  color: var(--text);
}
.slot-field input[type="text"]:focus,
.slot-field textarea:focus { border-color: var(--accent); outline: none; }
.slot-field input[type="text"]:focus-visible,
.slot-field textarea:focus-visible { box-shadow: 0 0 0 3px var(--accent-tint); }

.img-field { display: flex; align-items: center; gap: 10px; }
.img-preview {
  width: 72px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.img-field input[type="file"] { display: none; }
.img-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(79,70,229,.08);
  border: 1px dashed rgba(79,70,229,.4);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  min-height: 44px;
}
.img-btn:hover { background: rgba(79,70,229,.15); }

.editor-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--preview-bg);
  padding: 12px;
  gap: 10px;
  overflow: hidden;
}
.preview-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.preview-viewport { flex: 1; min-height: 0; min-width: 0; display: flex; justify-content: center; overflow: hidden; }
#preview-stage { position: relative; flex-shrink: 0; }

#preview-frame {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  border: 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.preview-only .editor-panel { display: none; }
.shared-field { margin-top: 10px; white-space: normal; font-size: 12px; width: 100%; }

dialog {
  max-width: 520px; width: calc(100% - 32px); max-height: calc(100dvh - 32px);
  padding: 24px; border: 1px solid var(--border); border-radius: 16px;
  color: var(--text); background: var(--surface); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { font-size: 21px; margin-top: 0; }
dialog p, dialog li { font-size: 14px; line-height: 1.6; }
.dialog-error { color: var(--danger); font-weight: 600; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.dialog-actions .btn { white-space: normal; }
.publish-label { display: block; font-weight: 600; font-size: 14px; margin: 6px 0 8px; }
.publish-address { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.publish-address input { flex: 1 1 160px; min-width: 0; min-height: 46px; padding: 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); font: 400 16px/1.5 Inter, sans-serif; }
.publish-address span { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
#publish-status, #publish-error { overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .editor-panel { width: 300px; }
  .save-status { width: 100%; }
}
@media (max-width: 760px) {
  .editor-topbar { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; padding: 8px 12px; }
  .project-name-input { grid-column: 2 / 4; width: 100%; font-size: 16px; }
  .topbar-spacer { display: none; }
  .save-status { grid-column: 1 / -1; }
  .editor-more summary { justify-content: center; }
  .editor-body { flex-direction: column; }
  .editor-panel { width: 100%; flex: 1; min-height: 0; border: 0; padding: 16px; }
  .editor-preview { display: none; padding: 8px; }
  .preview-only .editor-preview { display: flex; }
  .slot-field input[type="text"], .slot-field textarea { font-size: 16px; }
  .page-tabs { padding: 4px 12px; flex-shrink: 0; }
  .section-head { flex-wrap: wrap; }
  .project-row .p-name { overflow-wrap: anywhere; }
  .toast { max-width: calc(100% - 24px); width: max-content; border-radius: 12px; }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
  z-index: 1000;
  animation: toast-in .2s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  .template-card:hover { transform: none; }
}
