/* Home follows the shared shell's activation class, including touch landscape.
   Every existing-panel override is scoped to this mobile Home presentation. */
.home-mobile {
    display: none;
}

.als-mobile-shell .dashboard.home-mobile-ready {
    display: block;
    padding: 16px 12px;
}

.als-mobile-shell .home-mobile-ready > section {
    display: none;
}

.als-mobile-shell .home-mobile {
    display: block;
    width: min(100%, 760px);
    margin: 0 auto;
}

.als-mobile-shell .home-mobile [hidden],
.als-mobile-shell .home-mobile-dialog [hidden] {
    display: none !important;
}

.als-mobile-shell .home-mobile-heading {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.25rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-intro {
    margin: 6px 0 16px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
}

.als-mobile-shell .home-mobile-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "level goals" "xp quests" "why control" "personalization personalization";
    gap: 10px;
}

.als-mobile-shell .home-mobile-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    min-width: 0;
    min-height: 150px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    background: linear-gradient(140deg, var(--panel-light), var(--panel));
    text-align: left;
    font: inherit;
    line-height: 1.4;
    cursor: pointer;
    touch-action: manipulation;
}

.als-mobile-shell .home-mobile-card:hover {
    background: var(--panel-hover);
    border-color: var(--accent-bright);
}

.als-mobile-shell .home-mobile-card:disabled {
    opacity: 0.7;
    cursor: wait;
}

.als-mobile-shell .home-mobile :focus-visible,
.als-mobile-shell .home-mobile-dialog :focus-visible {
    outline: 2px solid var(--accent-bright);
    outline-offset: 3px;
}

.als-mobile-shell .home-mobile-card-level { grid-area: level; }
.als-mobile-shell .home-mobile-card-goals { grid-area: goals; }
.als-mobile-shell .home-mobile-card-xp { grid-area: xp; }
.als-mobile-shell .home-mobile-card-quests { grid-area: quests; }
.als-mobile-shell .home-mobile-card-why { grid-area: why; }
.als-mobile-shell .home-mobile-card-control { grid-area: control; }
.als-mobile-shell .home-mobile-card-personalization { grid-area: personalization; }

.als-mobile-shell .home-mobile-card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 6px;
}

.als-mobile-shell .home-mobile-card-label {
    color: var(--accent-bright);
    font-size: 0.8125rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-card-arrow {
    flex: none;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1;
}

.als-mobile-shell .home-mobile-card-value {
    display: block;
    color: var(--text-primary);
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-card-summary {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.als-mobile-shell :is(.home-mobile-card-why, .home-mobile-card-control, .home-mobile-card-personalization) .home-mobile-card-value {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.45;
}

.als-mobile-shell .home-mobile-card-personalization {
    min-height: 132px;
}

.als-mobile-shell .home-mobile-card-personalization .home-mobile-card-value {
    font-size: 1.125rem;
    font-weight: 600;
    -webkit-line-clamp: 2;
}

.als-mobile-shell .home-mobile-meter {
    height: 5px;
    margin-top: auto;
    overflow: hidden;
    background: rgba(141, 232, 255, 0.12);
    border-radius: 99px;
}

.als-mobile-shell .home-mobile-meter-fill {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: inherit;
}

/* The native dialog is the overlay; one large sheet sits at its bottom edge. */
.home-mobile-dialog:not([open]) { display: none; }

html.als-mobile-root.home-detail-open {
    height: 100svh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
}

html.home-detail-open > body.als-mobile-shell {
    position: fixed;
    top: var(--home-overview-offset);
    width: 100%;
}

.als-mobile-shell .home-mobile-dialog[open] {
    --home-viewport-height: 100svh;
    --home-usable-height: calc(var(--home-viewport-height) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    position: fixed;
    inset: 0;
    display: grid;
    align-items: end;
    justify-items: center;
    width: 100%;
    height: var(--home-viewport-height);
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    color: var(--text-primary);
    background: transparent;
    overscroll-behavior: none;
}

@supports (height: 100dvh) {
    .als-mobile-shell .home-mobile-dialog[open] { --home-viewport-height: 100dvh; }
}

.als-mobile-shell .home-mobile-dialog::backdrop {
    background: rgba(0, 4, 10, 0.72);
    animation: home-detail-dim 160ms ease-out;
}

.als-mobile-shell .home-mobile-sheet {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(100%, 760px);
    height: calc(var(--home-usable-height) * 0.88 + env(safe-area-inset-bottom, 0px));
    max-height: calc(var(--home-viewport-height) - env(safe-area-inset-top, 0px) - 44px);
    min-height: 0;
    padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    overflow: hidden;
    border: 1px solid var(--border-bright);
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
    background: linear-gradient(145deg, var(--panel-light), var(--background-secondary)), var(--background-secondary);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
    animation: home-detail-enter 160ms ease-out;
}

.als-mobile-shell .home-mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--soft-white-line);
}

.als-mobile-shell .home-mobile-sheet-close {
    flex: none;
    min-width: 44px;
    min-height: 44px;
    padding: 8px;
    color: var(--accent-bright);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
}

.als-mobile-shell .home-mobile-sheet-close:hover { background: var(--panel-hover); }

.als-mobile-shell .home-mobile-sheet-content {
    min-width: 0;
    min-height: 0;
    padding: 16px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.als-mobile-shell .home-mobile-dialog.is-closing .home-mobile-sheet {
    animation: home-detail-exit 160ms ease-in forwards;
}

.als-mobile-shell .home-mobile-dialog.is-closing::backdrop {
    animation: home-detail-dim 160ms ease-in reverse forwards;
}

@keyframes home-detail-enter {
    from { transform: translateY(24px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes home-detail-exit {
    from { transform: translateY(0); opacity: 1; }
    to { transform: translateY(24px); opacity: 0; }
}

@keyframes home-detail-dim {
    from { background: rgba(0, 4, 10, 0); }
    to { background: rgba(0, 4, 10, 0.72); }
}

@media (prefers-reduced-motion: reduce) {
    .als-mobile-shell .home-mobile-dialog .home-mobile-sheet,
    .als-mobile-shell .home-mobile-dialog::backdrop,
    .als-mobile-shell .home-mobile-dialog.is-closing .home-mobile-sheet,
    .als-mobile-shell .home-mobile-dialog.is-closing::backdrop { animation: none; }
}

/* Reflow the original Home panels only while mounted in the detail sheet. */
.als-mobile-shell .home-mobile-panel-host > .system-panel {
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 14px;
    overflow: visible;
    border-radius: 12px;
    box-shadow: none;
}

.als-mobile-shell .home-mobile-panel-host > .system-panel::before,
.als-mobile-shell .home-mobile-panel-host > .system-panel::after {
    display: none;
}

.als-mobile-shell .home-mobile-panel-host .panel-heading {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 12px;
}

.als-mobile-shell .home-mobile-panel-host :is(.panel-label, .panel-value, .quest-reset) {
    font-size: 0.75rem;
    line-height: 1.5;
    letter-spacing: 0.04em;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-panel-host :is(.goal-list, .quest-list, .personalization-list, .personalization-layout, .level-content) {
    height: auto;
    min-height: 0;
    overflow: visible;
}

.als-mobile-shell .home-mobile-panel-host :is(.goal-list, .quest-list) {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.als-mobile-shell .home-mobile-panel-host :is(.goal-card-button, .quest-item) {
    flex: none;
    min-height: 60px;
    padding: 12px;
    gap: 10px;
    border-radius: 8px;
}

.als-mobile-shell .home-mobile-panel-host .goal-card-button {
    grid-template-columns: minmax(0, 1fr) auto;
}

.als-mobile-shell .home-mobile-panel-host .goal-number {
    display: none;
}

.als-mobile-shell .home-mobile-panel-host :is(.goal-content h2, .quest-copy strong) {
    font-size: 1rem;
    line-height: 1.4;
}

.als-mobile-shell .home-mobile-panel-host :is(.goal-content h2, .goal-content p, .quest-copy strong, .quest-copy small) {
    display: block;
    overflow: visible;
    white-space: normal;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-panel-host :is(.goal-content p, .quest-copy small, .goal-percent, .quest-xp) {
    font-size: 0.8125rem;
    line-height: 1.5;
}

.als-mobile-shell .home-mobile-panel-host .quest-item {
    grid-template-columns: 22px minmax(0, 1fr);
}

.als-mobile-shell .home-mobile-panel-host .custom-checkbox {
    width: 22px;
    height: 22px;
}

.als-mobile-shell .home-mobile-panel-host .quest-xp {
    grid-column: 2;
}

.als-mobile-shell .home-mobile-panel-host .quest-item:focus-within {
    outline: 2px solid var(--accent-bright);
    outline-offset: 2px;
}

.als-mobile-shell .home-mobile-panel-host :is(.muted-text, .panel-note, .reason-text) {
    display: block;
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-panel-host .reason-text {
    white-space: pre-wrap;
}

.als-mobile-shell .home-mobile-panel-host .level-content {
    flex-wrap: wrap;
    gap: 16px;
}

.als-mobile-shell .home-mobile-panel-host .level-details h1 {
    font-size: 1.25rem;
}

.als-mobile-shell .home-mobile-panel-host .level-details .eyebrow {
    font-size: 0.75rem;
}

.als-mobile-shell .home-mobile-panel-host .personalization-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
}

.als-mobile-shell .home-mobile-panel-host .image-stub {
    justify-self: center;
    width: 128px;
    min-height: 128px;
    padding: 12px;
    font-size: 0.75rem;
}

.als-mobile-shell .home-mobile-panel-host .personalization-row {
    display: grid;
    gap: 6px;
    padding: 12px 0;
    font-size: 0.8125rem;
}

.als-mobile-shell .home-mobile-panel-host .personalization-row strong {
    font-size: 0.9375rem;
    line-height: 1.5;
    letter-spacing: normal;
    text-transform: none;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-panel-host :is(.panel-action, .text-button) {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 0.8125rem;
    line-height: 1.4;
    white-space: normal;
}

.als-mobile-shell .home-mobile-panel-host .running-counter-button {
    height: auto;
    min-height: 160px;
    grid-template-rows: auto auto auto;
    gap: 8px;
    padding: 12px 0;
}

.als-mobile-shell .home-mobile-panel-host .running-counter-title {
    font-size: 1rem;
    line-height: 1.5;
    white-space: normal;
    overflow-wrap: anywhere;
}

.als-mobile-shell .home-mobile-panel-host :is(.running-counter-elapsed, .running-counter-units) {
    width: 100%;
    margin: 0;
}

.als-mobile-shell .home-mobile-panel-host .running-counter-elapsed {
    font-size: clamp(1rem, 7cqw, 1.5rem);
}

.als-mobile-shell .home-mobile-panel-host :is(.running-counter-edit, .running-counter-resets) {
    position: static;
    display: block;
    margin: 12px 0 0;
    font-size: 0.8125rem;
}

/* Existing Home editors: touch sizing and dynamic viewport bounds only. */
body.als-mobile-shell[data-page="home"] .home-modal {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

body.als-mobile-shell[data-page="home"] .home-modal-card {
    width: min(620px, 100%);
    max-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
    padding: 16px;
    border-radius: 12px;
}

body.als-mobile-shell[data-page="home"] .home-modal :is(button, input, select) {
    min-width: 44px;
    min-height: 44px;
}

body.als-mobile-shell[data-page="home"] .home-modal :is(input, textarea, select) {
    font-size: 1rem;
}

body.als-mobile-shell[data-page="home"] .home-modal :is(.home-form-field, button) {
    font-size: 0.875rem;
}

body.als-mobile-shell[data-page="home"] .home-modal :is(.home-modal-actions, .home-modal-action-group) {
    flex-wrap: wrap;
}

body.als-mobile-shell[data-page="home"] .home-modal :focus-visible {
    outline: 2px solid var(--accent-bright);
    outline-offset: 2px;
}
