/* Match DigiPrep Design Tokens from biolessonstyles.css */
:root {
    --bg-main: #121212;
    --bg-content: #1e1e1e;
    --bg-header: #333;
    --text-color: #ffffff;
    --accent-red: #a81f2a;
    --accent-green: #0a6820;
    --accent-blue: #2563eb;
    --sidebar-bg: #1e1e1e;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Open Sans', sans-serif;
}

html,
body {
    height: 100%;
    width: 100%;
    background-color: var(--bg-main);
    color: var(--text-color);
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

/* Main Area Layout - Flex child */
.app-layout {
    flex: 1;
    display: flex;
    background-color: var(--bg-main);
    overflow: hidden;
}

/* Common Sidebar Styles */
.sidebar-section {
    width: 250px;
    background-color: var(--bg-main);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-controls {
    flex: 4 1 0;
    min-height: 0;
    overflow-y: auto;
    padding: 8px 12px;
}

/* Hide tools scrollbar when thumb would cover >70% of the panel (little overflow) */
.sidebar-controls.scrollbar-suppressed {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar-controls.scrollbar-suppressed::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

/* Custom Scrollbars - Matching biolessonstyles.css */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: #aaa;
}

.ad-container {
    flex: 5 1 0;
    min-height: 0;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.ad-placeholder {
    flex: 1;
    border: 1px dashed #3a3a3c;
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    color: #636366;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.side-left {
    border-right: 1px solid #333;
}

.side-right {
    border-left: 1px solid #333;
}

#right-sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    /* Override .sidebar-section 250px — marking panel needs 280 / 368 */
    width: 280px;
    transition: width 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

#right-sidebar.rs-marking-active {
    width: 368px;
}

.right-sidebar-marking-host {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#dp-bug-report-slot {
    flex-shrink: 0;
}

/* ═══ Self-marking sidebar (v2 Oct/Nov 2024) ═══ */
#right-sidebar-marking-host.rs-sidebar-host {
    --rs-surface: #151516;
    --rs-elevated: #1a1a1c;
    --rs-line: rgba(255, 255, 255, 0.07);
    --rs-muted: #8e8e93;
    --rs-fg: #f2f2f7;
    --rs-accent: #6ea8fe;
    --rs-accent-soft: rgba(110, 168, 254, 0.16);
    --rs-good: #34c759;
    --rs-warn: #ffd60a;
    --rs-bad: #ff453a;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    background: var(--bg-main);
}

.rs-root {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    outline: none;
    color: var(--rs-fg);
    font-size: 13px;
    line-height: 1.45;
}

.rs-toolbar {
    flex-shrink: 0;
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--rs-line);
    background: linear-gradient(180deg, rgba(30, 30, 32, 0.95), rgba(22, 22, 24, 0.6));
}

.rs-toolbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.rs-toolbar-label {
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--rs-muted);
}

.rs-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    background: transparent;
    color: var(--rs-fg);
    cursor: pointer;
    padding: 4px 0;
    font: inherit;
}

.rs-toggle-track {
    width: 34px;
    height: 18px;
    border-radius: 999px;
    background: #2c2c2e;
    border: 1px solid var(--rs-line);
    position: relative;
    transition: background 0.22s ease, border-color 0.22s ease;
}

.rs-toggle[aria-pressed='true'] .rs-toggle-track {
    background: var(--rs-accent-soft);
    border-color: rgba(110, 168, 254, 0.45);
}

.rs-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #f2f2f7;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.rs-toggle[aria-pressed='true'] .rs-toggle-thumb {
    transform: translateX(16px);
    background: var(--rs-accent);
}

.rs-toggle-text {
    font-size: 0.78rem;
    font-weight: 600;
    color: #d1d1d6;
}

.rs-toolbar-hint {
    margin-top: 8px;
    font-size: 0.72rem;
    color: var(--rs-muted);
    font-weight: 400;
}

#right-sidebar-marking-host.rs-sidebar-host.rs-marking-active .rs-toolbar-hint {
    display: none;
}

.rs-panels {
    flex: 1;
    min-height: 0;
    position: relative;
}

.rs-panel {
    position: absolute;
    inset: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0 2px 12px;
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.26s ease, transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    scrollbar-gutter: stable;
}

.rs-panel.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(10px);
}

.rs-panel--marking {
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
}

.rs-passive-inner {
    padding: 12px 10px 16px;
}

.rs-resource-card {
    display: block;
    padding: 10px 11px;
    border-radius: 10px;
    background: var(--rs-surface);
    border: 1px solid var(--rs-line);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.rs-resource-card:hover {
    border-color: rgba(110, 168, 254, 0.35);
    background: #1e1e21;
}

.rs-resource-card--quiet {
    opacity: 0.92;
}

.rs-resource-kicker {
    display: block;
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--rs-muted);
    margin-bottom: 4px;
}

.rs-resource-title {
    display: block;
    font-size: 0.84rem;
    font-weight: 600;
    margin-bottom: 3px;
}

.rs-resource-meta {
    font-size: 0.68rem;
    color: var(--rs-muted);
}

/* Marking workspace */
.rs-sticky {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 12px 11px 11px;
    margin: 0 2px;
    border-bottom: 1px solid var(--rs-line);
    background: rgba(21, 21, 22, 0.82);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.rs-head-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.rs-score {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.rs-grade-reveal-block:not([hidden]) {
    margin-top: 10px;
}

.rs-grade-blended {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--rs-accent-soft);
    border: 1px solid rgba(110, 168, 254, 0.38);
}

.rs-grade-prefix {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--rs-fg);
    opacity: 0.88;
}

.rs-grade-value {
    display: inline-block;
    font-size: 1.55rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
    color: #b8d4ff;
    text-shadow: 0 0 20px rgba(110, 168, 254, 0.35);
}

.rs-motivate {
    margin-top: 10px;
    padding: 10px 12px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--rs-fg);
    line-height: 1.45;
    background: rgba(255, 255, 255, 0.07);
    border-left: 3px solid var(--rs-warn);
    border-radius: 0 8px 8px 0;
}

/* Duolingo-style grade reveal */
.rs-sticky.rs-sticky--grade-reveal {
    animation: rs-grade-header-glow 0.82s cubic-bezier(0.22, 1, 0.36, 1);
}

.rs-grade-row-reveal {
    animation: rs-grade-row-in 0.48s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.rs-grade-value--pop {
    animation: rs-grade-letter-pop 0.68s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.rs-motivate--reveal {
    animation: rs-tier-hint-in 0.58s cubic-bezier(0.22, 1, 0.36, 1) 0.26s both;
}

@keyframes rs-grade-header-glow {
    0% {
        box-shadow: inset 0 0 0 0 rgba(88, 204, 2, 0);
    }
    38% {
        box-shadow: inset 0 0 28px rgba(88, 204, 2, 0.12);
    }
    100% {
        box-shadow: inset 0 0 0 0 rgba(88, 204, 2, 0);
    }
}

@keyframes rs-grade-row-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes rs-grade-letter-pop {
    0% {
        opacity: 0;
        transform: scale(0.25) rotate(-12deg);
    }
    48% {
        opacity: 1;
        transform: scale(1.22) rotate(4deg);
        color: #7ee85a;
    }
    68% {
        transform: scale(0.92) rotate(-2deg);
        color: #b8d4ff;
    }
    82% {
        transform: scale(1.06) rotate(1deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0);
        color: #b8d4ff;
    }
}

@keyframes rs-tier-hint-in {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.96);
    }
    55% {
        opacity: 1;
        transform: translateY(-2px) scale(1.01);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .rs-sticky.rs-sticky--grade-reveal,
    .rs-grade-row-reveal,
    .rs-grade-value--pop,
    .rs-motivate--reveal {
        animation: none !important;
    }
}

.rs-show-grade-wrap {
    margin-top: 14px;
    padding-top: 4px;
}

.rs-show-grade {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(110, 168, 254, 0.35);
    background: rgba(110, 168, 254, 0.12);
    color: var(--rs-accent);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.rs-show-grade:hover {
    border-color: rgba(110, 168, 254, 0.52);
    background: rgba(110, 168, 254, 0.18);
}

.rs-stack {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 10px 8px 14px;
}

.rs-kbd-hint {
    flex-shrink: 0;
    padding: 8px 11px 11px;
    font-size: 0.62rem;
    color: #48484a;
    letter-spacing: 0.02em;
    border-top: 1px solid var(--rs-line);
}

.rs-q {
    border-radius: 10px;
    border: 1px solid var(--rs-line);
    background: var(--rs-surface);
    margin-bottom: 8px;
    overflow: clip;
    transition: border-color 0.2s ease, box-shadow 0.22s ease;
}

.rs-q.is-expanded {
    border-color: rgba(110, 168, 254, 0.28);
    box-shadow: 0 0 0 1px rgba(110, 168, 254, 0.06);
}

.rs-q-head {
    width: 100%;
    display: block;
    text-align: left;
    padding: 9px 10px;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font: inherit;
}

.rs-q-head:focus-visible {
    outline: 2px solid var(--rs-accent);
    outline-offset: -2px;
}

.rs-q-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.rs-q-head-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.rs-q-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rs-q-status {
    font-size: 0.72rem;
    width: 1.25rem;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.rs-q-label {
    font-weight: 600;
    font-size: 0.82rem;
}

.rs-q-score {
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    color: var(--rs-muted);
    flex-shrink: 0;
}

.rs-q-title {
    font-weight: 600;
    font-size: 0.82rem;
}

.rs-tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    padding-left: 1.55rem;
}

.rs-tag {
    font-size: 0.58rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    color: #9a9aa0;
    border: 1px solid rgba(255, 255, 255, 0.06);
    letter-spacing: 0.02em;
}

.rs-tag--link {
    cursor: pointer;
    color: #c9d7ef;
    text-decoration: none;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.rs-tag--link:hover,
.rs-tag--link:focus-visible {
    background: rgba(96, 165, 250, 0.18);
    border-color: rgba(96, 165, 250, 0.5);
    color: #eaf2ff;
}

.rs-syllabus-warning-row,
.rs-tree-syllabus-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
    padding-left: 1.55rem;
}

.rs-tree-syllabus-row {
    padding-left: calc(1.55rem + (var(--rs-depth, 0) * 14px));
}

.rs-syllabus-warning {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    width: fit-content;
    max-width: 100%;
    padding: 4px 6px;
    border-radius: 6px;
    background: rgba(245, 158, 11, 0.11);
    border: 1px solid rgba(245, 158, 11, 0.34);
    color: #f9d38b;
    font-size: 0.58rem;
    line-height: 1.35;
}

.rs-syllabus-warning__badge {
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.rs-syllabus-warning__topic {
    color: #ffe7b5;
}

.rs-syllabus-warning__message {
    flex-basis: 100%;
    color: #d7c3a1;
}

.rs-q-body {
    padding: 0 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.rs-mark-panel {
    margin-top: 10px;
}

.rs-awarded-row {
    margin-top: 10px;
    text-align: right;
    font-size: 0.72rem;
    color: var(--rs-muted);
    font-variant-numeric: tabular-nums;
}

.rs-resources-panel {
    margin-top: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.rs-resources-label {
    display: block;
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--rs-muted);
    margin: 0;
    width: 100%;
}

.rs-resources-empty {
    font-size: 0.68rem;
    color: #636366;
}

.rs-ms-heading {
    font-size: 0.84rem;
    font-weight: 600;
    margin-top: 10px;
}

.rs-ms-sub {
    font-size: 0.68rem;
    color: var(--rs-muted);
    margin: 4px 0 10px;
}

.rs-stem {
    font-size: 0.76rem;
    line-height: 1.45;
    color: #dddde3;
    max-height: 10.5rem;
    overflow-y: auto;
    padding-right: 4px;
}

.rs-mcq-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin-top: 10px;
}

.rs-choice {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--rs-line);
    background: #1f2023;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.rs-choice:hover {
    border-color: rgba(110, 168, 254, 0.28);
    background: #242529;
}

.rs-choice.is-selected {
    border-color: rgba(110, 168, 254, 0.42);
}

.rs-choice.is-correct-sel {
    border-color: rgba(52, 199, 89, 0.55);
    background: rgba(52, 199, 89, 0.06);
}

.rs-choice.is-wrong-sel {
    border-color: rgba(255, 69, 58, 0.35);
    background: rgba(255, 69, 58, 0.05);
}

.rs-choice-letter {
    flex-shrink: 0;
    width: 1rem;
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--rs-accent);
}

.rs-choice-copy {
    flex: 1;
    font-size: 0.73rem;
    line-height: 1.38;
    color: #d8d8dc;
}

.rs-choice:focus-visible {
    outline: 2px solid var(--rs-accent);
    outline-offset: 1px;
}

.rs-choice.rs-hit {
    position: relative;
    overflow: hidden;
}

.rs-choice.rs-hit::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    pointer-events: none;
    background: linear-gradient(
        105deg,
        transparent 40%,
        rgba(110, 168, 254, 0.35) 50%,
        transparent 60%
    );
    opacity: 0;
    animation: rs-glow-sweep var(--rs-hit-ms, 160ms) ease-out forwards;
}

.rs-choice.rs-hit .rs-choice-letter {
    animation: rs-check-pop var(--rs-hit-ms, 160ms) cubic-bezier(0.22, 1, 0.36, 1);
}

.rs-mark-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.rs-mark-row {
    --rs-hit-ms: 160ms;
    position: relative;
    border-radius: 7px;
    margin-bottom: 4px;
    overflow: hidden;
}

.rs-mark-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 7px 8px;
    cursor: pointer;
    border-radius: 7px;
    transition: background 0.15s ease;
}

.rs-mark-row:hover .rs-mark-label {
    background: rgba(255, 255, 255, 0.03);
}

.rs-mark-row.is-checked .rs-mark-label {
    background: rgba(52, 199, 89, 0.07);
}

.rs-checkbox {
    appearance: none;
    width: 15px;
    height: 15px;
    margin-top: 2px;
    flex-shrink: 0;
    border-radius: 4px;
    border: 1px solid #48484a;
    background: #2c2c2e;
    transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.rs-checkbox:checked {
    border-color: var(--rs-good);
    background: rgba(52, 199, 89, 0.25);
    box-shadow: inset 0 0 0 2px var(--rs-good);
}

.rs-checkbox:focus-visible {
    outline: 2px solid var(--rs-accent);
    outline-offset: 1px;
}

.rs-mark-copy {
    flex: 1;
    font-size: 0.78rem;
    color: #e5e5ea;
}

.rs-mark-weight {
    font-size: 0.68rem;
    color: var(--rs-muted);
    font-variant-numeric: tabular-nums;
}

/* Reward sweep */
.rs-mark-row.rs-hit::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 7px;
    pointer-events: none;
    background: linear-gradient(
        105deg,
        transparent 40%,
        rgba(110, 168, 254, 0.35) 50%,
        transparent 60%
    );
    opacity: 0;
    animation: rs-glow-sweep var(--rs-hit-ms) ease-out forwards;
}

@keyframes rs-glow-sweep {
    0% {
        opacity: 0;
        transform: translateX(-30%);
    }
    35% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translateX(40%);
    }
}

.rs-mark-row.rs-hit .rs-checkbox:checked {
    animation: rs-check-pop var(--rs-hit-ms) cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rs-check-pop {
    40% {
        transform: scale(1.08);
    }
    100% {
        transform: scale(1);
    }
}

.rs-q-actions {
    margin-top: 10px;
}

.rs-chip {
    font-size: 0.68rem;
    padding: 5px 9px;
    border-radius: 6px;
    border: 1px solid var(--rs-line);
    background: #242426;
    color: #aeaeb2;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.rs-chip.is-on {
    border-color: rgba(255, 214, 10, 0.45);
    background: rgba(255, 214, 10, 0.1);
    color: #ffd60a;
}

.rs-video {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    font-size: 0.74rem;
    color: var(--rs-accent);
    text-decoration: none;
    opacity: 0.92;
}

.rs-video:hover {
    opacity: 1;
    text-decoration: underline;
}

.rs-celebrate {
    animation: rs-celebrate 0.62s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rs-celebrate {
    0% {
        box-shadow: 0 0 0 0 rgba(110, 168, 254, 0);
    }
    35% {
        border-color: rgba(110, 168, 254, 0.55);
        box-shadow: 0 0 24px rgba(110, 168, 254, 0.22);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(110, 168, 254, 0);
    }
}

.rs-q-status.is-ok {
    color: var(--rs-good);
}
.rs-q-status.is-review {
    color: var(--rs-warn);
}
.rs-q-status.is-pending {
    color: #ff6b6b;
}


/* Sidebar Groups */
.sidebar-group {
    margin-bottom: 8px;
}

.group-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: #636366;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

/* Stopwatch Card */
.stopwatch-card {
    background-color: #1c1c1e;
    border-radius: 10px;
    padding: 8px;
    text-align: center;
    border: 1px solid #2c2c2e;
    transition: all 0.3s ease;
}

.stopwatch-card.running {
    border-color: var(--accent-blue);
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.2);
}

#stopwatch-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.6rem;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 4px;
    letter-spacing: 1px;
}

.stopwatch-controls {
    display: flex;
    gap: 6px;
}

.stopwatch-controls button {
    flex: 1;
    padding: 4px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    font-size: 0.75rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

#start-stop-btn {
    background-color: #008a5e;
    color: white;
}

#reset-btn {
    background-color: #3a3a3c;
    color: #ffffff;
}

.stopwatch-controls button:hover {
    opacity: 0.9;
}

/* Tool Grid */
.tool-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

.tool-btn {
    padding: 6px;
    background-color: #2c2c2e;
    border: 1px solid #3a3a3c;
    color: #8e8e93;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn .material-symbols-outlined {
    font-size: 1.25rem;
    font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
    transition: all 0.2s ease;
}

.tool-btn.active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

#tool-eraser {
    grid-column: span 2;
}

.tool-btn:hover {
    background-color: #3a3a3c;
    color: #ffffff;
}

.tool-btn.active {
    background-color: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

/* Color Row */
.color-row {
    display: flex;
    justify-content: space-between;
    padding: 0 2px;
    margin-bottom: 6px;
}

.swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
}

.swatch.active {
    border-color: #ffffff;
    transform: scale(1.1);
}

/* History Grid */
.history-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

.history-grid button {
    padding: 6px;
    background-color: #2c2c2e;
    border: 1px solid #3a3a3c;
    color: #ffffff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-grid button .material-symbols-outlined {
    font-size: 1.25rem;
    font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
    transition: all 0.2s ease;
}

.history-grid button:active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.history-grid button:hover {
    background-color: #3a3a3c;
}

/* PDF Viewer Section */
.viewer-section {
    flex: 1;
    min-height: 0;
    position: relative;
    background-color: #262626;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    scrollbar-gutter: stable;
}

#pdf-render-target {
    width: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

/* Page Container & Overlay */
.page-container {
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    background: white;
    margin-bottom: 10px;
}

.annotation-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: all;
}

.annotation-layer-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* Cursors */
.cursor-pen {
    cursor: crosshair;
}

.cursor-text {
    cursor: text;
}

.cursor-table {
    cursor: cell;
}

.cursor-select {
    cursor: default;
}

.cursor-eraser {
    cursor: url('https://img.icons8.com/ios-filled/20/000000/eraser.png') 10 10, auto;
}

/* Lasso Box */
.lasso-box {
    position: fixed;
    border: 1px dashed var(--accent-blue);
    background: rgba(37, 99, 235, 0.1);
    pointer-events: none;
    z-index: 10000;
}

/* Text Editor & Annotation */
.text-editor,
.text-annotation {
    position: absolute;
    background: transparent !important;
    color: black;
    padding: 4px;
    outline: none;
    font-family: 'Open Sans', sans-serif;
    line-height: 1.55;
    box-sizing: border-box;
    min-width: 0;
    overflow-x: hidden;
    overflow-wrap: break-word;
    word-break: normal;
    white-space: pre-wrap;
    z-index: 20;
}

.text-editor {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    border: 2px dashed #007AFF;
    border-radius: 4px;
    z-index: 2000;
}

.text-annotation.selected {
    outline: 2px solid var(--accent-blue);
}

/* Table Logic */
.table-container {
    position: absolute;
    background: transparent !important;
    border: 1px solid #000;
    z-index: 20;
}

.table-container table {
    border-collapse: collapse;
    width: 100%;
    height: 100%;
    background: transparent !important;
}

.table-container td {
    border: 1px solid #000;
    padding: 8px 4px;
    min-height: 40px;
    background: transparent !important;
}

.table-container.selected {
    outline: 2px solid var(--accent-blue);
}

/* ── Table Row/Col Adjustors ── */
.table-adj {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 3px;
    background: #1e1e1e;
    border: 1px solid #444;
    border-radius: 20px;
    padding: 2px 6px;
    z-index: 100;
    pointer-events: all;
    user-select: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Row adjustor: centred on top edge */
.table-adj-row {
    top: 0;
    left: 50%;
    transform: translate(-50%, -130%);
    flex-direction: row;
}

/* Col adjustor: centred on left edge */
.table-adj-col {
    left: 0;
    top: 50%;
    transform: translate(-130%, -50%);
    flex-direction: column;
}

.table-adj span {
    font-size: 10px;
    color: #aaa;
    min-width: 18px;
    text-align: center;
}

.adj-btn {
    width: 18px;
    height: 18px;
    background: #333;
    border: 1px solid #555;
    color: #eee;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.adj-btn:hover {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

/* ── Group Selection Box ── */
.group-box {
    position: absolute;
    border: 2px dashed var(--accent-blue);
    background: rgba(37, 99, 235, 0.04);
    z-index: 50;
    cursor: move;
    pointer-events: all;
}

.group-resize-handle {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 12px;
    height: 12px;
    background: white;
    border: 2px solid var(--accent-blue);
    border-radius: 2px;
    cursor: se-resize;
}

.selection-delete-btn {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 28px;
    height: 28px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: #ff3b30;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
    pointer-events: all;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
    z-index: 2;
}

.selection-delete-btn:hover {
    background: #d70015;
}

/* iPad scroll rail — visual affordance in the existing PDF/right-sidebar margin (no layout change). */
@media (hover: none) and (pointer: coarse) {
    html.is-ipad-annotator .viewer-section {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    html.is-ipad-annotator .ipad-scroll-rail {
        position: fixed;
        z-index: 90;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-between;
        padding: 14px 0;
        box-sizing: border-box;
        user-select: none;
        -webkit-user-select: none;
        pointer-events: none;
        background:
            linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.035)),
            linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0%, rgba(255, 255, 255, 0.01) 18%, rgba(255, 255, 255, 0.01) 82%, rgba(255, 255, 255, 0.04) 100%);
        border-left: 1px solid rgba(255, 255, 255, 0.12);
        box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.25);
    }

    html.is-ipad-annotator .ipad-scroll-rail__arrow {
        font-size: 1.35rem;
        font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
        color: rgba(255, 255, 255, 0.42);
        line-height: 1;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    }

    html.is-ipad-annotator .ipad-scroll-rail__track {
        flex: 1;
        min-height: 48px;
        margin: 6px 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: space-evenly;
        overflow: hidden;
        opacity: 0.7;
    }

    html.is-ipad-annotator .ipad-scroll-rail__chevron {
        font-size: 1rem;
        font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 20;
        color: rgba(255, 255, 255, 0.32);
        line-height: 1;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    }

    html.is-ipad-annotator.is-ipad-stylus-mode .viewer-section {
        touch-action: pan-y;
    }

    html.is-ipad-annotator.is-ipad-stylus-mode .annotation-layer {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: pan-y;
    }

    html.is-ipad-annotator.is-ipad-stylus-mode .page-container canvas {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
        touch-action: none;
        pointer-events: none;
    }

    html.is-ipad-annotator.is-ipad-stylus-mode .text-editor {
        -webkit-user-select: text;
        user-select: text;
        touch-action: manipulation;
    }

    html.is-ipad-annotator.is-ipad-stylus-mode .ipad-input-toggle,
    html.is-ipad-annotator.is-ipad-stylus-mode #right-sidebar,
    html.is-ipad-annotator.is-ipad-stylus-mode #left-sidebar {
        touch-action: manipulation;
    }

    /* Prevent iOS sticky :hover from phantom mouse traversing the layout. */
    html.is-ipad-annotator .tool-btn:hover,
    html.is-ipad-annotator .swatch:hover,
    html.is-ipad-annotator .history-grid button:hover,
    html.is-ipad-annotator .stopwatch-controls button:hover {
        background-color: #2c2c2e;
        color: #8e8e93;
    }

    html.is-ipad-annotator .tool-btn.active:hover {
        background-color: #2563eb;
        color: #ffffff;
    }

    html.is-ipad-annotator.is-ipad-finger-mode .page-container,
    html.is-ipad-annotator.is-ipad-finger-mode .annotation-layer {
        touch-action: none;
    }

    html.is-ipad-annotator .viewer-section::-webkit-scrollbar {
        width: 10px;
    }

    html.is-ipad-annotator .viewer-section::-webkit-scrollbar-thumb {
        background-color: rgba(255, 255, 255, 0.35);
        border-radius: 10px;
    }
}

/* iPad landscape annotator layout. Desktop sizing intentionally stays unchanged. */
@media (orientation: landscape) and (pointer: coarse) {
    html.is-ipad-annotator .ipad-input-toggle {
        position: sticky;
        bottom: 18px;
        align-self: flex-end;
        z-index: 2000;
        margin: -74px 18px 18px 0;
        min-width: 150px;
        min-height: 54px;
        border: 1px solid rgba(255, 255, 255, 0.18);
        border-radius: 999px;
        background: rgba(18, 18, 18, 0.88);
        color: #ffffff;
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        cursor: pointer;
        touch-action: manipulation;
        user-select: none;
    }

    html.is-ipad-annotator .ipad-input-toggle.is-finger-mode {
        background: rgba(37, 99, 235, 0.92);
        border-color: rgba(255, 255, 255, 0.28);
    }

    html.is-ipad-annotator .ipad-input-toggle__label {
        font-size: 0.84rem;
        font-weight: 800;
        line-height: 1;
    }

    html.is-ipad-annotator .ipad-input-toggle__hint {
        color: rgba(255, 255, 255, 0.72);
        font-size: 0.68rem;
        font-weight: 600;
        line-height: 1;
    }

    html.is-ipad-annotator .tool-grid {
        gap: 8px;
    }

    html.is-ipad-annotator .tool-btn,
    html.is-ipad-annotator .history-grid button,
    html.is-ipad-annotator .stopwatch-controls button {
        min-height: 42px;
        padding: 9px;
    }

    html.is-ipad-annotator .tool-btn .material-symbols-outlined,
    html.is-ipad-annotator .history-grid button .material-symbols-outlined {
        font-size: 1.45rem;
    }

    html.is-ipad-annotator .color-row {
        gap: 10px;
        justify-content: flex-start;
    }

    html.is-ipad-annotator .swatch {
        width: 34px;
        height: 34px;
    }

    html.is-ipad-annotator .table-adj {
        gap: 6px;
        padding: 5px 9px;
    }

    html.is-ipad-annotator .adj-btn {
        width: 30px;
        height: 30px;
        font-size: 18px;
    }

    html.is-ipad-annotator .group-resize-handle {
        bottom: -10px;
        right: -10px;
        width: 24px;
        height: 24px;
    }

    html.is-ipad-annotator .selection-delete-btn {
        top: -20px;
        right: -20px;
        width: 40px;
        height: 40px;
        font-size: 28px;
    }
}
