/* OneAppleFall · AI Image Upscaler v4 (rendered inside a shadow root) */
.up { --ink: #16161d; --muted: #5f5f6b; --line: #e6e6ee; --soft: #f6f6fb; --a: var(--oaf-primary, #4f46e5); --b: var(--oaf-secondary, #7c3aed);
  --ok: #059669; --bad: #dc2626; color: var(--ink); font: 15px/1.5 inherit; border-radius: 24px; overflow: hidden; background: #fff;
  border: 1px solid var(--line); box-shadow: 0 30px 70px -40px rgba(13, 18, 38, .55); margin: 6px 0 36px; }
.up * { box-sizing: border-box; }
.up button { font: inherit; cursor: pointer; }
.up button:disabled { opacity: .5; cursor: not-allowed; }
.up [hidden] { display: none !important; }

/* Header strip */
.up__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px; padding: 16px 22px; color: #fff;
  background: radial-gradient(600px 160px at 0% 0%, rgba(124, 58, 237, .65), transparent 70%), radial-gradient(500px 160px at 100% 100%, rgba(6, 182, 212, .45), transparent 70%), #0d1226; }
.up__title { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.up__logo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--a), var(--b)); font-size: 15px; }
.up__badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.up__badges li { font-size: 12.5px; font-weight: 700; padding: 5px 11px; border-radius: 999px; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .18); }
.up__badges li::before { content: '✓ '; color: #6ee7b7; }

/* Layout */
.up__body { display: grid; grid-template-columns: 340px 1fr; min-height: 560px; }
.up__panel { padding: 18px; border-right: 1px solid var(--line); background: var(--soft); display: flex; flex-direction: column; gap: 16px; }
.up__main { display: flex; flex-direction: column; min-width: 0; }

/* Drop zone */
.up__drop { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  min-height: 150px; padding: 18px; border: 2px dashed #c9c9da; border-radius: 16px; background: #fff; cursor: pointer; transition: border-color .15s, background .15s; }
.up__drop:hover, .up__drop.is-over { border-color: var(--a); background: #f5f5ff; }
.up__drop.is-compact { min-height: 0; flex-direction: row; padding: 12px; }
.up__drop.is-compact .up__dropsub { display: none; }
.up__drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.up__dropicon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(135deg, var(--a), var(--b)); color: #fff; font-size: 20px; }
.up__drop.is-compact .up__dropicon { width: 30px; height: 30px; font-size: 16px; }
.up__drop strong { font-size: 15px; }
.up__dropsub { font-size: 12.5px; color: var(--muted); }

/* Queue */
.up__queuewrap { display: flex; flex-direction: column; gap: 6px; }
.up__qhead { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.up__qhead button { border: 0; background: none; color: var(--a); font-weight: 700; font-size: 12.5px; text-transform: none; letter-spacing: 0; }
.up__queue { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow: auto; }
.up__item { display: grid; grid-template-columns: 40px 1fr auto 22px; gap: 8px; align-items: center; padding: 6px; border-radius: 12px; background: #fff; border: 1px solid var(--line); cursor: pointer; }
.up__item.is-sel { border-color: var(--a); box-shadow: 0 0 0 2px rgba(79, 70, 229, .15); }
.up__item img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #eee; }
.up__iname { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.up__iname small { display: block; font-weight: 400; color: var(--muted); font-size: 11.5px; }
.up__pill { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: #3730a3; }
.up__pill--done { background: #d1fae5; color: #065f46; } .up__pill--working { background: #fef3c7; color: #92400e; } .up__pill--error { background: #fee2e2; color: #991b1b; }
.up__x { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0; }

/* Settings */
.up__set { display: flex; flex-direction: column; gap: 14px; }
.up__group { border: 0; padding: 0; margin: 0; }
.up__group legend { font-size: 12px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; padding: 0; }
.up__seg { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.up__seg label { flex: 1 1 auto; position: relative; }
.up__seg input { position: absolute; opacity: 0; pointer-events: none; }
.up__seg span { display: block; text-align: center; padding: 7px 10px; border-radius: 10px; font-size: 13.5px; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap; }
.up__seg span small { display: block; font-weight: 500; font-size: 11px; }
.up__seg input:checked + span { background: linear-gradient(135deg, var(--a), var(--b)); color: #fff; box-shadow: 0 6px 14px -8px rgba(79, 70, 229, .9); }
.up__seg input:focus-visible + span { outline: 2px solid var(--a); outline-offset: 1px; }
.up__seg input:disabled + span { cursor: not-allowed; }
.up__noise.is-off { opacity: .45; }
.up__hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.up__quality { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.up__quality input { flex: 1; accent-color: var(--a); }
.up__alpha { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.up__alpha input { accent-color: var(--a); width: 16px; height: 16px; }

/* Actions */
.up__actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.up__btn { border: 0; border-radius: 999px; padding: 13px 18px; font-weight: 800; font-size: 15.5px; color: #fff; background: linear-gradient(135deg, var(--a), var(--b));
  box-shadow: 0 12px 24px -12px rgba(79, 70, 229, .9); transition: transform .15s; }
.up__btn:not(:disabled):hover { transform: translateY(-1px); }
.up__btn--ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: none; font-weight: 700; }
.up__btn--dark { background: #111827; box-shadow: none; }
.up__bar { height: 6px; border-radius: 999px; background: #e4e4ee; overflow: hidden; }
.up__bar > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--a), #06b6d4); transition: width .2s; }
.up__status { font-size: 13px; color: var(--muted); min-height: 1.4em; }
.up__status.is-error { color: var(--bad); }
.up__engine { font-size: 11.5px; color: var(--muted); }
.up.is-busy .up__drop { pointer-events: none; opacity: .6; }

/* Empty state */
.up__empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; padding: 30px;
  background: repeating-conic-gradient(#f6f6fa 0 25%, #fff 0 50%) 0 0 / 24px 24px; }
.up__empty h3 { margin: 0; font-size: 22px; }
.up__empty p { margin: 0; color: var(--muted); max-width: 420px; }
.up__samples { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.up__samples button { display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 8px; border-radius: 14px; border: 1px solid var(--line); background: #fff; font-weight: 700; }
.up__samples img { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; }

/* Viewer */
.up__viewer { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.up__vtools { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.up__viewmode, .up__zoom { display: flex; gap: 4px; padding: 3px; border-radius: 12px; background: var(--soft); border: 1px solid var(--line); }
.up__viewmode button, .up__zoom button { border: 0; background: none; padding: 5px 11px; border-radius: 9px; font-size: 13px; font-weight: 700; color: var(--muted); }
.up__viewmode button.is-on, .up__zoom button.is-on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.up__stages { position: relative; flex: 1; display: grid; min-height: 420px; }
.up__stage { position: relative; overflow: hidden; min-height: 420px; touch-action: none; user-select: none;
  background: repeating-conic-gradient(#efeff4 0 25%, #fff 0 50%) 0 0 / 20px 20px; }
.up__stage.can-pan { cursor: grab; }
.up__canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.up__canvas img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: auto; -webkit-user-drag: none; }
.up__stage--split .up__after { clip-path: inset(0 0 0 var(--split, 50%)); }
.up__handle { position: absolute; top: 0; bottom: 0; left: var(--split, 50%); width: 0; z-index: 2; cursor: ew-resize; outline: none; }
.up__handle::before { content: ''; position: absolute; top: 0; bottom: 0; left: calc(-1.5px * var(--hs, 1)); width: calc(3px * var(--hs, 1)); background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.up__handle::after { content: '⟷'; position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%) scale(var(--hs, 1)); width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; background: #fff; color: var(--a); font-weight: 900; box-shadow: 0 6px 16px rgba(0, 0, 0, .25); }
.up__handle:focus-visible::after { outline: 3px solid var(--a); }
.up__tag { position: absolute; top: 10px; z-index: 3; font-size: 11px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: #fff;
  background: rgba(13, 18, 38, .7); padding: 4px 9px; border-radius: 7px; pointer-events: none; }
.up__tag--l { left: 10px; } .up__tag--r { right: 10px; }
/* view states */
.up[data-view="single"] .up__stage--a, .up[data-view="single"] .up__stage--b, .up[data-view="split"] .up__stage--a, .up[data-view="split"] .up__stage--b { display: none; }
.up[data-view="single"] .up__before, .up[data-view="single"] .up__handle, .up[data-view="single"] .up__tag { display: none; }
.up[data-view="single"] .up__after { clip-path: none; }
.up[data-view="side"] .up__stages { grid-template-columns: 1fr 1fr; gap: 2px; background: var(--line); }
.up[data-view="side"] .up__stage--split { display: none; }
.up__info { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.up__info b { color: var(--ink); }
.up__info > span { flex: 1 1 auto; }
.up__dl { display: flex; gap: 8px; padding: 0 16px 16px; flex-wrap: wrap; }
.up__dl .up__btn { flex: 1 1 200px; }

@media (max-width: 900px) {
  .up__body { grid-template-columns: 1fr; }
  .up__panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .up__stages, .up__stage { min-height: 320px; }
}
@media (prefers-reduced-motion: reduce) { .up__btn, .up__drop, .up__bar > span { transition: none; } }
