:root{
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e5e7eb;
  --accent: #0ea5e9;
  --accent-2: #22d3ee;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 6px 24px rgba(0,0,0,.08);
  --radius: 14px;
}

*{ box-sizing: border-box; }
html, body { margin:0; padding:0; background: var(--bg); color: var(--text); font-family: 'Roboto', system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Arial; line-height: 1.6; }
img { max-width:100%; height:auto; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* Container: 10px padding on mobile (guaranteed), 16px on desktop */
.container { width: min(1100px, 100%); margin: 0 auto; padding: 0 10px !important; }
@media (min-width: 900px) { .container { padding: 0 16px !important; } }

/* Fallback: if a page forgot .container, still get 10px padding on mobile */
@media (max-width: 899.98px) {
  main.page:not(.container) { padding-left: 10px; padding-right: 10px; }
}

/* Header */
.topbar { position: sticky; top:0; z-index: 50; background: rgba(255,255,255,.85); border-bottom: 1px solid var(--border); backdrop-filter: blur(10px); }
.topbar-inner { display:flex; align-items:center; justify-content:space-between; height: 56px; }
.brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.menu-btn {
  border: 1px solid var(--border); background: #fff; width: 40px; height: 40px; border-radius: 10px;
  display:grid; place-items:center; cursor:pointer; box-shadow: var(--shadow-sm);
}
.menu-btn .hamburger,
.menu-btn .hamburger::before,
.menu-btn .hamburger::after {
  content: ""; display:block; width: 18px; height: 2px; background: var(--text);
  border-radius: 2px; transition: transform .2s ease, opacity .2s ease;
}
.menu-btn .hamburger::before { transform: translateY(-6px); }
.menu-btn .hamburger::after  { transform: translateY(6px); }

/* Mobile dropdown menu */
.menu {
  position: absolute; right:10px; left:10px; top:58px; display:none;
  background:#fff; border:1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-md);
  padding: 8px; z-index: 60;
}
.menu.open { display:block; }
.menu a { display:block; padding: 10px 12px; border-radius: 8px; color: var(--text); }
.menu a:hover { background: #f8fafc; text-decoration: none; }

/* Desktop: show links inline; hide hamburger */
@media (min-width: 900px) {
  .menu-btn { display:none; }
  .menu { position: static; display:flex !important; background: transparent; border: none; box-shadow: none; padding: 0; gap: 14px; }
  .menu a { display:inline-block; padding: 0; margin-left: 14px; border-radius: 8px; line-height: 56px; }
  .menu a:hover { background: transparent; text-decoration: underline; }
}

.page { padding: 18px 0 calc(var(--sticky-h) + 16px); }
.page-title { font-size: 22px; font-weight: 700; margin: 8px 0 16px; }

/* Gallery */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

/* Card */
.card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  cursor: zoom-in;
  transition: transform .16s ease, box-shadow .16s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* Animated black placeholders (skeleton) */
@keyframes dig-shine {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.img-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #0b0b0b;
}
.img-wrap::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, #0a0a0a 0%, #141414 50%, #0a0a0a 100%);
  background-size: 200% 100%;
  animation: dig-shine 1.2s linear infinite;
}
.img-wrap.loaded::before { opacity: 0; animation: none; transition: opacity .25s ease; }

.img-wrap img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .25s ease;
}
.img-wrap.loaded img { opacity: 1; }

.img-wrap.detail { aspect-ratio: auto; background: #0b0b0b; }

/* Meta */
.meta { padding: 10px 12px; }
.meta .prompt {
  font-size: 14px; font-weight: 500;
  display:-webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}
.meta .details { margin-top: 4px; color: var(--muted); font-size: 12px; }

/* Pagination */
.pagination { display:flex; align-items:center; gap:10px; justify-content:center; margin: 16px 0 50px; }
.btn {
  display:inline-flex; align-items:center; justify-content:center;
  padding: 9px 14px; border-radius: 10px; background: #fff; color: var(--text);
  border: 1px solid var(--border); text-decoration:none; font-size: 14px;
}
.btn.primary { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #05202a; border: none; font-weight: 700; }
.btn.disabled { opacity: .5; pointer-events: none; }

/* Lock page scroll when modal is open */
body.modal-open { overflow: hidden; }

/* Modal overlay — add small safe-area padding so it never touches screen edges */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0,0,0,.65);
  z-index: 60;

  /* gap from edges (does NOT add white space around the image) */
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.modal.open { display: grid; }

/* Modal content — centered, rounded, scrollable. No internal padding = no white bands */
.modal-content {
  position: relative;
  width: min(1000px, 100%);  /* respect overlay padding; never hits screen edge */
  max-height: 90vh;
  background: #fff;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  overflow: auto;                /* own scroll */
  -webkit-overflow-scrolling: touch;
  padding: 0;                    /* no white space around the image */
  margin: 0 auto;                /* extra safety for centering */
}

/* Desktop: slightly shorter modal height (more breathing room above/below) */
@media (min-width: 900px) {
  .modal-content { max-height: 90vh; }
}

/* Themed, rounded scrollbar (inside modal only) */
.modal-content::-webkit-scrollbar { width: 10px; height: 10px; }
.modal-content::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: var(--radius);
}
.modal-content::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: var(--radius);
  border: 2px solid #f1f5f9;
}
.modal-content { scrollbar-width: thin; scrollbar-color: var(--accent) #f1f5f9; }

/* Floating close button */
.modal .close {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-size: 18px;
  background: #fff;
  color: #111;
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  cursor: pointer;
  z-index: 2;
}

/* Image — edge-to-edge inside the rounded modal (no gaps) */
.modal-content img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;                 /* full portrait visible */
  background: #0b0b0b;                 /* letterbox only where needed */
  border-radius: var(--radius) var(--radius) 0 0; /* match container corners */
}

/* Prompt/seed below image; scroll inside modal to view */
.modal-info {
  padding: 14px 16px 18px;
  font-size: 14px;
  color: var(--muted);
}
.modal-prompt { color: var(--text); margin-bottom: 6px; font-weight: 500; }


/* Sticky generator */
.sticky-gen { padding-bottom: 5px; padding-top:5px; position: fixed; left:0; right:0; bottom:0; z-index: 55; background: rgba(255,255,255,.96); border-top: 1px solid var(--border); backdrop-filter: blur(8px); }
.gen-inner { display:flex; gap: 8px; align-items:center; padding: 10px 12px; }
.sticky-gen input[type="text"], .sticky-gen input[type="number"] {
  background: #fff; color: var(--text); border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 10px; outline: none; width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.sticky-gen input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,165,233,.15); }
#prompt { flex: 1.8; }
#width, #height { max-width: 110px; }
#seed { max-width: 160px; }
.gen-status { margin-left: 8px; color: var(--muted); min-width: 140px; }

/* Mobile wrap for generator */
@media (max-width: 720px) {
  .gen-inner { flex-wrap: wrap;
  margin-top: 10px;
  }
  #prompt { flex: 1 0 100%; }
  #width, #height, #seed { flex: 1; max-width: none; }
}



@media (max-width: 768px) {
  .pagination {
    margin: 16px 0 120px;
  }
}

/* Chat layout */
.chat-toolbar { display:flex; align-items:center; gap:10px; margin: 6px 0 12px; }
.chat-toolbar .spacer { flex:1; }

.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Message bubbles */
.msg {
  display: grid;
  gap: 6px;
  max-width: 820px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  background: #fff;
}
.msg .who { font-size: 12px; color: var(--muted); }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }

.msg.user {
  margin-left: auto;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #05202a;
  border: none;
}
.msg.user .who { color: rgba(5,32,42,.85); }

.msg.ai { margin-right: auto; }

/* History drawer */
.history-panel {
  position: fixed; inset: 56px 10px auto 10px;
  z-index: 40;
}
.history-inner {
  background:#fff; border:1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-md);
  padding: 10px;
  max-height: 50vh; overflow:auto;
}
.history-header { display:flex; align-items:center; justify-content:space-between; margin-bottom: 8px; }
#historyList { list-style: none; margin:0; padding:0; }
#historyList li { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:8px; border-radius: 8px; }
#historyList li:hover { background:#f8fafc; cursor:pointer; }
#historyList .title { flex:1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#historyList .time { color: var(--muted); font-size: 12px; }

/* Chat input (sticky bottom) */
#chatForm textarea {
  resize: none;
  min-height: 44px;
  max-height: 160px;
  width: 100%;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
#chatForm textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14,165,233,.15); }

/* Markdown basics inside AI messages */
.msg.ai h1,.msg.ai h2,.msg.ai h3{ margin: .4em 0 .2em; }
.msg.ai p { margin: .3em 0; }
.msg.ai code { background:#f1f5f9; padding: 2px 6px; border-radius: 6px; }
.msg.ai pre { background:#0b1220; color:#e6edf3; padding: 10px; border-radius: 10px; overflow:auto; }




/* Ensure the variable exists (keeps working even without JS measuring) */
:root { --sticky-h: 120px; }

/* Keep chat content clear of the sticky input bar */
#chat {
  padding-bottom: calc(var(--sticky-h) + 16px) !important;
}

/* A little extra space on mobile */
@media (max-width: 900px) {
  #chat {
    padding-bottom: calc(var(--sticky-h) + 24px) !important;
  }
}