/*
 * Tablet and laptop layout. Loaded after style.css / halloween.css; every rule lives
 * inside a min-width query, so the phone layout is untouched.
 *   768px+  tablet: one wider column (760px), bottom navigation, 4-column grids.
 *   1100px+ laptop: navigation becomes a left sidebar (like the admin workspace),
 *           content column next to it, 5-column grids, home rows become grids.
 * The administrator workspace (body.admin-mode) has its own desktop layout.
 */

@media (min-width: 768px) {
  body:not(.admin-mode) {
    --app-column: 760px;
  }

  body:not(.admin-mode) .app-container,
  body:not(.admin-mode) .bottom-nav {
    max-width: var(--app-column);
  }

  body:not(.admin-mode) .app-container {
    box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.12), 0 24px 80px rgba(3, 1, 10, 0.55);
  }

  body:not(.admin-mode) .catalog-grid,
  body:not(.admin-mode) .npc-grid,
  body:not(.admin-mode) .story-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 16px !important;
    padding-inline: 24px !important;
  }

  body:not(.admin-mode) .catalog-card,
  body:not(.admin-mode) .npc-card,
  body:not(.admin-mode) .story-card {
    min-height: 0 !important;
  }

  .home-character-row,
  .home-video-row,
  .home-photo-row {
    grid-auto-columns: 200px;
  }

  .character-sheet-panel {
    max-width: 640px;
  }

  .world-list,
  #worlds-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-view,
  .subscription-view {
    padding-inline: 32px;
  }

  .toast-container {
    max-width: min(560px, calc(100vw - 32px));
  }

  /* Chat page: a wider column, bubbles keep a readable line length. */
  .site-chat-shell {
    width: min(820px, 100%);
    max-width: 820px;
    box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.14), 0 24px 80px rgba(3, 1, 10, 0.6);
  }

  .site-chat-bubble {
    max-width: min(78%, 620px);
  }

  /* Chat page: the sections panel stays on the left, the chat column sits next to it. */
  .site-chat-body {
    --chat-sidebar: 188px;
    --chat-frame-left: max(0px, calc((100vw - 820px - var(--chat-sidebar)) / 2));
  }

  .site-chat-body .site-chat-shell {
    left: calc(var(--chat-frame-left) + var(--chat-sidebar));
    width: min(820px, calc(100vw - var(--chat-sidebar)));
    transform: none;
  }

  /* Beats the laptop sidebar rule for the app page (body:not(.admin-mode):not(.setting-play-mode) .bottom-nav). */
  body.site-chat-body:not(.admin-mode):not(.setting-play-mode) .site-chat-nav {
    display: flex !important;
    top: 0;
    bottom: 0;
    left: var(--chat-frame-left);
    right: auto;
    z-index: 40;
    width: var(--chat-sidebar);
    max-width: none;
    height: auto;
    margin: 0;
    padding: 36px 12px calc(20px + env(safe-area-inset-bottom, 0px));
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 2px;
    border-top: 0;
    border-right: 1px solid rgba(168, 85, 247, 0.14);
    background: rgba(9, 5, 20, 0.72);
    box-shadow: none;
  }

  .site-chat-nav .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 40px;
    padding: 0 12px 0 16px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: rgba(226, 214, 255, 0.58);
    text-shadow: none;
    filter: none;
    transition: color 0.2s ease, background 0.2s ease;
  }

  .site-chat-nav .nav-item .nav-icon svg {
    width: 17px;
    height: 17px;
    stroke-width: 1.7;
  }

  .site-chat-nav .nav-item:hover {
    background: rgba(168, 85, 247, 0.07);
    color: rgba(245, 238, 255, 0.92);
  }

  .site-chat-nav .nav-item.active {
    background: linear-gradient(90deg, rgba(168, 85, 247, 0.16), rgba(168, 85, 247, 0.02));
    color: #fff;
    text-shadow: 0 0 10px rgba(216, 180, 254, 0.45);
  }

  .site-chat-nav .nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 2px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--accent-neon), var(--accent-pink));
    box-shadow: 0 0 10px rgba(192, 132, 252, 0.8);
  }

  .site-chat-body.theme-light .site-chat-nav {
    border-right-color: rgba(255, 145, 196, 0.32);
    background: rgba(255, 249, 253, 0.86);
  }

  .site-chat-body.theme-light .site-chat-nav .nav-item {
    color: #9a7f99;
  }

  .site-chat-body.theme-light .site-chat-nav .nav-item.active {
    background: linear-gradient(90deg, rgba(255, 91, 168, 0.12), rgba(255, 91, 168, 0.02));
    color: #c2185b;
    text-shadow: none;
  }
}

/* Tablets in portrait: a narrower panel leaves the chat enough room. */
@media (min-width: 768px) and (max-width: 899px) {
  .site-chat-body {
    --chat-sidebar: 150px;
  }

  .site-chat-nav .nav-item {
    padding: 0 8px 0 12px;
    gap: 8px;
    font-size: 10px;
    letter-spacing: 0.08em;
  }
}

@media (min-width: 1100px) {
  body:not(.admin-mode) {
    --app-sidebar: 188px;
    --app-column: 1200px;
    padding-bottom: 0;
  }

  /* Content sits to the right of the sidebar inside one centered frame. */
  body:not(.admin-mode) .app-container {
    padding-left: var(--app-sidebar);
    padding-bottom: 32px;
  }

  /* A slim, quiet sidebar: thin items, a glowing accent line marks the current one. */
  body:not(.admin-mode):not(.setting-play-mode) .bottom-nav {
    top: 0;
    bottom: 0;
    left: max(0px, calc(50% - var(--app-column) / 2));
    right: auto;
    width: var(--app-sidebar);
    max-width: none;
    height: auto;
    margin: 0;
    padding: 36px 12px calc(20px + env(safe-area-inset-bottom, 0px));
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 2px;
    border-top: 0;
    border-right: 1px solid rgba(168, 85, 247, 0.14);
    background: rgba(9, 5, 20, 0.72);
    box-shadow: none;
  }

  body:not(.admin-mode) .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 40px;
    padding: 0 12px 0 16px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: rgba(226, 214, 255, 0.58);
    text-shadow: none;
    filter: none;
    transition: color 0.2s ease, background 0.2s ease;
  }

  body:not(.admin-mode) .nav-item .nav-icon svg {
    width: 17px;
    height: 17px;
    stroke-width: 1.7;
  }

  body:not(.admin-mode) .nav-item:hover {
    background: rgba(168, 85, 247, 0.07);
    color: rgba(245, 238, 255, 0.92);
  }

  body:not(.admin-mode) .nav-item.active {
    background: linear-gradient(90deg, rgba(168, 85, 247, 0.16), rgba(168, 85, 247, 0.02));
    color: #fff;
    text-shadow: 0 0 10px rgba(216, 180, 254, 0.45);
  }

  body:not(.admin-mode) .nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 2px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--accent-neon), var(--accent-pink));
    box-shadow: 0 0 10px rgba(192, 132, 252, 0.8);
  }

  body:not(.admin-mode) .nav-new-indicator {
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
  }

  body.theme-light:not(.admin-mode) .bottom-nav {
    border-right-color: rgba(255, 145, 196, 0.32);
    background: rgba(255, 249, 253, 0.86);
    box-shadow: none;
  }

  body.theme-light:not(.admin-mode) .nav-item {
    color: #9a7f99;
  }

  body.theme-light:not(.admin-mode) .nav-item.active {
    background: linear-gradient(90deg, rgba(255, 91, 168, 0.12), rgba(255, 91, 168, 0.02));
    color: #c2185b;
    text-shadow: none;
  }

  body:not(.admin-mode) .catalog-grid,
  body:not(.admin-mode) .npc-grid,
  body:not(.admin-mode) .story-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 18px !important;
    padding-inline: 32px !important;
  }

  /* With a mouse a hidden horizontal scroll is unreachable: rows become grids. */
  .home-character-row,
  .home-video-row,
  .home-photo-row {
    grid-auto-flow: row !important;
    grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)) !important;
    grid-auto-columns: auto;
    overflow: visible;
    padding-inline: 24px;
  }

  /* Videos stay one row: three smaller cards in view, the rest by scrolling (a thin visible
     scrollbar for the mouse) or on the video page. */
  .home-video-row {
    --home-video-width: 230px;
    grid-auto-flow: column !important;
    grid-template-columns: none !important;
    grid-auto-columns: var(--home-video-width);
    gap: 18px !important;
    /* Exactly three whole cards: no right padding where a fourth card would peek in, and
       scrolling stops on a card's edge. */
    max-width: calc(3 * var(--home-video-width) + 2 * 18px + 24px);
    padding-inline: 24px 0;
    scroll-padding-left: 24px;
    scroll-snap-type: x mandatory;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(192, 132, 252, 0.45) transparent;
    padding-bottom: 10px;
  }

  .home-video-row::-webkit-scrollbar {
    display: block;
    height: 6px;
  }

  .home-video-row::-webkit-scrollbar-thumb {
    border-radius: 99px;
    background: rgba(192, 132, 252, 0.45);
  }

  #worlds-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .settings-view,
  .subscription-view {
    max-width: 820px;
    margin-inline: auto;
  }

  .character-sheet-panel {
    max-width: 720px;
  }
}

@media (min-width: 1100px) and (max-width: 1240px) {
  body:not(.admin-mode):not(.setting-play-mode) .bottom-nav {
    left: 0;
  }
}
