/* Phone layout overrides. Kept in a separate file so desktop presentation remains unchanged. */
@media (max-width: 600px), (max-width: 980px) and (max-height: 540px) and (orientation: landscape) {
  :root {
    --mobile-edge: 14px;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    min-width: 320px;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
  }

  button,
  a,
  input,
  textarea,
  select,
  summary {
    touch-action: manipulation;
  }

  .site-header {
    top: max(10px, env(safe-area-inset-top));
    left: var(--mobile-edge);
    right: var(--mobile-edge);
    min-height: 60px;
    border-radius: 18px;
  }

  .menu-toggle,
  .focus-settings-button,
  .study-exit-button,
  .calendar-controls button {
    min-width: 44px;
    min-height: 44px;
  }

  .navigation-shell {
    max-height: calc(100svh - 92px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .site-nav a,
  .account-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .home-hero {
    min-height: 100svh;
    padding-bottom: calc(98px + env(safe-area-inset-bottom));
  }

  .room-presence {
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  /* Scene selector: use a horizontal control dock instead of a clipped side rail. */
  .scene-selection-main {
    grid-template-columns: minmax(0, 1fr);
    padding-right: var(--mobile-edge);
    padding-left: var(--mobile-edge);
  }

  .scene-workspace {
    display: flex;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    flex-direction: column;
    gap: 14px;
  }

  .scene-workspace .scene-picker,
  .scene-track {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .scene-track {
    touch-action: pan-y;
  }

  .settings-rail {
    width: 100%;
    min-width: 0;
    min-height: 66px;
    margin: 0;
    padding: 8px;
    align-self: stretch;
    justify-self: stretch;
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    border-radius: 18px;
    scrollbar-width: none;
  }

  .settings-rail::-webkit-scrollbar {
    display: none;
  }

  .settings-rail-section,
  .settings-icon-stack,
  .settings-time-stack {
    width: auto;
    display: flex;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    gap: 7px;
  }

  .rail-divider {
    width: 1px;
    height: 32px;
    margin: 0 2px;
  }

  .rail-option {
    width: 38px;
    height: 38px;
    font-size: 17px;
  }

  .rail-time {
    width: 42px;
    height: 36px;
    border-color: rgba(255, 255, 255, 0.36);
    border-radius: 50%;
  }

  .rail-enter-button {
    width: 46px;
    height: 46px;
    margin-left: 2px;
  }

  .rail-option::after,
  .rail-time::after,
  .rail-enter-button::after {
    display: none;
  }

  .settings-rail .inline-setting-form {
    position: fixed;
    z-index: 80;
    top: auto;
    right: var(--mobile-edge);
    bottom: max(12px, env(safe-area-inset-bottom));
    left: var(--mobile-edge);
    width: auto;
    transform: none;
  }

  /* Focus room: timer first, then tasks; controls remain reachable without hover. */
  .study-room-main {
    min-height: 100svh;
    padding-right: var(--mobile-edge);
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
    padding-left: var(--mobile-edge);
  }

  .timer-stage {
    min-height: min(54svh, 460px);
  }

  .timer-display {
    font-size: clamp(56px, 18vw, 74px);
  }

  .timer-control,
  .timer-controls button,
  .todo-add,
  .todo-remove {
    min-width: 44px;
    min-height: 44px;
  }

  .todo-panel {
    padding: 18px;
    border-radius: 18px;
  }

  .study-settings-panel {
    top: calc(76px + env(safe-area-inset-top));
    right: var(--mobile-edge);
    left: var(--mobile-edge);
    width: auto;
    max-height: calc(100svh - 100px);
    overflow-y: auto;
  }

  /* Community: scan feed first, keep long tabs and filters finger-scrollable. */
  .community-main {
    padding-right: 0;
    padding-left: 0;
  }

  .community-intro {
    padding-right: var(--mobile-edge);
    padding-left: var(--mobile-edge);
  }

  .community-intro h1 {
    font-size: clamp(38px, 11vw, 48px);
  }

  .community-workspace {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .community-tabs,
  .subject-filters,
  .post-tags,
  .profile-post-tags {
    overflow-x: auto !important;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }

  .community-tabs::-webkit-scrollbar,
  .subject-filters::-webkit-scrollbar,
  .post-tags::-webkit-scrollbar,
  .profile-post-tags::-webkit-scrollbar {
    display: none;
  }

  .community-tabs button,
  .subject-filters button,
  .post-tags > *,
  .profile-post-tags > * {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .community-feed,
  .publish-panel {
    padding: 16px var(--mobile-edge);
  }

  .publish-type-control input {
    width: 1px !important;
    height: 1px !important;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }

  .community-post {
    padding: 16px;
  }

  .post-footer {
    gap: 10px;
  }

  .post-actions button,
  .publish-panel button,
  .comment-form button {
    min-height: 42px;
  }

  .post-image-grid img {
    max-height: 180px;
    object-fit: cover;
  }

  /* My learning: maintain readable calendar targets and full-width inputs. */
  .my-study-page .page-shell,
  .learning-main {
    width: min(100% - 24px, 680px);
  }

  .learning-intro h1 {
    font-size: clamp(36px, 10vw, 48px);
  }

  .learning-profile-panel,
  .learning-calendar-panel,
  .learning-day-panel,
  .learning-posts-panel {
    padding: 18px;
    border-radius: 18px;
  }

  .learning-goal-form {
    grid-template-columns: 1fr;
  }

  .learning-goal-form button {
    width: 100%;
    min-height: 44px;
  }

  .calendar-weekdays span,
  .calendar-day {
    min-width: 0;
  }

  .calendar-day {
    width: min(34px, 9vw);
    height: min(34px, 9vw);
  }

  /* Chats and user-created rooms become single-column, thumb-friendly flows. */
  .groups-main,
  .theme-rooms-main {
    width: min(100% - 24px, 680px);
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .messenger {
    min-height: 0;
  }

  .conversation-sidebar {
    max-height: 270px;
  }

  .person-card,
  .conversation-row,
  .theme-room-list .room-row {
    min-height: 64px;
  }

  .person-action,
  .groups-mini-button,
  .room-form-actions button {
    min-height: 44px;
  }

  .theme-rooms-intro h1 {
    font-size: clamp(38px, 11vw, 46px);
  }

  .theme-rooms-panel,
  .theme-room-summary,
  .theme-room-sidebar {
    border-radius: 18px;
  }

  .room-background-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .theme-study-room-main {
    padding-right: var(--mobile-edge);
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
    padding-left: var(--mobile-edge);
  }

  .theme-timer-stage {
    min-height: 300px;
  }

  .theme-timer-stage .timer-display {
    font-size: clamp(56px, 17vw, 70px);
  }

  .theme-room-fold summary {
    min-height: 44px;
  }

  .theme-chat-form {
    grid-template-columns: minmax(0, 1fr) 40px 40px;
  }

  .theme-chat-form button,
  .theme-emoji-picker button {
    min-width: 36px;
    min-height: 36px;
  }

  /* Admin: retain the same controls, stack management actions and media cards. */
  .admin-shell {
    gap: 12px;
    padding: 12px;
  }

  .admin-sidebar {
    position: sticky;
    top: max(8px, env(safe-area-inset-top));
    z-index: 20;
    overflow-x: auto;
    border-radius: 16px;
  }

  .admin-nav {
    display: flex;
    min-width: max-content;
  }

  .admin-nav button {
    min-height: 42px;
  }

  .admin-main {
    min-width: 0;
  }

  .admin-topbar,
  .admin-section-heading {
    gap: 12px;
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .admin-heading-actions,
  .admin-preview-link {
    width: 100%;
  }

  .admin-primary-button,
  .admin-secondary-button {
    min-height: 44px;
  }

  .scene-admin-grid,
  .audio-admin-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px), (max-width: 980px) and (max-height: 540px) and (orientation: landscape) {
  .home-hero {
    justify-content: center;
  }

  .hero-copy {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .hero-kicker,
  .hero-description {
    margin-right: auto;
    margin-left: auto;
    text-align: center;
  }

  .hero-actions {
    width: 100%;
    justify-content: center;
  }

  .hero-actions [data-enter-room] {
    margin-right: auto;
    margin-left: auto;
  }
}

@media (max-width: 370px) {
  .brand-copy strong {
    font-size: 16px;
  }

  .hero-copy h1 {
    font-size: 48px;
  }

  .community-toolbar,
  .community-feed,
  .publish-panel {
    padding-right: 12px;
    padding-left: 12px;
  }
}

@media (max-width: 980px) and (max-height: 540px) and (orientation: landscape), (max-width: 600px) and (orientation: portrait) {
  .site-header {
    top: max(7px, env(safe-area-inset-top));
    min-height: 50px;
    padding: 6px 10px;
    border-radius: 16px;
  }

  .brand-seal {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .brand-copy strong {
    font-size: 17px;
  }

  .brand-copy small {
    display: none;
  }

  .menu-toggle {
    display: none;
  }

  .navigation-shell {
    position: static;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-height: none;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    opacity: 1;
    visibility: visible;
    transform: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .site-nav {
    display: flex;
    flex: 1 1 auto;
    gap: 2px;
    min-width: 0;
  }

  .site-nav a,
  .account-link {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  .site-nav a:last-child {
    grid-column: auto;
  }

  .account-actions {
    flex: 0 0 auto;
    padding-top: 0;
    border-top: 0;
  }

  .navigation-shell {
    max-height: calc(100svh - 70px);
  }

  .home-hero {
    min-height: 100svh;
    padding: 68px 7vw 58px;
  }

  .hero-copy {
    width: min(470px, 64vw);
    margin-top: 0;
  }

  .hero-copy h1 {
    font-size: clamp(42px, 7vw, 60px);
  }

  .hero-description {
    margin-top: 9px;
    font-size: 15px;
  }

  .hero-actions {
    margin-top: 18px;
  }

  .room-presence {
    min-height: 46px;
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 7px 12px;
  }

  .scene-selection-main {
    gap: 7px;
    padding: 68px 22px 10px;
  }

  .scene-selection-copy h1 {
    font-size: clamp(30px, 5vw, 40px);
  }

  .scene-selection-copy .hero-kicker,
  .scene-intro {
    margin-top: 4px;
    margin-bottom: 4px;
  }

  .scene-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 64px;
    align-items: center;
    gap: 12px;
  }

  .scene-track {
    height: min(46vh, 250px);
  }

  .scene-card {
    width: min(47vw, 370px);
  }

  .settings-rail {
    width: 64px;
    min-width: 64px;
    min-height: 0;
    max-height: min(58vh, 270px);
    padding: 8px 6px;
    align-self: center;
    justify-self: end;
    flex-direction: column;
    align-items: center;
    overflow-x: visible;
    overflow-y: auto;
    border-radius: 30px;
  }

  .settings-rail-section,
  .settings-icon-stack,
  .settings-time-stack {
    width: 100%;
    flex-direction: column;
    gap: 5px;
  }

  .rail-divider {
    width: 30px;
    height: 1px;
    margin: 2px 0;
  }

  .rail-option {
    width: 32px;
    height: 32px;
  }

  .rail-time {
    width: 40px;
    height: 21px;
    border-color: transparent;
    border-radius: 12px;
  }

  .study-room-main {
    grid-template-columns: minmax(0, 1.1fr) minmax(230px, 0.9fr);
    align-items: center;
    gap: 14px;
    min-height: 100svh;
    padding: 68px 16px 12px;
  }

  .timer-stage {
    min-height: min(67svh, 330px);
    padding: 18px;
  }

  .timer-display {
    font-size: clamp(54px, 10vw, 76px);
  }

  .todo-panel {
    order: 1;
    max-height: min(67svh, 330px);
    overflow-y: auto;
  }

  .study-balance-column {
    display: none;
  }

  .todo-list {
    max-height: 160px;
  }

  .study-settings-panel {
    top: 64px;
    right: 12px;
    left: auto;
    width: min(300px, calc(100vw - 24px));
    max-height: calc(100svh - 76px);
  }

  .community-main {
    padding-top: 68px;
  }

  .community-intro {
    margin-bottom: 10px;
  }

  .community-intro h1,
  .learning-intro h1,
  .theme-rooms-intro h1 {
    font-size: clamp(30px, 5vw, 42px);
  }

  .community-category-bar {
    padding-bottom: 8px;
  }

  .community-body {
    grid-template-columns: minmax(0, 1fr) minmax(230px, 290px);
  }

  .community-feed,
  .publish-panel {
    padding: 14px;
  }

  .publish-panel {
    position: static;
    width: auto;
    max-height: none;
    margin: 0;
  }

  .community-post {
    padding: 14px;
  }

  .learning-main,
  .groups-main,
  .theme-rooms-main {
    width: min(100% - 36px, 920px);
    padding-top: 70px;
    padding-bottom: 28px;
  }

  .learning-main {
    display: grid;
    grid-template-columns: minmax(245px, 0.85fr) minmax(0, 1.15fr);
    gap: 12px;
  }

  .learning-intro,
  .learning-posts-panel {
    grid-column: 1 / -1;
  }

  .learning-profile-panel,
  .learning-calendar-panel,
  .learning-day-panel,
  .learning-posts-panel {
    margin-top: 0;
    padding: 16px;
  }

  .learning-calendar-panel,
  .learning-day-panel {
    min-width: 0;
  }

  .messenger {
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: 430px;
  }

  .conversation-sidebar {
    max-height: none;
  }

  .theme-rooms-main {
    min-height: 100svh;
  }

  .theme-rooms-intro {
    margin-bottom: 14px;
  }

  .theme-rooms-panel {
    padding: 16px;
  }

  .theme-room-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .theme-room-list .room-row {
    min-height: 175px;
    padding: 15px;
  }

  .theme-study-room-main {
    grid-template-columns: minmax(190px, 0.75fr) minmax(0, 1.25fr) minmax(205px, 0.8fr);
    gap: 12px;
    padding: 68px 14px 12px;
  }

  .theme-room-summary,
  .theme-room-sidebar {
    grid-column: auto;
    width: auto;
  }

  .theme-timer-stage {
    min-height: min(66svh, 320px);
  }

  .theme-timer-stage .timer-display {
    font-size: clamp(52px, 9vw, 72px);
  }

  .admin-shell {
    grid-template-columns: 172px minmax(0, 1fr);
    gap: 12px;
    padding: 10px;
  }

  .admin-sidebar {
    position: sticky;
    top: 10px;
    align-self: start;
  }

  .admin-main {
    min-width: 0;
    padding-top: 0;
  }

  .admin-topbar,
  .admin-section-heading {
    padding: 14px;
  }
}

.scene-carousel-arrow,
.mobile-scene-enter {
  display: none;
}

/* Scene selection: landscape H5 uses a continuous full-screen carousel. */
@media (max-width: 980px) and (max-height: 540px) and (orientation: landscape) {
  .scene-page {
    overflow: hidden;
    background: #101816;
  }

  .scene-page .scene-selection-background,
  .scene-page .scene-selection-copy,
  .scene-page .scene-confirmation {
    display: none;
  }

  .scene-page .site-header {
    position: fixed;
    z-index: 30;
    top: max(7px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    min-height: 50px;
    padding: 6px 10px;
    border-color: rgba(255, 255, 255, 0.42);
    background: rgba(13, 28, 24, 0.32);
    box-shadow: 0 8px 24px rgba(5, 15, 14, 0.16);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .scene-page .scene-selection-main {
    width: 100%;
    min-height: 100svh;
    height: 100svh;
    display: block;
    padding: 0;
  }

  .scene-page .scene-workspace {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0;
  }

  .scene-page .scene-workspace .scene-picker {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .scene-page .scene-track {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    border-radius: 0;
    background: #101816;
  }

  .scene-page .scene-card,
  .scene-page .scene-card[data-position="center"] {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    transform: none;
  }

  .scene-page .scene-card[data-position="center"] {
    z-index: 2;
    opacity: 1;
    filter: none;
  }

  .scene-page .scene-card:not([data-position="center"]) {
    z-index: 1;
    opacity: 0;
    pointer-events: none;
    transform: none;
  }

  .scene-page .scene-card-image,
  .scene-page .scene-card-video {
    width: 100%;
    height: 100%;
    transform: none;
  }

  .scene-page .scene-card-copy,
  .scene-page .scene-selected-mark {
    display: none;
  }

  .scene-page .scene-carousel-arrow {
    position: absolute;
    z-index: 8;
    top: 50%;
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-radius: 50%;
    background: rgba(8, 20, 18, 0.28);
    box-shadow: 0 8px 24px rgba(3, 10, 9, 0.18);
    color: rgba(255, 246, 232, 0.96);
    cursor: pointer;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 38px;
    line-height: 1;
    transform: translateY(-50%);
    transition: background 0.22s ease, border-color 0.22s ease, transform 0.22s ease;
    touch-action: manipulation;
  }

  .scene-page .scene-carousel-arrow--previous {
    left: max(10px, env(safe-area-inset-left));
  }

  .scene-page .scene-carousel-arrow--next {
    right: max(10px, env(safe-area-inset-right));
  }

  .scene-page .scene-carousel-arrow:active {
    border-color: rgba(255, 255, 255, 0.84);
    background: rgba(8, 20, 18, 0.5);
    transform: translateY(-50%) scale(0.94);
  }

  .scene-page .settings-rail {
    width: fit-content;
    min-width: 0;
    max-width: calc(100vw - 16px);
    min-height: 58px;
    max-height: none;
    align-self: end;
    justify-self: center;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 7px 12px max(7px, env(safe-area-inset-bottom));
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 28px 28px 0 0;
    scrollbar-width: none;
  }

  .scene-page .settings-rail::-webkit-scrollbar {
    display: none;
  }

  .scene-page .settings-rail-section,
  .scene-page .settings-icon-stack,
  .scene-page .settings-time-stack {
    width: auto;
    display: flex;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .scene-page .rail-divider {
    width: 1px;
    height: 30px;
    margin: 0 2px;
  }

  .scene-page .rail-option,
  .scene-page .rail-time,
  .scene-page .rail-enter-button {
    flex: 0 0 auto;
  }

  .scene-page .mobile-scene-enter {
    display: grid;
  }

  .scene-page .settings-rail .inline-setting-form {
    position: fixed;
    z-index: 35;
    top: auto;
    right: 50%;
    bottom: 68px;
    transform: translateX(50%);
  }
}

/* Focus room: retain only essential controls in the H5 landscape view. */
@media (max-width: 980px) and (max-height: 540px) and (orientation: landscape) {
  .study-room-page {
    overflow: hidden;
  }

  .study-room-page .site-header {
    position: fixed;
    z-index: 32;
    top: max(9px, env(safe-area-inset-top));
    right: 10px;
    left: auto;
    width: auto;
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .study-room-page .site-header > .brand,
  .study-room-page .site-header > .menu-toggle,
  .study-room-page .site-nav {
    display: none;
  }

  .study-room-page .site-header .navigation-shell {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .study-room-page .site-header .study-account-actions {
    display: flex;
    gap: 8px;
    padding: 0;
  }

  .study-room-page .focus-settings-button,
  .study-room-page .study-exit-button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 50%;
    background: rgba(10, 25, 22, 0.2);
  }

  .study-room-page .study-settings-panel {
    top: 58px;
    right: 10px;
    left: auto;
    width: min(280px, calc(100vw - 20px));
    max-height: calc(100svh - 68px);
  }

  .study-room-page .study-room-main {
    min-height: 100svh;
    display: block;
    padding: 0;
  }

  .study-room-page .timer-stage {
    position: fixed;
    z-index: 3;
    top: 50%;
    left: 50%;
    width: min(220px, 30vw);
    min-height: 128px;
    margin: 0;
    padding: 14px 12px;
    border-radius: 17px;
    transform: translate(-50%, -50%);
  }

  .study-room-page .timer-display {
    min-height: 50px;
    font-size: clamp(40px, 6vw, 52px);
  }

  .study-room-page .timer-progress {
    width: 126px;
  }

  .study-room-page .timer-controls {
    min-height: 38px;
    gap: 8px;
    margin-top: 10px;
  }

  .study-room-page .timer-control {
    width: 36px;
    height: 36px;
    min-height: 36px;
    font-size: 15px;
  }

  .study-room-page .todo-panel {
    position: fixed;
    z-index: 4;
    top: max(9px, env(safe-area-inset-top));
    left: 10px;
    width: min(172px, 22vw);
    max-height: 136px;
    margin: 0;
    padding: 8px;
    overflow: hidden;
    border-radius: 13px;
    background: rgba(8, 22, 19, 0.16);
  }

  .study-room-page .todo-heading {
    gap: 6px;
  }

  .study-room-page .todo-heading p {
    margin-bottom: 1px;
    font-size: 7px;
  }

  .study-room-page .todo-heading h2 {
    font-size: 15px;
  }

  .study-room-page .todo-heading > span {
    font-size: 8px;
  }

  .study-room-page .todo-form {
    grid-template-columns: minmax(0, 1fr) 25px;
    gap: 4px;
    margin-top: 7px;
  }

  .study-room-page .todo-form input {
    height: 26px;
    padding: 4px 7px;
    border-radius: 9px;
    font-size: 9px;
  }

  .study-room-page .todo-form button {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    font-size: 13px;
  }

  .study-room-page .todo-list {
    max-height: 58px;
    margin-top: 6px;
  }

  .study-room-page .todo-item {
    min-height: 25px;
    grid-template-columns: 13px minmax(0, 1fr) 16px;
    gap: 4px;
  }

  .study-room-page .todo-check {
    width: 12px;
    height: 12px;
  }

  .study-room-page .todo-text {
    font-size: 9px;
    line-height: 1.3;
  }

  .study-room-page .todo-remove {
    width: 16px;
    height: 16px;
    font-size: 11px;
  }

  .study-room-page .todo-empty {
    margin: 8px 0 0;
    font-size: 8px;
  }
}

/* Home: keep the H5 entry action compact and clear of the room status bar. */
@media (max-width: 980px) and (max-height: 540px) and (orientation: landscape) {
  .home-hero .primary-action {
    min-width: 142px;
    min-height: 43px;
    padding: 8px 18px;
    border-radius: 16px;
    font-size: 12px;
  }

  .home-hero .primary-action .button-arrow {
    font-size: 14px;
  }

  .home-hero .hero-actions {
    margin-top: 18px;
    margin-bottom: 4px;
  }
}

/* Portrait H5: keep section links inside a compact horizontal top drawer. */
@media (max-width: 600px) and (orientation: portrait) {
  .site-header {
    top: max(8px, env(safe-area-inset-top));
    left: 10px;
    right: 10px;
    min-height: 50px;
    padding: 6px 10px;
    border-radius: 16px;
  }

  .site-header .menu-toggle {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    display: grid;
    place-items: center;
    margin-left: auto;
    border-radius: 50%;
  }

  .site-header .account-actions:not(.study-account-actions) {
    display: none;
  }

  .site-header .navigation-shell {
    position: fixed;
    z-index: 25;
    top: calc(env(safe-area-inset-top) + 64px);
    left: 10px;
    right: 10px;
    display: block;
    min-width: 0;
    height: 46px;
    max-height: none;
    margin: 0;
    padding: 5px 8px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 28px rgba(3, 12, 10, 0.12);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-7px);
    transition: opacity 0.24s ease, visibility 0.24s ease, transform 0.24s ease;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .site-header.nav-open .navigation-shell {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
  }

  .site-header .site-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    height: 34px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .site-header .site-nav::-webkit-scrollbar {
    display: none;
  }

  .site-header .site-nav a,
  .site-header .site-nav a:last-child {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 5px 8px;
    border-radius: 9px;
    font-size: 10px;
    line-height: 1;
    white-space: nowrap;
  }

  .site-header .navigation-shell .account-actions:not(.study-account-actions) {
    display: none;
  }
}

/* Portrait scene picker: make the carousel the visual focus and dock controls below it. */
@media (max-width: 600px) and (orientation: portrait) {
  .scene-page .scene-selection-copy,
  .scene-page .scene-confirmation {
    display: none;
  }

  .scene-page .scene-selection-main {
    min-height: 100svh;
    display: flex;
    align-items: center;
    padding: calc(70px + env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
  }

  .scene-page .scene-workspace {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-content: center;
    gap: 10px;
  }

  .scene-page .scene-workspace .scene-picker {
    width: 100%;
    min-width: 0;
  }

  .scene-page .scene-track {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .scene-page .scene-card {
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border: 1px solid rgba(255, 246, 232, 0.7);
    border-radius: 20px;
    box-shadow: 0 10px 26px rgba(7, 20, 18, 0.24);
  }

  .scene-page .settings-rail {
    position: relative;
    width: 100%;
    min-width: 0;
    min-height: 58px;
    max-height: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 7px;
    margin: 0;
    padding: 8px 56px 8px 10px;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 18px;
    scrollbar-width: none;
  }

  .scene-page .settings-rail::-webkit-scrollbar {
    display: none;
  }

  .scene-page .settings-rail-section,
  .scene-page .settings-icon-stack,
  .scene-page .settings-time-stack {
    width: auto;
    display: flex;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .scene-page .rail-divider {
    width: 1px;
    height: 28px;
    flex: 0 0 1px;
    margin: 0 2px;
  }

  .scene-page .mobile-scene-enter {
    position: absolute;
    z-index: 3;
    top: 50%;
    right: 8px;
    width: 38px;
    height: 38px;
    display: grid;
    min-height: 38px;
    background: rgba(10, 25, 22, 0.58);
    box-shadow: -8px 0 16px rgba(8, 22, 19, 0.3);
    transform: translateY(-50%);
  }

  .scene-page .settings-rail .inline-setting-form {
    position: fixed;
    z-index: 35;
    right: 10px;
    bottom: max(82px, env(safe-area-inset-bottom));
  }
}

/* Portrait focus room: center a compact timer and keep tasks unobtrusive. */
@media (max-width: 600px) and (orientation: portrait) {
  .study-room-page {
    overflow: hidden;
  }

  .study-room-page .study-room-main {
    min-height: 100svh;
    display: block;
    padding: 0;
  }

  .study-room-page .timer-stage {
    position: fixed;
    z-index: 3;
    top: 50%;
    left: 50%;
    width: min(180px, calc(100vw - 44px));
    min-height: 166px;
    margin: 0;
    padding: 14px 12px;
    border-radius: 18px;
    transform: translate(-50%, -50%);
  }

  .study-room-page .timer-display {
    min-height: 48px;
    font-size: clamp(40px, 11vw, 46px);
  }

  .study-room-page .timer-progress {
    width: 122px;
  }

  .study-room-page .timer-controls {
    min-height: 40px;
    gap: 9px;
    margin-top: 10px;
  }

  .study-room-page .timer-control {
    width: 38px;
    height: 38px;
    min-height: 38px;
    font-size: 16px;
  }

  .study-room-page .todo-panel {
    position: fixed;
    z-index: 4;
    top: calc(env(safe-area-inset-top) + 68px);
    left: 10px;
    width: 136px;
    max-height: 126px;
    margin: 0;
    padding: 9px;
    overflow: hidden;
    border-radius: 14px;
    background: rgba(8, 22, 19, 0.16);
  }

  .study-room-page .todo-heading {
    gap: 5px;
  }

  .study-room-page .todo-heading p {
    margin-bottom: 1px;
    font-size: 8px;
  }

  .study-room-page .todo-heading h2 {
    font-size: 16px;
  }

  .study-room-page .todo-heading > span {
    font-size: 9px;
  }

  .study-room-page .todo-form {
    grid-template-columns: minmax(0, 1fr) 27px;
    gap: 4px;
    margin-top: 7px;
  }

  .study-room-page .todo-form input {
    height: 27px;
    padding: 4px 7px;
    border-radius: 9px;
    font-size: 10px;
  }

  .study-room-page .todo-form button {
    width: 27px;
    height: 27px;
    border-radius: 50%;
    font-size: 14px;
  }

  .study-room-page .todo-list {
    max-height: 48px;
    margin-top: 6px;
  }

  .study-room-page .todo-item {
    min-height: 24px;
    grid-template-columns: 13px minmax(0, 1fr) 16px;
    gap: 4px;
  }

  .study-room-page .todo-check {
    width: 12px;
    height: 12px;
  }

  .study-room-page .todo-text {
    font-size: 10px;
    line-height: 1.3;
  }

  .study-room-page .todo-remove {
    width: 16px;
    height: 16px;
    font-size: 11px;
  }

  .study-room-page .todo-empty {
    margin: 8px 0 0;
    font-size: 9px;
  }
}

.mobile-community-stack {
  display: none;
}

/* Portrait My Study: compact the goal form and keep every panel in one vertical flow. */
@media (max-width: 600px) and (orientation: portrait) {
  .my-study-page .page-shell,
  .my-study-page .learning-main {
    width: 100%;
    max-width: none;
  }

  .my-study-page .learning-main {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 88px 12px 32px;
  }

  .my-study-page .learning-main > .learning-intro,
  .my-study-page .learning-main > .learning-profile-panel,
  .my-study-page .learning-main > .learning-calendar-panel,
  .my-study-page .learning-main > .learning-day-panel,
  .my-study-page .learning-main > .learning-posts-panel {
    width: 100%;
    margin: 0;
  }

  .my-study-page .learning-profile-panel {
    padding: 12px;
  }

  .my-study-page .learning-profile-panel .learning-goal-form {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    margin-top: 12px;
  }

  .my-study-page .learning-profile-panel .learning-goal-form label {
    gap: 5px;
  }

  .my-study-page .learning-profile-panel .learning-goal-form label > span {
    font-size: 10px;
    line-height: 1.35;
  }

  .my-study-page .learning-profile-panel .learning-goal-form input,
  .my-study-page .learning-profile-panel .learning-goal-form button {
    min-height: 36px;
  }

  .my-study-page .learning-profile-panel .learning-goal-form button {
    width: auto;
    padding-inline: 12px;
  }

  .my-study-page .learning-profile-panel .learning-goal-status {
    grid-column: 1 / -1;
    min-height: 0;
    font-size: 10px;
    line-height: 1.25;
  }

  .my-study-page .learning-profile-panel .learning-tags-block {
    gap: 6px;
    margin-top: 10px;
  }

  .my-study-page .learning-profile-panel .learning-tag {
    min-height: 23px;
    padding: 2px 8px;
    font-size: 10px;
  }
}

/* Portrait community: composer first, followed by three full-width content sections. */
@media (max-width: 600px) and (orientation: portrait) {
  .community-page {
    overflow-y: auto;
  }

  .community-page .community-main {
    width: 100%;
    padding: 70px 0 30px;
  }

  .community-page .community-intro,
  .community-page .community-category-bar,
  .community-page .community-feed {
    display: none;
  }

  .community-page .community-workspace {
    width: 100%;
    border-radius: 0;
  }

  .community-page .community-toolbar {
    padding: 14px 10px;
  }

  .community-page .community-body {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 20px;
  }

  .community-page .publish-panel,
  .community-page .publish-panel.is-fixed {
    position: static;
    order: 1;
    width: 100%;
    min-width: 0;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 16px 10px;
    border: 0;
    border-radius: 0;
  }

  .community-page .mobile-community-stack {
    order: 2;
    width: 100%;
    min-width: 0;
    display: grid;
    gap: 20px;
  }

  .community-page .mobile-community-section {
    width: 100%;
    min-width: 0;
    padding: 0 10px;
  }

  .community-page .mobile-community-section-heading {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-height: 30px;
    margin-bottom: 10px;
  }

  .community-page .mobile-community-section-heading p,
  .community-page .mobile-community-section-heading h2 {
    margin: 0;
  }

  .community-page .mobile-community-section-heading p {
    color: rgba(255, 246, 232, 0.52);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 9px;
    letter-spacing: 0.08em;
  }

  .community-page .mobile-community-section-heading h2 {
    color: var(--warm-text);
    font-family: "STKaiti", "KaiTi", serif;
    font-size: 20px;
    font-weight: 500;
  }

  .community-page .mobile-community-section .post-list {
    width: 100%;
  }
}
