/* generate — valkoinen/musta, koralli aksentti. Otsikot Instrument Serif, teksti Geist. */

:root {
  --accent: #F2542D;
  --accent-ink: #ffffff;
  --accent-soft: rgba(242, 84, 45, 0.1);
  --bg: #ffffff;
  --surface: #f6f6f7;
  --surface-2: #ececee;
  --line: #e3e3e6;
  --ink: #131314;
  --ink-2: #55555b;
  --ink-3: #8b8b92;
  --danger: #c4262e;
  --radius: 14px;
  --radius-sm: 9px;
  --serif: "Instrument Serif", "Times New Roman", serif;
  --sans: "Geist", ui-sans-serif, system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 30px rgba(0,0,0,.06);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0e0e0f;
  --surface: #18181a;
  --surface-2: #222225;
  --line: #2b2b2f;
  --ink: #f2f2f3;
  --ink-2: #b4b4bb;
  --ink-3: #7c7c84;
  --accent-soft: rgba(242, 84, 45, 0.16);
  --danger: #ff6b6b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
::selection { background: var(--accent); color: #fff; }

.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico-sm { width: 16px; height: 16px; }

.display { font-family: var(--serif); font-weight: 400; letter-spacing: -0.01em; line-height: 1.02; }

/* ---------- Yläpalkki ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(16px, 3vw, 40px);
  padding-top: max(14px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; }
.brand-word { font-family: var(--serif); font-style: italic; font-size: 28px; line-height: 1; letter-spacing: -0.02em; }
.topbar-right { display: flex; align-items: center; gap: 6px; }
.machine {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-2); padding: 6px 12px; border-radius: 99px; background: var(--surface);
  margin-right: 6px; white-space: nowrap;
}
.machine-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.machine.on .machine-dot { background: #1f9d55; }
.machine.busy .machine-dot { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.machine.off .machine-dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink-3); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- Napit ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--bg); cursor: pointer; text-decoration: none; font-weight: 500; font-size: 14px;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #e04720; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 26px; font-size: 16px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }

/* ---------- Kirjautuminen ---------- */
.login {
  min-height: calc(100vh - 70px);
  display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 40px;
  padding: 20px clamp(20px, 6vw, 90px) 60px;
}
.login-box { max-width: 440px; }
.login .display { font-size: clamp(52px, 7vw, 92px); margin: 0 0 20px; }
.login .display em { color: var(--accent); }
.lede { color: var(--ink-2); font-size: 17px; margin: 0 0 28px; }
.note { color: var(--ink-3); font-size: 14px; }
.admin-login { margin-top: 28px; color: var(--ink-2); }
.admin-login summary { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.admin-login form { display: grid; gap: 12px; margin-top: 16px; max-width: 300px; }
.admin-login label { display: grid; gap: 4px; font-size: 13px; }
.login-art { position: relative; height: min(70vh, 560px); }
.sheet { position: absolute; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
.sheet-a3 { width: 52%; aspect-ratio: 1 / 1.414; left: 8%; top: 4%; transform: rotate(-6deg); }
.sheet-a4 {
  width: 40%; aspect-ratio: 1 / 1.414; left: 42%; top: 22%; transform: rotate(4deg);
  background: linear-gradient(180deg, #2c2f6b 0%, #c4466a 55%, #f2542d 100%);
  border: 10px solid #fff; box-shadow: var(--shadow); overflow: visible;
}
.sheet-a4 .sun { position: absolute; width: 38%; aspect-ratio: 1; border-radius: 50%; background: #ffd7c8; right: -12%; top: -9%; box-shadow: 0 0 0 10px var(--bg); }

/* ---------- Sovelluksen asettelu ---------- */
.app {
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  gap: clamp(24px, 4vw, 64px);
  padding: 8px clamp(16px, 3vw, 40px) 80px;
  align-items: start;
}
.studio { position: sticky; top: 76px; max-height: calc(100vh - 90px); overflow: auto; padding: 4px 6px 20px 2px; scrollbar-width: thin; }

.idea-block { margin-bottom: 26px; }
.idea-label { display: block; font-size: clamp(44px, 5vw, 64px); margin: 6px 0 14px; }
textarea#idea {
  width: 100%; resize: vertical; min-height: 120px;
  border: 0; border-bottom: 2px solid var(--ink); border-radius: 0;
  padding: 4px 0 12px; background: transparent;
  font-family: var(--serif); font-size: 24px; line-height: 1.25;
}
textarea#idea::placeholder { color: var(--ink-3); font-style: italic; }
textarea#idea:focus { outline: none; border-bottom-color: var(--accent); }
.idea-tools { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.idea-tools .btn { margin-left: -12px; }

.field { display: grid; gap: 8px; margin: 0 0 22px; border: 0; padding: 0; min-width: 0; }
.field-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); padding: 0; margin-bottom: 8px; }
.field > .field-label { margin-bottom: 0; }
.opt { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink-3); }
.hint { font-size: 13px; color: var(--ink-3); }
.field-row { display: grid; grid-template-columns: 1fr auto; gap: 18px; }

input:not([type=radio]):not([type=checkbox]), select {
  width: 100%; padding: 11px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg);
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b8b92' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; padding-right: 36px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--bg); border-radius: 99px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; transition: all .12s;
}
.chip:hover { border-color: var(--ink-3); }
.chip[aria-checked="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.papers { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; align-items: end; }
.paper {
  display: grid; justify-items: center; gap: 8px; padding: 12px 4px 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; font-size: 12.5px;
}
.paper-shape { border: 1.6px solid currentColor; border-radius: 2px; }
.paper[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.paper[aria-checked="true"] .paper-shape { background: var(--accent); border-color: var(--accent); }

.seg { display: inline-flex; padding: 3px; border-radius: 99px; background: var(--surface); gap: 2px; }
.seg button {
  border: 0; background: transparent; border-radius: 99px; padding: 8px 14px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.seg button small { color: var(--ink-3); margin-left: 4px; font-size: 12px; }
.seg button[aria-pressed="true"], .seg button[aria-checked="true"] { background: var(--bg); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-small button { padding: 6px 12px; font-size: 13px; }

.stepper { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 99px; padding: 2px; }
.stepper .icon-btn { width: 36px; height: 36px; }
.stepper output { min-width: 28px; text-align: center; font-family: var(--mono); font-size: 16px; }

.actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.actions .btn-primary { flex: 1; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 10px 0 0; }
.banner { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); font-size: 14px; }

/* ---------- Erät (edistyminen) ---------- */
.batches { display: grid; gap: 12px; margin-bottom: 28px; }
.batches:empty { display: none; }
.batch {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; background: var(--bg);
  animation: rise .25s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.batch-idea { font-family: var(--serif); font-size: 22px; line-height: 1.15; margin: 0; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.batch-status { font-family: var(--mono); font-size: 13px; color: var(--ink-2); grid-column: 1; }
.batch-status strong { color: var(--ink); font-weight: 500; }
.batch-tools { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; align-items: start; }
.cells { grid-column: 1 / -1; display: flex; gap: 4px; margin-top: 8px; }
.cell { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); position: relative; overflow: hidden; }
.cell.done { background: var(--accent); }
.cell.running { background: var(--accent-soft); }
.cell.running::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--accent); border-radius: 3px; animation: slide 1.3s ease-in-out infinite; }
.cell.failed { background: var(--ink); }
.cell.cancelled { background: repeating-linear-gradient(90deg, var(--surface-2) 0 4px, transparent 4px 7px); }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(250%); } }
.batch-errors { grid-column: 1 / -1; margin: 8px 0 0; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface); font-size: 14px; display: grid; gap: 8px; }
.batch-errors p { margin: 0; }
.batch-errors .btn { justify-self: start; }

/* ---------- Galleria ---------- */
.gallery-head { display: flex; align-items: end; gap: 12px 16px; flex-wrap: wrap; margin: 4px 0 18px; }
.gallery-title { font-size: clamp(40px, 4.4vw, 56px); margin: 0 auto 0 0; }
.tabs { display: inline-flex; gap: 2px; background: var(--surface); padding: 3px; border-radius: 99px; }
.tab { border: 0; background: transparent; padding: 7px 14px; border-radius: 99px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.tab[aria-selected="true"] { background: var(--bg); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tab span { color: var(--ink-3); font-family: var(--mono); font-size: 12px; }
.search { position: relative; display: block; width: 200px; }
.search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search input { padding-left: 36px !important; border-radius: 99px !important; }
#style-filter { width: auto; border-radius: 99px; }

.gallery { columns: 4 220px; column-gap: 14px; }
.tile {
  break-inside: avoid; margin: 0 0 14px; position: relative; border-radius: 10px; overflow: hidden;
  background: var(--surface); cursor: zoom-in; display: block; width: 100%; padding: 0; border: 0;
}
.tile img { display: block; width: 100%; height: auto; transition: transform .4s ease; }
.tile:hover img { transform: scale(1.025); }
.tile-cap {
  position: absolute; inset: auto 0 0 0; padding: 26px 12px 10px; text-align: left;
  background: linear-gradient(transparent, rgba(0,0,0,.6)); color: #fff; font-size: 13px; line-height: 1.3;
  opacity: 0; transition: opacity .2s;
}
.tile:hover .tile-cap, .tile:focus-visible .tile-cap { opacity: 1; }
.tile-star {
  position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0,0,0,.35); color: #fff; border: 0; cursor: pointer;
  opacity: 0; transition: opacity .2s;
}
.tile:hover .tile-star, .tile-star.on { opacity: 1; }
.tile-star.on .ico, #lb-fav[aria-pressed="true"] .ico { fill: var(--accent); stroke: var(--accent); }
.tile.new { animation: rise .4s ease-out; }
.empty { color: var(--ink-3); font-family: var(--serif); font-size: 26px; font-style: italic; padding: 40px 0; }
.more { display: flex; margin: 10px auto; }

/* Ensimmäinen kuva saa olla iso – rikotaan tylsää ruudukkoa. */
@media (min-width: 1100px) {
  .gallery.feature .tile:first-child { column-span: all; max-width: 46%; }
}

/* ---------- Lightbox ---------- */
.lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--bg); color: var(--ink);
  display: none; grid-template-columns: 1fr 380px;
}
.lightbox[open] { display: grid; }
.lightbox::backdrop { background: rgba(0,0,0,.5); }
.lb-stage { position: relative; display: grid; place-items: center; padding: 28px; background: var(--surface); min-height: 0; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 56px); object-fit: contain; box-shadow: var(--shadow); background: var(--bg); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: var(--bg); box-shadow: var(--shadow); }
.lb-prev { left: 16px; } .lb-next { right: 16px; }
.lb-side { position: relative; overflow: auto; padding: 28px 26px 40px; border-left: 1px solid var(--line); }
.lb-close { position: absolute; right: 14px; top: 14px; }
.lb-meta { font-family: var(--mono); font-size: 12px; color: var(--ink-3); margin: 6px 40px 10px 0; }
.lb-title { font-size: 34px; margin: 0 0 8px; }
.lb-idea { color: var(--ink-2); margin: 0 0 22px; }
.lb-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lb-actions .btn-primary { flex: 1 1 100%; }
.print-opts { margin-top: 18px; padding: 16px; border-radius: var(--radius); background: var(--surface); display: grid; gap: 12px; justify-items: start; }
.print-opts h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); }
.print-opts .seg { background: var(--surface-2); }
.radio-list { display: grid; gap: 6px; font-size: 14px; }
.radio-list input { accent-color: var(--accent); margin-right: 6px; }
.dpi { margin: 0; font-size: 14px; }
.dpi b { font-family: var(--mono); font-weight: 500; }
.lb-prompt { margin-top: 22px; font-size: 14px; }
.lb-prompt summary { cursor: pointer; color: var(--ink-2); }
.lb-prompt pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; background: var(--surface); padding: 12px; border-radius: var(--radius-sm); }
.lb-prompt dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.lb-prompt dt { color: var(--ink-3); }
.lb-prompt dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14px; z-index: 100;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

#print-root { display: none; }

/* ---------- Mobiili ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .studio { position: static; max-height: none; overflow: visible; }
  .login { grid-template-columns: 1fr; }
  .login-art { height: 220px; order: -1; }
  .lightbox { grid-template-columns: 1fr; grid-template-rows: auto auto; overflow: auto; }
  .lb-stage { padding: 12px; }
  .lb-stage img { max-height: 70vh; }
  .lb-side { border-left: 0; overflow: visible; }
  .lb-nav { width: 36px; height: 36px; }
  .lb-prev { left: 6px; } .lb-next { right: 6px; }
  .tile-star { opacity: 1; }
  .search { width: 100%; order: 5; }
  .machine { display: none !important; }
}
@media (max-width: 420px) {
  .papers { grid-template-columns: repeat(2, 1fr); }
  .gallery { columns: 2; column-gap: 8px; }
  .tile { margin-bottom: 8px; }
  .field-row { grid-template-columns: 1fr; }
}

/* ---------- Tulostus ---------- */
@media print {
  body > *:not(#print-root) { display: none !important; }
  html, body { background: #fff !important; margin: 0; padding: 0; }
  #print-root { display: block !important; }
  #print-root .page { width: 100vw; height: 100vh; display: flex; align-items: center; justify-content: center; overflow: hidden; page-break-after: avoid; break-after: avoid; }
  #print-root img { width: 100%; height: 100%; display: block; }
  #print-root.contain img { object-fit: contain; }
  #print-root.cover img { object-fit: cover; }
}
