/* Portal Studio on phones + the restrained depth look for Portal Projects
   and the editor. Loaded after styles.css. Layout only: the editor engine,
   timeline, tools, Save/Export and destination series are unchanged.
   Phone = portrait up to 760px wide, or a short landscape screen (the same
   query as STUDIO_PHONE_QUERY in app.js). */

.ps-phonebar { display: none; }

/* ------------------------------------------------ depth look (tablet/desktop) */
@media (min-width: 761px) and (min-height: 501px), (min-width: 1001px) {
  #view-studio #edPanel {
    background:
      radial-gradient(120% 70% at 50% -12%, #22143a 0%, transparent 60%),
      linear-gradient(180deg, #0f0819, #090512);
    border: 1px solid #2d1e4a;
    box-shadow: inset 0 1px 0 #ffffff12, 0 2px 0 #05020b, 0 26px 60px #000a, 0 0 0 1px #a879ff14;
  }
  #view-studio #edPanel :is(.ps-topbar, .ps-rail, .ps-toolpanel, .ps-inspector, .ps-transport, .ps-bottom) {
    background: linear-gradient(180deg, #20153a 0%, #170f27 100%);
    border-color: #33235a;
    box-shadow: inset 0 1px 0 #ffffff10, inset 0 -1px 0 #0006, 0 8px 18px #0006;
  }
  #view-studio #edPanel .editor-stage {
    border-color: #2f2150;
    box-shadow: inset 0 0 0 1px #19f57a1a, inset 0 0 40px #0008, 0 16px 36px #000b;
  }
  #view-studio #edPanel .ps-rail .ed2-tool[aria-pressed="true"] {
    box-shadow: inset 0 0 12px #19f57a26, 0 0 0 1px #19f57a55, 0 4px 12px #19f57a1f;
  }
}

/* ------------------------------------------------ phone shared pieces */
@media (max-width: 760px) and (orientation: portrait), (max-height: 500px) and (max-width: 1000px) and (orientation: landscape) {
  #view-studio #edPanel {
    overflow-x: hidden;
    max-width: 100%;
    background: linear-gradient(180deg, #120c1c, #0c0814);
  }
  #view-studio #edPanel.ps-full {
    /* The keyboard shrinks the visual viewport; follow it (set by portal-studio-mobile.js). */
    height: var(--ps-vvh, 100dvh);
    top: var(--ps-vvtop, 0);
    bottom: auto;
  }
  #view-studio #edPanel :is(.ps-main, .ps-left) { display: contents; }
  #view-studio #edPanel .ps-topbar { grid-area: top; min-width: 0; }
  #view-studio #edPanel .ps-center { grid-area: center; min-width: 0; min-height: 0; }
  #view-studio #edPanel .ps-bottom { grid-area: tl; min-width: 0; min-height: 0; height: auto; margin: 0; }
  #view-studio #edPanel :is(.ps-toolpanel, .ps-inspector) {
    grid-area: pane; display: none; min-width: 0; min-height: 0; max-height: none; height: auto;
    overflow: auto; overscroll-behavior: contain; border-top: 1px solid var(--ps-edge);
  }
  #view-studio #edPanel[data-mobile-panel="tool"] .ps-toolpanel { display: block; }
  #view-studio #edPanel[data-mobile-panel="inspector"] .ps-inspector { display: flex; }

  /* The preview stays inside its own pane; the canvas is fitted by fitStage(). */
  #view-studio #edPanel .editor-stage { overflow: hidden; contain: paint; position: relative; }

  /* Only the timeline scrolls sideways. */
  #view-studio #edPanel .ps-bottom .ed2-zoomscroll { overflow-x: auto; overflow-y: auto; touch-action: pan-x pan-y; }
  #view-studio #edPanel .ps-tl-head { min-width: 0; gap: 6px; }

  /* Tools tray: collapsed by default, opened with the labeled Tools button. */
  #view-studio #edPanel .ps-rail {
    grid-area: tray; display: none; margin: 0; min-width: 0;
    border: 0; border-top: 1px solid var(--ps-edge); border-radius: 0;
    background: linear-gradient(180deg, #1d1530, #150f22);
    box-shadow: inset 0 1px 0 #ffffff0d;
  }
  #view-studio #edPanel[data-tray="open"] .ps-rail {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px; padding: 6px; overflow: visible;
  }
  #view-studio #edPanel .ps-rail .ed2-tool {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-width: 0; min-height: 52px; padding: 4px 2px; flex: none;
    font: 600 .7rem/1.15 system-ui, sans-serif; font-style: normal;
    color: var(--ps-dim); background: #ffffff06; border: 1px solid transparent; border-radius: 10px;
    overflow-wrap: anywhere; text-align: center;
  }
  #view-studio #edPanel .ps-rail .ed2-tool .ed2-tool-ic { font-size: 1.15rem; line-height: 1; }
  #view-studio #edPanel .ps-rail .ed2-tool[aria-pressed="true"] {
    color: var(--ps-accent); border-color: color-mix(in srgb, var(--ps-accent) 60%, transparent);
    background: color-mix(in srgb, var(--ps-accent) 10%, transparent);
  }

  /* Bottom bar: Timeline · Tools · Details */
  #view-studio #edPanel .ps-phonebar {
    grid-area: bar; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 6px; padding: 5px 6px; min-width: 0;
    border-top: 1px solid var(--ps-edge);
    background: linear-gradient(180deg, #171121, #110c19);
  }
  #view-studio #edPanel .ps-phonebar button {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    min-width: 0; min-height: 46px; padding: 0 8px;
    font: 600 .8rem/1.1 system-ui, sans-serif; font-style: normal;
    color: var(--ps-dim); background: transparent; border: 1px solid transparent; border-radius: 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; touch-action: manipulation;
  }
  #view-studio #edPanel .ps-phonebar button > span { font-size: 1.1rem; line-height: 1; }
  #view-studio #edPanel .ps-phonebar .ps-mobile-tab[aria-pressed="true"] { color: var(--ps-accent); background: #ffffff08; }
  #view-studio #edPanel .ps-phonebar .ps-tray-toggle {
    color: #f3f0ff; border-color: #3b2d5c;
    background: linear-gradient(180deg, #2a1f42, #1c1530);
    box-shadow: inset 0 1px 0 #ffffff14, 0 4px 12px #0007;
  }
  #view-studio #edPanel .ps-tray-toggle small {
    color: var(--ps-accent); font-size: .72rem; font-weight: 600;
    min-width: 0; overflow: hidden; text-overflow: ellipsis;
  }
  #view-studio #edPanel .ps-tray-toggle small::before { content: "· "; color: var(--ps-dim); }
  #view-studio #edPanel .ps-tray-toggle small:empty { display: none; }
  #view-studio #edPanel .ps-tray-toggle[aria-expanded="true"] { border-color: var(--ps-accent); }
  #view-studio #edPanel .ps-phonebar button:focus-visible,
  #view-studio #edPanel .ps-rail .ed2-tool:focus-visible { outline: 2px solid var(--ps-accent); outline-offset: 1px; }
}

/* ------------------------------------------------ phone portrait */
@media (max-width: 760px) and (orientation: portrait) {
  #view-studio #edPanel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "center" "tl" "pane" "tray" "bar";
    grid-template-rows: auto auto minmax(0, 1fr) 0 auto auto !important;
    overflow-y: auto !important;
  }
  #view-studio #edPanel:is([data-mobile-panel="tool"], [data-mobile-panel="inspector"]) {
    grid-template-rows: auto auto minmax(92px, 2fr) minmax(0, 3fr) auto auto !important;
  }
  #view-studio #edPanel .editor-stage:not(:fullscreen) { height: clamp(140px, 33dvh, 300px) !important; }
  #view-studio #edPanel:is([data-mobile-panel="tool"], [data-mobile-panel="inspector"]) .editor-stage:not(:fullscreen) {
    height: clamp(110px, 24dvh, 220px) !important;
  }
  #view-studio #edPanel .ps-transport { row-gap: 2px; }
  #view-studio #edPanel #edHostedLimits { font-size: .72rem; }
}
@media (max-width: 760px) and (max-height: 620px) and (orientation: portrait) {
  #view-studio #edPanel .editor-stage:not(:fullscreen) { height: clamp(110px, 28dvh, 200px) !important; }
  #view-studio #edPanel:is([data-mobile-panel="tool"], [data-mobile-panel="inspector"]) .editor-stage:not(:fullscreen) {
    height: clamp(90px, 20dvh, 150px) !important;
  }
}

/* ------------------------------------------------ phone landscape */
@media (max-height: 500px) and (max-width: 1000px) and (orientation: landscape) {
  #view-studio #edPanel {
    --ps-panel: #1b1528; --ps-edge: #33294a; --ps-dim: #c6bedb; --ps-accent: #54efc0;
    display: grid !important;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    grid-template-areas: "top top" "center tl" "center pane" "center tray" "center bar";
    grid-template-rows: auto minmax(0, 1fr) 0 auto auto;
    gap: 4px 8px;
    height: 100dvh; min-height: 0;
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    border-radius: 0; overflow: hidden;
  }
  #view-studio #edPanel:is([data-mobile-panel="tool"], [data-mobile-panel="inspector"]) {
    grid-template-rows: auto minmax(108px, 1fr) minmax(0, 1.2fr) auto auto;
  }
  #view-studio #edPanel :is(.ps-topbar, .ps-transport, .ps-bottom, .ps-toolpanel, .ps-inspector) {
    margin: 0; border-radius: 10px; border: 1px solid var(--ps-edge);
    background: linear-gradient(180deg, #1e1730, #161022);
    box-shadow: inset 0 1px 0 #ffffff0d;
  }
  #view-studio #edPanel .ps-topbar { flex-wrap: nowrap; gap: 4px; padding: 2px 4px; }
  #view-studio #edPanel .ps-topbar :is(button, select) { height: 40px; min-width: 40px; }
  #view-studio #edPanel .ps-brand { display: none; }
  #view-studio #edPanel .ps-proj { display: block; flex: 1 1 auto; min-width: 0; max-width: none; }
  #view-studio #edPanel .ps-topspacer { display: none; }
  #view-studio #edPanel #edExport { padding-inline: 14px; }
  #view-studio #edPanel .ps-center { display: flex; flex-direction: column; gap: 4px; }
  #view-studio #edPanel .editor-stage:not(:fullscreen) {
    flex: 1 1 auto; height: auto !important; min-height: 80px; max-height: none; border-radius: 10px;
  }
  #view-studio #edPanel .ps-transport {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
    gap: 2px 6px; padding: 2px 6px; flex: none;
  }
  #view-studio #edPanel .ps-transport :is(.ed2-iconbtn, .ed2-play) { width: 40px; height: 40px; min-height: 40px; min-width: 40px; }
  #view-studio #edPanel #edStatus:empty { display: none; }
  #view-studio #edPanel #edHostedLimits { flex-basis: 100%; font-size: .68rem; line-height: 1.25; text-align: center; margin: 0; }
  #view-studio #edPanel .studio-save-tools { flex-basis: 100%; justify-content: center; }
  #view-studio #edPanel .studio-save-tools button { min-height: 36px; padding: 0 10px; font-size: .76rem; }
  #view-studio #edPanel #edExportBox { max-height: 45%; overflow: auto; flex: none; margin: 0; }
  #view-studio #edPanel .ps-bottom { padding: 4px 6px; }
  #view-studio #edPanel .ps-tl-head .ps-tl-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #view-studio #edPanel .ps-tl-head { margin-bottom: 2px; }
  /* While a tool or Details is open, keep the ruler + clip strip; Add clips and zoom return with Timeline. */
  #view-studio #edPanel:is([data-mobile-panel="tool"], [data-mobile-panel="inspector"]) .ps-tl-head { display: none; }
  #view-studio #edPanel .ps-tl-head :is(.ps-add-clips, .ed2-iconbtn) { min-height: 36px; height: 36px; margin: 0; white-space: nowrap; }
  #view-studio #edPanel .ps-tl-head .ps-add-clips { display: inline-flex; align-items: center; padding-block: 0; }
  #view-studio #edPanel .ed2-lanes-head { display: none; }
  #view-studio #edPanel .ps-phonebar { border: 0; padding: 0; background: transparent; }
  #view-studio #edPanel .ps-phonebar button { min-height: 42px; }
  #view-studio #edPanel[data-tray="open"] .ps-rail { border-radius: 10px; border: 1px solid var(--ps-edge); }
  #view-studio #edPanel .ps-rail .ed2-tool { min-height: 46px; }
}

/* Keyboard open: give the visible space to the field and the timeline. */
@media (max-width: 760px) and (orientation: portrait), (max-height: 500px) and (max-width: 1000px) and (orientation: landscape) {
  #view-studio #edPanel[data-keyboard="open"] .editor-stage:not(:fullscreen) {
    height: clamp(72px, calc(var(--ps-vvh, 100dvh) * .22), 160px) !important;
    flex: none;
  }
  #view-studio #edPanel[data-keyboard="open"] :is(.ps-rail, #edHostedLimits) { display: none; }
}

/* ------------------------------------------------ Portal Projects depth */
#view-portal-projects .portal-series-card {
  position: relative; isolation: isolate;
  background: linear-gradient(180deg, #1a201f, #121615);
  border-color: #3d4644;
  box-shadow: inset 0 1px 0 #ffffff14, 0 2px 0 #050707, 0 12px 26px #0009;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
#view-portal-projects .portal-series-card .portal-art { image-rendering: auto; }
#view-portal-projects .portal-series-card::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(160deg, #ffffff12 0%, transparent 32%);
}
#view-portal-projects .portal-episode-row {
  background: linear-gradient(180deg, #151a19, #101413);
  box-shadow: inset 0 1px 0 #ffffff0f, 0 6px 16px #0007;
}
#view-portal-projects .portal-lime { box-shadow: inset 0 1px 0 #ffffff59, 0 3px 0 #4d6b10, 0 6px 16px #b9fc4033; }
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  #view-portal-projects .portal-series-card:hover {
    transform: translateY(-3px);
    border-color: #b9fc4099;
    box-shadow: inset 0 1px 0 #ffffff1f, 0 2px 0 #050707, 0 18px 34px #000b, 0 0 0 1px #b9fc4033;
  }
}
