/* Focus mode — whole-page study shell. Mods off. Looks educational. */

/* Toggle */
.focus-toggle {
    display: inline-flex;
    gap: 10px;
    align-items: center;
    min-height: 44px;
    padding: 0 12px 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--ink);
    background: var(--paper);
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    transition:
        transform 220ms var(--ease-out),
        border-color 240ms var(--ease),
        background-color 240ms var(--ease),
        box-shadow 280ms var(--ease-soft),
        color 240ms var(--ease);
    animation: mastIn 640ms var(--ease-out) 80ms backwards;
}

.focus-toggle:hover {
    border-color: var(--ink);
    background: #FFF;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(23, 26, 32, 0.08);
}

.focus-toggle:active {
    transform: translateY(1px) scale(0.985);
}

.focus-toggle-label {
    line-height: 1;
}

.focus-toggle-track {
    position: relative;
    width: 36px;
    height: 22px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--ink) 12%, var(--bg-deep));
    transition: background-color 320ms var(--ease);
}

.focus-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--paper);
    box-shadow: 0 1px 3px rgba(23, 26, 32, 0.18);
    transition: transform 420ms var(--ease-out);
    will-change: transform;
}

.focus-toggle[aria-pressed="true"] {
    border-color: color-mix(in srgb, var(--accent) 45%, var(--line-strong));
    color: var(--accent-dark);
    background: color-mix(in srgb, var(--accent-soft) 70%, var(--paper));
}

.focus-toggle[aria-pressed="true"] .focus-toggle-track {
    background: var(--accent);
}

.focus-toggle[aria-pressed="true"] .focus-toggle-thumb {
    transform: translateX(14px);
}

.brand-games,
.brand-focus {
    display: flex;
    align-items: flex-end;
    gap: 0.18em;
}

.brand-focus {
    display: none;
    font-size: inherit;
    font-weight: 800;
    letter-spacing: -0.075em;
    line-height: 0.78;
    color: var(--ink);
}

/* Panes */
.portal-pane {
    display: none;
}

.portal-pane.is-active {
    display: block !important;
    animation: portalPaneIn 460ms var(--ease-out) both;
}

@keyframes portalPaneIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ========== Full-page Focus mode ========== */
body.is-focus {
    --bg: #F5F6F8;
    --bg-deep: #EBEEF2;
    --paper: #FFFFFF;
    --ink: #1A2332;
    --ink-soft: #334155;
    --mute: #64748B;
    --line: rgba(26, 35, 50, 0.1);
    --line-strong: rgba(26, 35, 50, 0.18);
    --accent: #2563EB;
    --accent-dark: #1D4ED8;
    --accent-soft: #E8EEFB;
    --glow-a: transparent;
    --glow-b: transparent;
    --stamp: transparent;
    color: var(--ink);
    background: var(--bg);
    color-scheme: light;
}

body.is-focus[data-focus-theme="dark"],
html[data-focus-theme="dark"] body.is-focus {
    --bg: #0F1419;
    --bg-deep: #161C24;
    --paper: #1A222D;
    --ink: #E8EEF6;
    --ink-soft: #C5D0DC;
    --mute: #8B98A8;
    --line: rgba(232, 238, 246, 0.1);
    --line-strong: rgba(232, 238, 246, 0.18);
    --accent: #5B8DEF;
    --accent-dark: #8BB0F5;
    --accent-soft: rgba(91, 141, 239, 0.16);
    color-scheme: dark;
}

.focus-theme-toggle {
    display: none;
    width: 44px;
    height: 44px;
    place-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--ink-soft);
    background: var(--paper);
    transition:
        transform 220ms var(--ease-out),
        border-color 240ms var(--ease),
        background-color 240ms var(--ease),
        color 240ms var(--ease);
}

body.is-focus .focus-theme-toggle:not([hidden]) {
    display: grid;
}

.focus-theme-toggle:hover {
    border-color: var(--line-strong);
    color: var(--ink);
    background: var(--bg-deep);
    transform: translateY(-1px);
}

.focus-theme-toggle:active {
    transform: translateY(1px) scale(0.985);
}

.focus-theme-toggle .focus-theme-ico {
    display: none;
    line-height: 0;
}

html[data-focus-theme="dark"] .focus-theme-toggle .focus-theme-ico-sun {
    display: block;
}

html:not([data-focus-theme="dark"]) .focus-theme-toggle .focus-theme-ico-moon {
    display: block;
}

html[data-focus-theme="dark"] body.is-focus .hw-tool:hover {
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
}

html[data-focus-theme="dark"] body.is-focus .hw-workspace {
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
}

body.is-focus::before {
    display: none;
}

body.is-focus .portal-fx,
body.is-focus .mod-layer {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

body.is-focus .brand-games {
    display: none;
}

body.is-focus .brand-focus {
    display: flex;
    animation: portalPaneIn 460ms var(--ease-out) both;
}

body.is-focus .brand {
    font-size: clamp(2.6rem, 5.5vw, 3.6rem);
    letter-spacing: -0.05em;
    line-height: 0.9;
}

body.is-focus .top {
    grid-template-areas: "brand actions";
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    margin-bottom: 22px;
    padding: 4px 0 20px;
    border-bottom-color: var(--line);
}

body.is-focus .home-search-wrap,
body.is-focus #libraryBtn,
body.is-focus #settingsBtn {
    display: none !important;
}

body.is-focus .focus-toggle {
    border-color: var(--line);
    color: var(--ink-soft);
    background: var(--paper);
    box-shadow: none;
}

body.is-focus .focus-toggle:hover {
    border-color: var(--line-strong);
    transform: none;
    box-shadow: none;
}

body.is-focus .app {
    padding-top: 28px;
    max-width: 880px;
    width: min(100%, 880px);
}

body.is-focus .section-title {
    font-size: clamp(1.7rem, 3.5vw, 2.1rem);
    font-weight: 750;
    letter-spacing: -0.035em;
}

body.is-focus .section-kicker {
    color: var(--mute);
    letter-spacing: 0.1em;
}

body.is-focus .hw-meta {
    max-width: 18ch;
    color: var(--mute);
    font-weight: 500;
}

/* Tools */
.hw-section {
    min-height: 48vh;
}

/* === multi-tool shell (patched) === */
.hw-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 360px;
}

.hw-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.hw-tool {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    min-height: 96px;
    padding: 18px 16px 18px 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--ink);
    background: var(--paper);
    text-align: left;
    transition:
        transform 280ms var(--ease-out),
        border-color 280ms var(--ease),
        background-color 280ms var(--ease),
        box-shadow 320ms var(--ease-soft),
        min-height 280ms var(--ease),
        padding 280ms var(--ease);
    animation: hwToolIn 520ms var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 55ms + 40ms);
}

@keyframes hwToolIn {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.hw-tool:hover {
    border-color: var(--line-strong);
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(26, 35, 50, 0.06);
}

.hw-tool:active {
    transform: translateY(0) scale(0.99);
}

.hw-tool.is-open {
    border-color: color-mix(in srgb, var(--accent) 55%, var(--line-strong));
    background: color-mix(in srgb, var(--accent-soft) 70%, var(--paper));
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.hw-tool-icon {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    border-radius: 12px;
    color: var(--accent-dark);
    background: var(--accent-soft);
    transition: transform 320ms var(--ease-out), width 280ms var(--ease), height 280ms var(--ease);
}

.hw-tool:hover .hw-tool-icon {
    transform: scale(1.05);
}

.hw-tool-copy {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.hw-tool-title {
    font-size: 1.05rem;
    font-weight: 750;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.hw-tool-desc {
    color: var(--mute);
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.35;
}

.hw-tool-arrow {
    display: grid;
    place-items: center;
    color: var(--mute);
    opacity: 0.45;
    transition:
        opacity 240ms var(--ease),
        transform 280ms var(--ease-out),
        color 240ms var(--ease);
}

.hw-tool:hover .hw-tool-arrow {
    color: var(--ink);
    opacity: 1;
    transform: translateX(3px);
}

/* Compact picker while panels are open */
.hw-shell.is-tool .hw-tools {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.hw-shell.is-tool .hw-tool {
    min-height: 58px;
    padding: 10px 12px;
    gap: 10px;
}

.hw-shell.is-tool .hw-tool-icon {
    width: 34px;
    height: 34px;
}

.hw-shell.is-tool .hw-tool-icon svg {
    width: 16px;
    height: 16px;
}

.hw-shell.is-tool .hw-tool-title {
    font-size: 0.92rem;
}

.hw-shell.is-tool .hw-tool-desc,
.hw-shell.is-tool .hw-tool-arrow {
    display: none;
}

.hw-workspace {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--paper);
    box-shadow: 0 12px 32px rgba(26, 35, 50, 0.05);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    max-height: 0;
    overflow: hidden;
    transition:
        opacity 320ms var(--ease-out),
        transform 360ms var(--ease-out),
        max-height 0ms linear 360ms;
}

.hw-shell.is-tool .hw-workspace {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    max-height: none;
    overflow: visible;
    transition:
        opacity 360ms var(--ease-out),
        transform 420ms var(--ease-out);
}

.hw-workspace-bar {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.hw-close-all {
    flex: 0 0 auto;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--ink);
    background: var(--paper);
    font-size: 0.78rem;
    font-weight: 700;
}

.hw-close-all:hover {
    border-color: var(--line-strong);
}

.hw-workspace-title-wrap {
    min-width: 0;
}

.hw-workspace-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 750;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.hw-workspace-body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    flex: 1;
    min-height: 0;
    max-height: none;
    padding: 12px;
    overflow: visible;
    mask-image: none;
}

.hw-workspace-body[data-open-count="2"],
.hw-workspace-body[data-open-count="3"],
.hw-workspace-body[data-open-count="4"],
.hw-workspace-body.is-multi {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
}

.hw-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 280px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: color-mix(in srgb, var(--bg-deep, #ebeef2) 35%, var(--paper));
    overflow: hidden;
    animation: hwPanelIn 420ms var(--ease-out) both;
}

.hw-panel[hidden] {
    display: none !important;
}

@keyframes hwPanelIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.hw-panel.is-focus {
    border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
}

.hw-panel-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
}

.hw-panel-title-wrap {
    min-width: 0;
}

.hw-panel-title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 750;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.hw-panel-close {
    flex: 0 0 auto;
    color: var(--mute);
}

.hw-panel-close:hover {
    color: var(--ink);
}

.hw-panel-body {
    flex: 1;
    min-height: 0;
    padding: 12px;
    overflow: auto;
    scrollbar-width: thin;
}

.hw-panel-body:has(#hwCalc),
.hw-panel-body:has(#hwStudyAi) {
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.hw-panel-body #hwCalc,
.hw-panel-body #hwStudyAi {
    flex: 1;
    min-height: 0;
}

.hw-workspace-body[data-open-count="1"] .hw-panel {
    min-height: min(62vh, 640px);
}

.hw-workspace-body.is-multi .hw-panel {
    min-height: min(56vh, 560px);
}

.hw-placeholder {
    display: grid;
    gap: 10px;
    justify-items: center;
    align-content: center;
    min-height: 200px;
    padding: 24px 12px;
    text-align: center;
    animation: hwPlaceholderIn 480ms var(--ease-out) 80ms both;
}

@keyframes hwPlaceholderIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.hw-placeholder-mark {
    width: 48px;
    height: 48px;
    margin-bottom: 6px;
    border-radius: 14px;
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 18%, transparent);
    animation: hwPulse 2.8s var(--ease-soft) infinite;
}

@keyframes hwPulse {
    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.04);
        opacity: 0.88;
    }
}

.hw-placeholder-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 750;
    letter-spacing: -0.025em;
}

.hw-placeholder-text {
    margin: 0;
    max-width: 36ch;
    color: var(--mute);
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.5;
}

/* Notes tool */
.hw-notes {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    min-height: 240px;
}

.hw-notes__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.hw-notes__meta {
    margin: 0;
    color: var(--mute);
    font-size: 0.78rem;
    font-weight: 600;
}

.hw-notes__clear {
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 0.74rem;
    font-weight: 700;
}

.hw-notes__input {
    flex: 1;
    min-height: 220px;
    width: 100%;
    resize: vertical;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--ink);
    background: var(--paper);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.5;
}

.hw-notes__input:focus {
    outline: none;
    border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

/* Timer tool */
.hw-timer {
    display: grid;
    gap: 14px;
    place-content: center;
    min-height: 240px;
    text-align: center;
    padding: 12px;
}

.hw-timer__label {
    margin: 0;
    color: var(--mute);
    font-size: 0.85rem;
    font-weight: 650;
}

.hw-timer__display {
    margin: 0;
    font-size: clamp(2.4rem, 8vw, 3.4rem);
    font-weight: 780;
    letter-spacing: -0.04em;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.hw-timer.is-running .hw-timer__display {
    color: var(--accent-dark);
}

.hw-timer__controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.hw-timer__mins {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    color: var(--mute);
    font-size: 0.78rem;
    font-weight: 650;
}

.hw-timer__mins input {
    width: 64px;
    min-height: 34px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: var(--paper);
    font: inherit;
    font-weight: 700;
}

.hw-timer__start,
.hw-timer__pause,
.hw-timer__reset {
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 700;
}

.hw-timer__start {
    border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
    color: var(--accent-dark);
    background: var(--accent-soft);
}

html[data-scheme="dark"] .focus-toggle:hover {
    background: var(--paper);
}

@media (max-width: 700px) {
    body.is-focus .brand {
        font-size: clamp(2.1rem, 10vw, 2.8rem);
    }

    body.is-focus .top {
        gap: 12px;
        margin-bottom: 18px;
        padding-bottom: 16px;
    }

    .focus-toggle-label {
        font-size: 0.82rem;
    }

    .hw-tools {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .hw-shell.is-tool .hw-tools {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .hw-tool {
        min-height: 84px;
        padding: 14px 12px 14px 14px;
    }

    .hw-tool-icon {
        width: 40px;
        height: 40px;
    }

    .hw-workspace-body,
    .hw-workspace-body.is-multi,
    .hw-workspace-body[data-open-count="2"],
    .hw-workspace-body[data-open-count="3"],
    .hw-workspace-body[data-open-count="4"] {
        grid-template-columns: 1fr;
        padding: 10px;
    }

    .hw-workspace-body[data-open-count="1"] .hw-panel,
    .hw-workspace-body.is-multi .hw-panel {
        min-height: min(58vh, 520px);
    }

    .hw-meta {
        max-width: 12ch;
    }
}

@media (prefers-reduced-motion: reduce) {
    .portal-pane.is-active,
    .hw-tool,
    .hw-panel,
    .hw-placeholder,
    .hw-placeholder-mark,
    .brand-focus,
    .focus-toggle {
        animation: none !important;
    }

    .focus-toggle-thumb,
    .hw-tool,
    .hw-tool-icon,
    .hw-tool-arrow,
    .hw-workspace,
    .hw-shell .hw-tools {
        transition: none !important;
    }
}
