/* Apple Liquid Glass — frosted, refracting, responsive (iOS / iPadOS / macOS) */

:root {
  --bg-1: #0b0b14;
  --bg-2: #11122a;
  --text: #f4f4f7;
  --text-dim: rgba(244, 244, 247, 0.62);
  --text-mute: rgba(244, 244, 247, 0.42);
  --accent: #0a84ff;        /* Apple system blue (dark) */
  --accent-2: #5e5ce6;      /* Apple system indigo */
  --success: #30d158;
  --warn: #ff9f0a;
  --danger: #ff453a;

  --glass-bg: rgba(255, 255, 255, 0.08);
  --glass-bg-strong: rgba(255, 255, 255, 0.14);
  --glass-stroke: rgba(255, 255, 255, 0.18);
  --glass-stroke-soft: rgba(255, 255, 255, 0.10);
  --glass-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.55),
                  0 8px 22px -8px rgba(0, 0, 0, 0.45),
                  inset 0 1px 0 rgba(255, 255, 255, 0.18),
                  inset 0 -1px 0 rgba(0, 0, 0, 0.25);
  --blur: 28px;
  --radius: 22px;
  --radius-sm: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-1: #eef0f6;
    --bg-2: #dfe5f1;
    --text: #1c1c1e;
    --text-dim: rgba(28, 28, 30, 0.62);
    --text-mute: rgba(28, 28, 30, 0.42);
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-bg-strong: rgba(255, 255, 255, 0.7);
    --glass-stroke: rgba(255, 255, 255, 0.7);
    --glass-stroke-soft: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 30px 60px -20px rgba(31, 41, 70, 0.25),
                    0 8px 22px -8px rgba(31, 41, 70, 0.18),
                    inset 0 1px 0 rgba(255, 255, 255, 0.9),
                    inset 0 -1px 0 rgba(0, 0, 0, 0.05);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "Helvetica Neue", Inter, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  /* iOS safe-area aware */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- ambient blobs (the colors the glass actually refracts) ---------- */
.ambient {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.blob {
  position: absolute; border-radius: 50%;
  filter: blur(80px); opacity: 0.65; mix-blend-mode: screen;
  animation: drift 22s ease-in-out infinite alternate;
}
.blob-a { width: 520px; height: 520px; left: -120px; top: -120px;
  background: radial-gradient(circle, #5e5ce6, transparent 60%); }
.blob-b { width: 620px; height: 620px; right: -160px; top: 20%;
  background: radial-gradient(circle, #ff375f, transparent 60%);
  animation-delay: -7s; animation-duration: 28s; }
.blob-c { width: 540px; height: 540px; left: 30%; bottom: -180px;
  background: radial-gradient(circle, #0a84ff, transparent 60%);
  animation-delay: -14s; animation-duration: 25s; }
@keyframes drift {
  0%   { transform: translate3d(0,0,0) scale(1); }
  50%  { transform: translate3d(40px,-30px,0) scale(1.08); }
  100% { transform: translate3d(-30px,40px,0) scale(0.96); }
}
@media (prefers-color-scheme: light) {
  .blob { mix-blend-mode: multiply; opacity: 0.45; }
}

/* ---------- the glass primitive ---------- */
.glass {
  position: relative;
  background: var(--glass-bg);
  border: 1px solid var(--glass-stroke);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  /* the magic: blur + saturate gives the Liquid Glass refraction look */
  backdrop-filter: blur(var(--blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(180%);
  isolation: isolate;
}
/* specular top highlight — that subtle "wet glass" sheen */
.glass::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg,
    rgba(255,255,255,0.22) 0%,
    rgba(255,255,255,0.04) 30%,
    rgba(255,255,255,0)   60%);
  mix-blend-mode: overlay;
  opacity: 0.8;
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--glass-bg-strong); }
}

/* ---------- layout ---------- */
.shell {
  position: relative; z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 18px 64px;
  display: flex; flex-direction: column; gap: 18px;
}
@media (min-width: 820px) { .shell { padding: 36px 28px 80px; gap: 22px; } }

.header {
  padding: 16px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  position: sticky; top: max(12px, env(safe-area-inset-top));
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand h1 {
  margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em;
}
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background:
    radial-gradient(120% 120% at 20% 10%, #fff 0%, transparent 40%),
    linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.5),
              0 6px 18px -6px rgba(10, 132, 255, 0.55);
  flex: 0 0 auto;
}

#paths {
  margin: 2px 0 0; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw;
}

.muted { color: var(--text-dim); }
.muted.small { font-size: 12px; color: var(--text-mute); }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  font: inherit; color: var(--text);
  border-radius: 999px; padding: 10px 18px;
  border: 1px solid var(--glass-stroke);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; transition: transform .12s ease, background .15s ease, opacity .15s ease;
  user-select: none; min-height: 38px;
}
.btn:hover { background: rgba(255,255,255,0.18); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 92%, white 8%), var(--accent));
  border-color: rgba(255,255,255,0.25);
  color: white;
  box-shadow: 0 8px 22px -10px rgba(10, 132, 255, 0.7),
              inset 0 1px 0 rgba(255,255,255,0.4);
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost {
  background: transparent; border-color: var(--glass-stroke-soft);
}
.btn.danger { color: var(--danger); border-color: rgba(255,69,58,0.4); }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- segmented control (Apple-style tabs) ---------- */
.tabs {
  display: inline-flex; padding: 4px; gap: 2px;
  border-radius: 999px;
  align-self: center;
  width: max-content;
  max-width: 100%;
}
.tab {
  appearance: none; border: none;
  font: inherit; color: var(--text-dim);
  padding: 8px 18px; border-radius: 999px;
  background: transparent; cursor: pointer;
  transition: color .15s ease, background .15s ease;
  user-select: none; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  background: rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25),
              0 4px 12px -4px rgba(0,0,0,0.35);
}
@media (prefers-color-scheme: light) {
  .tab.active { background: rgba(255, 255, 255, 0.9); }
}

.view[hidden] { display: none !important; }

/* ---------- library view ---------- */
.library-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  position: sticky; top: calc(max(12px, env(safe-area-inset-top)) + 70px);
  z-index: 4;
}
.library-toolbar input[type="search"] {
  flex: 1; min-width: 0;
  font: inherit; color: var(--text);
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--glass-stroke-soft);
  padding: 9px 14px; border-radius: 999px;
  outline: none;
  -webkit-appearance: none;
}
@media (prefers-color-scheme: light) {
  .library-toolbar input[type="search"] { background: rgba(255,255,255,0.6); }
}
.library-toolbar input[type="search"]:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}
.library-stats { white-space: nowrap; }
#libraryRefresh { padding: 8px 12px; font-size: 16px; line-height: 1; }

.library-content { display: flex; flex-direction: column; gap: 26px; }

.lib-section { display: flex; flex-direction: column; gap: 12px; }
.lib-section-head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 0 4px;
}
.lib-section-head h2 {
  margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em;
}
.lib-section-head .muted { font-size: 13px; }

.poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 14px;
}
@media (min-width: 640px) {
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 18px; }
}
@media (min-width: 1100px) {
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

.tile {
  display: flex; flex-direction: column; gap: 6px;
  cursor: default;
  animation: rise .35s ease both;
}
.tile-poster {
  position: relative;
  width: 100%; aspect-ratio: 2 / 3;
  border-radius: 14px; overflow: hidden;
  background: linear-gradient(135deg, rgba(255,255,255,0.06), rgba(0,0,0,0.18));
  border: 1px solid var(--glass-stroke-soft);
  box-shadow: 0 10px 26px -14px rgba(0,0,0,0.6),
              inset 0 1px 0 rgba(255,255,255,0.10);
  transition: transform .2s ease, box-shadow .2s ease;
}
.tile:hover .tile-poster {
  transform: translateY(-2px);
  box-shadow: 0 16px 32px -12px rgba(0,0,0,0.7),
              inset 0 1px 0 rgba(255,255,255,0.15);
}
.tile-poster img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.tile-fallback {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 12px; text-align: center;
  font-size: 13px; font-weight: 500; color: var(--text-dim);
}
.tile-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.55); color: white;
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  backdrop-filter: blur(8px);
}
.tile-title {
  font-size: 13px; font-weight: 500; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; padding: 0 2px;
}
.tile-sub {
  font-size: 11px; color: var(--text-mute); padding: 0 2px;
}

.library-loading,
.library-empty {
  padding: 40px 20px; text-align: center; color: var(--text-dim);
}

/* ---------- status banner ---------- */
.status {
  padding: 14px 18px; font-size: 14px;
  display: flex; align-items: center; gap: 10px;
}
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

/* ---------- list of candidates ---------- */
.list {
  display: grid; grid-template-columns: 1fr; gap: 14px;
}
@media (min-width: 720px) { .list { gap: 18px; } }

.card {
  padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.card-head {
  display: flex; gap: 14px; align-items: flex-start;
}
.card-head-text {
  display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1;
}
.poster {
  width: 64px; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--glass-stroke-soft);
  box-shadow: 0 8px 20px -10px rgba(0,0,0,0.6);
  flex: 0 0 auto;
  background: rgba(0,0,0,0.25);
}
@media (min-width: 720px) {
  .card { padding: 20px; }
  .poster { width: 80px; }
}
.badge.tmdb {
  color: white;
  background: linear-gradient(135deg, #01b4e4, #0d253f);
  border-color: transparent;
}

.orig {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px; color: var(--text-mute);
  word-break: break-all;
}

.meta { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  padding: 4px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.10);
  border: 1px solid var(--glass-stroke-soft);
  color: var(--text-dim);
}
.badge.confidence.high   { color: var(--success); border-color: rgba(48,209,88,0.35); }
.badge.confidence.medium { color: var(--warn);    border-color: rgba(255,159,10,0.35); }
.badge.confidence.low    { color: var(--danger);  border-color: rgba(255,69,58,0.35); }
.badge.series {
  color: white; background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: transparent;
}

/* ---------- form rows ---------- */
.rename {
  display: grid; grid-template-columns: 1fr; gap: 10px;
}
@media (min-width: 720px) { .rename { grid-template-columns: 2fr 1fr; gap: 14px; } }

.rename label { display: flex; flex-direction: column; gap: 6px; }

.rename input {
  font: inherit; color: var(--text);
  padding: 10px 14px; min-height: 40px;
  background: rgba(0,0,0,0.20);
  border: 1px solid var(--glass-stroke-soft);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
  -webkit-appearance: none;
}
@media (prefers-color-scheme: light) {
  .rename input { background: rgba(255,255,255,0.6); }
}
.rename input:focus {
  border-color: color-mix(in srgb, var(--accent) 70%, transparent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}

.dest {
  display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--glass-stroke-soft);
}
@media (prefers-color-scheme: light) {
  .dest { background: rgba(255,255,255,0.45); }
}
.dest code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; word-break: break-all;
}

/* Collision banner — appears when a file already exists at destination */
.collision {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: rgba(255, 159, 10, 0.12);
  border: 1px solid rgba(255, 159, 10, 0.35);
}
.collision.replace {
  background: rgba(48, 209, 88, 0.10);
  border-color: rgba(48, 209, 88, 0.30);
}
.collision.keep_existing {
  background: rgba(255, 69, 58, 0.12);
  border-color: rgba(255, 69, 58, 0.35);
}
.collision-icon {
  flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; line-height: 1;
  background: rgba(255, 255, 255, 0.18);
}
.collision.replace .collision-icon::before { content: "↻"; }
.collision.keep_existing .collision-icon::before { content: "⊘"; }
.collision-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.collision-title { font-size: 13px; font-weight: 600; }
.collision.replace .collision-title { color: var(--success); }
.collision.keep_existing .collision-title { color: var(--danger); }

.actions {
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
}
@media (max-width: 480px) {
  .actions { flex-direction: column-reverse; }
  .actions .btn { width: 100%; justify-content: center; }
}

.card.removing {
  animation: collapse .35s ease forwards;
  pointer-events: none;
}
@keyframes collapse {
  to { opacity: 0; transform: translateY(-6px) scale(0.98); }
}

/* macOS / iPadOS large screens get a bit more breathing room */
@media (min-width: 1100px) {
  .shell { max-width: 1080px; }
  body { font-size: 16px; }
}

/* respect reduce-motion */
@media (prefers-reduced-motion: reduce) {
  .blob, .card, .spinner { animation: none !important; }
  .btn { transition: none; }
}
