/* ─── Two-column app layout ───────────────────────────────────────────────── */

/* Extend app wrapper to fill remaining height */
.app {
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

.app-body {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-height: calc(100dvh - 130px - env(safe-area-inset-top, 0px));
  overflow: hidden;
  margin: 0 -18px; /* bleed to edge of .app padding */
}

/* ── Config panel (left sidebar) ─────────────────────────────────────────── */
.config-panel {
  width: 300px;
  min-width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 2px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease, min-width 0.25s ease;
  position: relative;
  container-type: inline-size;
  container-name: config-panel;
}

.config-panel.collapsed {
  width: 44px;
  min-width: 44px;
  overflow: clip;
}

.panel-inner {
  flex: 1;
  min-width: 296px;
  padding: 0 14px 24px;
  overflow: clip;
  transition: opacity 0.2s ease;
}

.config-panel.collapsed .panel-inner {
  opacity: 0;
  pointer-events: none;
}

/* Toggle button — sticks to the top-right of the panel */
.panel-toggle-btn {
  position: sticky;
  top: 0;
  z-index: 20;
  align-self: flex-end;
  width: 36px;
  height: 36px;
  margin: 10px 4px 0 auto;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--purple);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.09);
}
.panel-toggle-btn:hover { background: var(--purple); color: #fff; border-color: var(--purple); }

/* Inside panel: hero section tweaks */
.config-panel .hero-section {
  padding: 14px 0 6px;
  text-align: left;
}
.config-panel .hero-tagline {
  font-size: 1rem;
  margin: 0 0 8px;
}
.config-panel .examples-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  max-width: 100%;
}
.config-panel .shuffle-cards-btn {
  margin: 6px 0 0;
}

/* Generator section inside panel */
.config-panel .generator-section {
  padding: 0;
  margin: 0;
}

/* ── Canvas area (right content) ─────────────────────────────────────────── */
.canvas-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* Remove top margin from workspace when inside canvas-area */
.canvas-area .workspace {
  margin-top: 0;
  flex: 1;
}

/* ── Landscape hint (portrait mobile only) ───────────────────────────────── */
.landscape-hint {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--purple), #a855f7);
  color: #fff;
  font-family: var(--ff-body);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
}

/* ── Color mode toggle ───────────────────────────────────────────────────── */
.color-mode-group {
  display: flex;
  gap: 0;
  border-radius: 50px;
  overflow: hidden;
  border: 2px solid var(--border);
  flex-shrink: 0;
}
.mode-btn {
  font-family: var(--ff-body);
  font-size: .82rem;
  font-weight: 800;
  padding: 6px 14px;
  border: none;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.mode-btn:first-child { border-right: 1.5px solid var(--border); }
.mode-btn.active {
  background: var(--purple);
  color: #fff;
}
.mode-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Paint coverage indicator in status bar */
#status.paint-coverage {
  background: linear-gradient(135deg, #fff8e1, #fff3e0);
  border-color: rgba(255,152,0,.3);
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #status.paint-coverage {
    background: rgba(255,152,0,0.14);
    border-color: rgba(255,152,0,0.3);
  }
}
:root[data-theme="dark"] #status.paint-coverage {
  background: rgba(255,152,0,0.14);
  border-color: rgba(255,152,0,0.3);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

/* Medium screens: narrower panel */
@media (max-width: 900px) {
  .config-panel { width: 240px; min-width: 240px; }
  .panel-inner  { min-width: 236px; }
}

/* Portrait mobile: sidebar hidden by default, canvas fills width */
@media (max-width: 767px) {
  /* Bound the app to 100dvh so the flex chain can't expand the body beyond the viewport */
  .app { overflow-x: hidden; height: 100dvh; overflow-y: hidden; }
  .app-body { flex-direction: column; min-height: 0; } /* override base calc() min-height */
  .canvas-area { min-height: 0; }                      /* allow flex shrink for overflow-y:auto */

  .config-panel {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 2px solid var(--border);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }
  .config-panel.mobile-open {
    max-height: 70dvh;
    overflow-y: auto;
  }
  /* Override collapsed: on mobile collapsed = hidden = 0 height */
  .config-panel.collapsed { width: 100%; min-width: 0; max-height: 0; }

  .panel-inner  { min-width: 0; width: 100%; padding: 0 14px 16px; }
  .panel-toggle-btn { display: none; } /* replaced by header menu btn on mobile */

  /* Keep suggestion cards visible on mobile — panel scrolls (max-height 70dvh + overflow-y auto) */
  .config-panel .shuffle-cards-btn { display: none; } /* shuffle btn still hidden to save space */
}

/* Landscape hint: phones only — tablets at 768px+ don't need a rotation nudge */
@media (max-width: 540px) {
  .landscape-hint { display: flex; }
}

/* Phone landscape: detected by short viewport height (phones rotated sideways).
   Works on all phones regardless of their portrait width (S Ultra, iPhone, etc.) */
@media (orientation: landscape) and (max-height: 500px) {
  .app-body { flex-direction: row; }
  .config-panel {
    width: 200px;
    min-width: 200px;
    max-height: none;
    border-right: 2px solid var(--border);
    border-bottom: none;
    overflow-y: auto;
    overflow-x: hidden;
  }
  /* Force panel visible — override collapsed class so prompt input is always accessible */
  .config-panel.collapsed {
    width: 200px !important;
    min-width: 200px !important;
    max-height: none !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }
  .config-panel.collapsed .panel-inner {
    opacity: 1 !important;
    pointer-events: auto !important;
  }
  .panel-inner { min-width: 196px; width: 196px; }
  .panel-toggle-btn { display: flex; }
  .mobile-menu-btn { display: none; }
  .landscape-hint { display: none; }
  /* footer wastes ~170px in landscape — hide it */
  .site-footer { display: none !important; }
  /* app-body: remove portrait negative-margin bleed; allow flex to size it correctly */
  .app-body { margin: 0; min-height: 0; overflow: hidden; }
  /* canvas-area fills the flex-row height */
  .canvas-area { height: 100%; min-height: 0; }
  /* Hide example cards and tagline — mirrors tablet landscape fix; keeps prompt above fold */
  .config-panel .examples-grid,
  .config-panel .shuffle-cards-btn { display: none !important; }
  .config-panel .hero-tagline       { display: none; }
  .config-panel .hero-section       { padding: 3px 0 2px; }
  /* Hide regen-btn so Draw! button gets full width and isn't clipped at 200px panel */
  .config-panel .regen-btn          { display: none !important; }
}

/* Tablet landscape: taller than a phone but height-constrained (501px–900px, 768px+ wide).
   Config panel content (~640px) overflows a 530px-tall 7" tablet in landscape, hiding the
   prompt input below fold. Fix: hide example cards + shrink hero so form stays visible. */
@media (orientation: landscape) and (min-height: 501px) and (max-height: 840px) and (min-width: 768px) {
  .config-panel { width: 260px; min-width: 260px; }
  .panel-inner  { min-width: 256px; }
  .config-panel .examples-grid,
  .config-panel .shuffle-cards-btn { display: none !important; }
  .config-panel .hero-tagline { display: none; }
  .config-panel .hero-section { padding: 8px 0 4px; }
}

/* ── Container queries: config-panel inner content adapts to sidebar width ─── */
/* Match app-body bleed margin to app padding at each mobile breakpoint to prevent viewport overflow */
@media (max-width: 480px) { .app-body { margin: 0 -10px; } }
@media (max-width: 360px) { .app-body { margin: 0 -8px;  } }

/* Tighter pill/chip wrapping when panel is narrow (e.g. 240px or landscape 220px) */
@container config-panel (max-width: 250px) {
  .ctrl-label { min-width: 56px; font-size: .68rem; }
  .setting-chip { font-size: .82rem; padding: 7px 12px; }
  .diff-pill, .palette-pill, .size-pill, .count-pill { font-size: .8rem; padding: 6px 11px; }
  .check-pill { font-size: .82rem; padding: 7px 12px; }
}
