/* Headliner Styles - Enhanced Icon System */
* { box-sizing: border-box; }

:root{
  --bg: #ffffff;
  --fg: #111111;
  --muted: #666;
  --ring: #3b82f6;
  --panel: color-mix(in oklab, var(--bg) 95%, black);
  --btn: #f3f4f6;
  --btn-fg: #111;
  --btn-primary: #2563eb;
  --btn-primary-fg: #fff;
  --accent: #7c3aed; /* Headliner brand */
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --bar-h: 64px;
  --radius: 16px;
}

@media (prefers-color-scheme: dark){
  :root{
    --bg: #0b0b0c;
    --fg: #eaeaea;
    --muted: #a3a3a3;
    --panel: color-mix(in oklab, var(--bg) 85%, white);
    --btn: #1b1c1f;
    --btn-fg: #eaeaea;
    --btn-primary: #3b82f6;
    --btn-primary-fg: #fff;
  }
}

/* Base styles */
html, body { height: 100%; }
html {
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body{
  margin:0; 
  background:var(--bg); 
  color:var(--fg);
  font: 15px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

body.lock { 
  position: fixed; 
  width: 100%; 
  overflow: hidden; 
}

/* Utility classes */
.hidden{ display:none !important; }
.vh{ 
  position:absolute !important; 
  width:1px; 
  height:1px; 
  overflow:hidden; 
  clip:rect(0 0 0 0); 
  clip-path:inset(50%); 
  white-space:nowrap; 
}

button, input, label { touch-action: manipulation; }

/* ENHANCED Icon System */
.icon { 
  width: 22px; 
  height: 22px; 
  display: inline-block; 
  vertical-align: middle; 
  color: currentColor;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

/* Ensure all SVG elements inherit currentColor properly */
.icon svg,
.icon use,
.icon path,
.icon circle,
.icon rect,
.icon polygon,
.icon line,
.icon polyline,
.icon ellipse { 
  fill: currentColor !important; 
  stroke: none !important; 
}

/* Handle stroke-only icons */
.icon-stroke svg,
.icon-stroke use,
.icon-stroke path,
.icon-stroke circle,
.icon-stroke rect,
.icon-stroke polygon,
.icon-stroke line,
.icon-stroke polyline,
.icon-stroke ellipse { 
  fill: none !important; 
  stroke: currentColor !important; 
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Special handling for mixed fill/stroke icons */
.icon [fill="none"] {
  fill: none !important;
}

.icon [stroke="none"] {
  stroke: none !important;
}

/* Icon size variants */
.icon-xs { width: 14px; height: 14px; }
.icon-sm { width: 16px; height: 16px; }
.icon-md { width: 20px; height: 20px; }
.icon-lg { width: 28px; height: 28px; }
.icon-xl { width: 32px; height: 32px; }
.icon-2xl { width: 48px; height: 48px; }

/* Icon states */
.icon-spin {
  animation: icon-spin 1s linear infinite;
}

@keyframes icon-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.icon-pulse {
  animation: icon-pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes icon-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Upload screen layout */
#screen-upload{ 
  min-height:100dvh; 
  display:flex; 
  flex-direction:column;
}

.hero{
  padding:16px 20px; 
  border-bottom:1px solid color-mix(in oklab, currentColor 12%, transparent);
  flex-shrink: 0;
}

.upload-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.grid{
  padding:20px; 
  display:grid; 
  gap:16px;
  grid-template-columns: repeat(auto-fit,minmax(260px,1fr));
  flex: 1;
  align-content:start;
}

.card{
  background:var(--panel); 
  border-radius:var(--radius); 
  padding:16px; 
  display:grid; 
  gap:12px;
  border:1px solid color-mix(in oklab, currentColor 10%, transparent);
}

/* Enhanced drop zones with integrated image preview */
.drop{
  border:2px dashed color-mix(in oklab, currentColor 25%, transparent);
  border-radius:12px; 
  text-align:center; 
  cursor:pointer; 
  transition: all 0.2s ease;
  min-height:140px; 
  position: relative;
  overflow: hidden;
  background: color-mix(in oklab, var(--panel) 70%, transparent);
}

.drop.drag{ 
  border-color: var(--ring); 
  background: color-mix(in oklab, var(--ring) 15%, transparent);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--ring) 20%, transparent);
}

.drop.has-image {
  border: 2px solid color-mix(in oklab, var(--ring) 40%, transparent);
  background: transparent;
  box-shadow: 0 2px 8px color-mix(in oklab, var(--ring) 15%, transparent);
}

/* Drop zone states */
.drop-content {
  padding: 16px;
  display: grid; 
  place-items: center; 
  gap: 10px;
  min-height: 140px;
}

.drop-preview {
  position: absolute;
  inset: 0;
  display: flex;
}

.drop-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(0,0,0,0.6), rgba(0,0,0,0.8));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
}

.drop:hover .drop-overlay {
  opacity: 1;
}

.drop-label {
  color: white;
  font-weight: 600;
  font-size: 14px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  letter-spacing: 0.5px;
}

.btn-change {
  display: inline-grid;
  grid-auto-flow: column;
  place-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.95);
  color: #333;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.btn-change:hover {
  background: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.btn-change .icon {
  width: 16px;
  height: 16px;
}

/* Hide thumbnail containers (using integrated preview now) */
.thumbs {
  display: none;
}

.actions{ 
  padding:16px 20px;
  display:flex; 
  gap:12px; 
  justify-content:flex-end; 
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid color-mix(in oklab, currentColor 8%, transparent);
}

/* ENHANCED Button System */
.btn{
  display:inline-grid; 
  grid-auto-flow:column; 
  place-items:center; 
  gap:8px;
  background:var(--btn); 
  color:var(--btn-fg);
  border:1px solid color-mix(in oklab, currentColor 14%, transparent);
  border-radius:14px; 
  padding:10px 14px; 
  cursor:pointer; 
  user-select:none;
  transition: all 0.15s ease;
  box-shadow: 0 1px 0 rgba(0,0,0,.04);
  font: inherit;
  text-decoration: none;
  min-height: 44px; /* Touch target */
}

.btn:hover{ 
  background: color-mix(in oklab, var(--btn) 85%, var(--ring)); 
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,.08);
}

.btn:active{ 
  transform: translateY(0px) scale(.98); 
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.btn:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: 0 1px 0 rgba(0,0,0,.04) !important;
}

.btn:disabled:hover {
  background: var(--btn);
}

/* Button variants */
.btn.primary{ 
  background: var(--btn-primary); 
  color: var(--btn-primary-fg); 
  border-color: transparent; 
}

.btn.primary:hover {
  background: color-mix(in oklab, var(--btn-primary) 90%, black);
}

.btn.subtle{ 
  background: color-mix(in oklab, var(--btn) 90%, transparent); 
}

.btn.danger {
  background: var(--danger);
  color: white;
  border-color: transparent;
}

.btn.danger:hover {
  background: color-mix(in oklab, var(--danger) 90%, black);
}

.btn.success {
  background: var(--success);
  color: white;
  border-color: transparent;
}

.btn.success:hover {
  background: color-mix(in oklab, var(--success) 90%, black);
}

.btn.active {
  background: var(--ring) !important;
  color: white !important;
  border-color: var(--ring) !important;
}

/* Button icon spacing */
.btn .icon { 
  margin-right: 6px; 
}

.btn.icon-only .icon,
.btn.only-icon .icon { 
  margin-right: 0; 
}

.btn.icon-left .icon {
  margin-right: 8px;
  margin-left: 0;
}

.btn.icon-right .icon {
  margin-left: 8px;
  margin-right: 0;
}

/* Special button types */
.btn-plain{ 
  background:none; 
  border:none; 
  color:inherit; 
  cursor:pointer; 
  padding: 8px;
  min-height: auto;
}

.btn-close-x{
  padding:.25rem; 
  border-radius:10px;
  background: color-mix(in oklab, var(--panel) 70%, transparent);
  min-height: auto;
}

.btn-close-x .icon{ 
  width:26px; 
  height:26px; 
  margin: 0;
}

.btn-close-x:hover{ 
  background: color-mix(in oklab, var(--danger) 15%, transparent);
  outline: 2px solid color-mix(in oklab, var(--danger) 30%, transparent);
}

/* Editor layout */
#screen-editor{ 
  height:100dvh; 
  display:grid; 
  grid-template-rows: 1fr var(--bar-h); 
}

#stageWrap{
  position:relative; 
  width:100%;
  height:calc(100dvh - var(--bar-h));
  background:#0a0a0a;
  transition: background .2s ease;
  touch-action: none;
}

canvas#stage{
  width:100%; 
  height:100%; 
  display:block;
  touch-action: none;
  -webkit-user-select: none; 
  user-select: none;
}

/* Refining mode styling */
body.refining #stageWrap{
  background:
    conic-gradient(from 45deg, #1a1a1a 0 25%, #0e0e0e 0 50%) top left / 24px 24px repeat;
}

/* Toolbar */
.toolbar{
  position:sticky; 
  bottom:0; 
  background:var(--panel);
  border-top:1px solid color-mix(in oklab, currentColor 12%, transparent);
  display:flex; 
  gap:10px; 
  align-items:center; 
  justify-content:center;
  padding: 10px calc(env(safe-area-inset-right,0) + 10px) calc(env(safe-area-inset-bottom,0) + 10px) calc(env(safe-area-inset-left,0) + 10px);
}

.toolbar .btn.primary{ 
  background: var(--accent); 
  color: #fff; 
}

.toolbar .btn.primary:hover {
  background: color-mix(in oklab, var(--accent) 90%, black);
}

/* Progress bar */
#progress{ 
  position:fixed; 
  left:0; 
  top:0; 
  width:100%; 
  height:3px; 
  background:transparent; 
  z-index:50; 
  display:none; 
}

#progressBar{ 
  width:0%; 
  height:100%; 
  background: var(--ring); 
  transition: width .3s ease; 
}

/* Toast notifications */
#snacks{ 
  position:fixed; 
  left:50%; 
  transform:translateX(-50%); 
  bottom: calc(var(--bar-h) + 16px); 
  display:grid; 
  gap:8px; 
  z-index:60; 
  pointer-events:none; 
  max-width: 90vw;
}

.snack{
  background: color-mix(in oklab, var(--panel) 85%, black);
  border:1px solid color-mix(in oklab, currentColor 12%, transparent);
  color: inherit; 
  padding:8px 12px; 
  border-radius:10px; 
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  pointer-events:auto;
  animation: snack-enter 0.3s ease-out;
  max-width: 400px;
  text-align: center;
}

@keyframes snack-enter {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Drawer/Sidebar */
.drawer {
  position: fixed; 
  right: 0; 
  top: 0; 
  height: 100%; 
  width: min(360px, 92vw);
  background: var(--panel); 
  color: inherit; 
  box-shadow: -12px 0 32px rgba(0,0,0,.2);
  transform: translateX(100%); 
  transition: transform .25s ease; 
  z-index: 70;
  display: grid; 
  grid-template-rows: auto 1fr auto;
  border-left: 1px solid color-mix(in oklab, currentColor 12%, transparent);
  overscroll-behavior: contain;
}

.drawer.open { 
  transform: translateX(0);
  box-shadow: 
    -12px 0 32px rgba(0,0,0,.2),
    0 0 0 1px color-mix(in oklab, var(--ring) 20%, transparent);
}

.drawer__hdr, .drawer__ftr { 
  padding: .75rem 1rem; 
  border-block: 1px solid color-mix(in oklab, currentColor 12%, transparent);
}

.drawer__hdr { 
  display:flex; 
  align-items:center; 
  justify-content:space-between;
  background: color-mix(in oklab, var(--panel) 95%, black);
}

.drawer__body { 
  padding: 1rem; 
  overflow:auto; 
  -webkit-overflow-scrolling: touch; 
}

/* Form controls in drawer */
.row { 
  display:grid; 
  grid-template-columns: 1fr auto auto; 
  gap:.75rem; 
  align-items:center; 
  margin:1rem 0;
}

.row input[type="range"] { 
  grid-column: span 2; 
  width: 200px; 
}

.row span {
  font-weight: 500;
}

.row output {
  font-family: ui-monospace, 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 14px;
  background: color-mix(in oklab, var(--panel) 90%, black);
  padding: 2px 6px;
  border-radius: 4px;
  min-width: 48px;
  text-align: center;
}

/* Mobile drawer as bottom sheet */
@media (pointer:coarse) {
  .drawer {
    right:auto; 
    left:0; 
    top:auto; 
    bottom:0; 
    width:100%;
    height:min(60dvh, 420px);
    border-left:none; 
    border-top:1px solid color-mix(in oklab, currentColor 12%, transparent);
    box-shadow: 0 -12px 32px rgba(0,0,0,.28);
    transform: translateY(100%);
  }
  
  .drawer.open{ 
    transform: translateY(0);
    box-shadow: 
      0 -12px 32px rgba(0,0,0,.28),
      0 0 0 1px color-mix(in oklab, var(--ring) 20%, transparent);
  }
}

/* Modal dialogs */
.modal{ 
  position:fixed; 
  inset:0; 
  display:grid; 
  place-items:center; 
  background:rgba(0,0,0,.45); 
  z-index:80; 
  backdrop-filter: blur(4px);
}

.modal.hidden{ 
  display:none; 
}

.modal__panel{
  width:min(560px, 92vw);
  background:var(--panel); 
  color:inherit;
  border:1px solid color-mix(in oklab, currentColor 12%, transparent);
  border-radius:16px; 
  box-shadow:0 18px 56px rgba(0,0,0,.35);
  display:grid; 
  grid-template-rows:auto 1fr auto;
  overscroll-behavior: contain;
  animation: modal-enter 0.2s ease-out;
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal__hdr, .modal__ftr{ 
  padding:.75rem 1rem; 
  border-block:1px solid color-mix(in oklab, currentColor 12%, transparent); 
}

.modal__hdr{ 
  display:flex; 
  align-items:center; 
  justify-content:space-between; 
}

.modal__body{ 
  padding:.75rem 1rem; 
  max-height:min(60dvh, 420px); 
  overflow:auto; 
  -webkit-overflow-scrolling: touch; 
}

/* Mobile optimizations */
@media (max-height: 700px) {
  .drop { 
    min-height: 120px; 
  }
  
  .drop-content {
    min-height: 120px;
    padding: 12px;
    gap: 8px;
  }
  
  .actions { 
    padding: 12px 20px; 
  }
  
  .grid { 
    padding: 16px; 
  }
}

@media (max-width: 768px) {
  .drop-overlay {
    opacity: 0.9;
  }
  
  .drop.has-image .drop-overlay {
    opacity: 0.0;
  }
  
  .drop.has-image:active .drop-overlay {
    opacity: 0.9;
  }
  
  .btn-change {
    padding: 10px 14px;
    font-size: 14px;
  }
  
  .drop-label {
    font-size: 15px;
  }
  
  /* Larger touch targets on mobile */
  .btn {
    min-height: 48px;
    padding: 12px 16px;
  }
  
  .toolbar {
    gap: 8px;
    padding: 12px calc(env(safe-area-inset-right,0) + 12px) calc(env(safe-area-inset-bottom,0) + 12px) calc(env(safe-area-inset-left,0) + 12px);
  }
}

/* Enhanced visual feedback */
@media (prefers-reduced-motion: no-preference) {
  .drop-image {
    transition: transform 0.2s ease;
  }
  
  .drop:hover .drop-image {
    transform: scale(1.02);
  }
  
  .drop.has-image {
    animation: imageLoaded 0.3s ease-out;
  }
  
  @keyframes imageLoaded {
    from {
      transform: scale(0.95);
      opacity: 0;
    }
    to {
      transform: scale(1);
      opacity: 1;
    }
  }
  
  .btn:hover .icon {
    transform: scale(1.05);
  }
  
  .btn:active .icon {
    transform: scale(0.95);
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn {
    border-width: 2px;
  }
  
  .drop {
    border-width: 3px;
  }
  
  .icon {
    filter: contrast(1.2);
  }
}

/* Print styles */
@media print {
  .toolbar,
  .drawer,
  .modal,
  #snacks,
  #progress {
    display: none !important;
  }
  
  #screen-editor {
    height: auto;
  }
  
  #stageWrap {
    height: 80vh;
    background: white !important;
  }
}
/* --- Mobile toolbar fix (portrait) --- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem;
  box-sizing: border-box;
}
.toolbar > * { min-width: 0; }
.toolbar .controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 240px;
  flex-wrap: wrap;
  min-width: 0;
}
.toolbar .actions {
  display: flex;
  gap: 0.5rem;
  flex: 0 0 auto;
}
.toolbar .btn, .toolbar button, .toolbar a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  max-width: 100%;
  white-space: nowrap;
  box-sizing: border-box;
}
.toolbar svg, .toolbar .icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
}
@media (max-width: 480px) {
  .toolbar { row-gap: 0.5rem; }
  .toolbar .controls { flex-basis: 100%; }
  .toolbar .actions { width: 100%; justify-content: stretch; }
  .toolbar .actions .btn, .toolbar .actions button, .toolbar .actions a.btn {
    flex: 1 1 auto;
  }
}

/* --- Toolbar spacing + larger icons in buttons --- */
.toolbar {
  gap: 0.375rem;                  /* tighter overall spacing */
  padding: 0.375rem 0.5rem;       /* slightly tighter padding */
}
.toolbar .controls { gap: 0.375rem; }
.toolbar .actions { gap: 0.375rem; }

/* Buttons: compact padding but let icons feel bigger */
.toolbar .btn, .toolbar button, .toolbar a.btn {
  padding: 0.45rem 0.6rem;        /* compact without feeling cramped */
  gap: 0.375rem;                  /* icon-text spacing */
}

/* Make SVGs occupy more visual space inside buttons */
.toolbar .btn svg, .toolbar .btn .icon,
.toolbar button svg, .toolbar button .icon,
.toolbar a.btn svg, .toolbar a.btn .icon {
  width: 1.5rem;
  height: 1.5rem;
}

/* On very small screens, give icons even more presence */
@media (max-width: 480px) {
  .toolbar { gap: 0.35rem; padding: 0.35rem 0.5rem; }
  .toolbar .btn, .toolbar button, .toolbar a.btn { padding: 0.42rem 0.55rem; }
  .toolbar .btn svg, .toolbar .btn .icon,
  .toolbar button svg, .toolbar button .icon,
  .toolbar a.btn svg, .toolbar a.btn .icon {
    width: 1.625rem;
    height: 1.625rem;
  }
}

/* --- Top bar (Home left, Donate right) --- */
.topbar{
  position: fixed;
  top: max(6px, env(safe-area-inset-top, 0));
  left: 0; right: 0;
  z-index: 100;
  pointer-events: none; /* let canvas interactions pass through except on buttons */
}

.topbar-btn{
  position: absolute;
  pointer-events: auto;
  backdrop-filter: blur(6px);
  background: color-mix(in oklab, var(--panel) 85%, transparent);
  border: 1px solid color-mix(in oklab, currentColor 12%, transparent);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}

.topbar-btn .icon{ width: 20px; height: 20px; }

.topbar-btn.left  { left: 12px; }
.topbar-btn.right { right: 12px; }

@media (max-width: 480px){
  .topbar-btn{ padding: 8px 10px; }
  .topbar-btn span{ display:none; } /* icon-only on small screens */
}

