:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --card-bg: rgba(255, 255, 255, 0.05);
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --highlight: rgba(99, 102, 241, 0.4);
    --success: #10b981;
    --circle-color: #10b981;
    --glow-color: #eab308;
    --font-main: 'Inter', sans-serif;
    --font-heading: 'Outfit', sans-serif;
    --modal-bg: #1e293b;
    --bg-color: #0f172a;
    --border-color: rgba(255,255,255,0.1);
    --error: #ef4444;
}

body.theme-light {
    --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --card-bg: rgba(0, 0, 0, 0.05);
    --text: #0f172a;
    --text-muted: #475569;
    --modal-bg: #ffffff;
    --bg-color: #f1f5f9;
    --border-color: rgba(0,0,0,0.12);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    overflow-y: auto;
}

body.modal-open {
    overflow: hidden;
}

.app-container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

.title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

h1 {
    font-family: var(--font-heading);
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #818cf8, #c084fc);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.pub-info-area {
    position: relative;
    width: 100%;
    margin-top: -12px;
    margin-bottom: 4px;
    min-height: 1.4rem;
}

.pub-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    transition: opacity 0.3s;
}

.status-message {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s;
    color: var(--text);
    border-radius: 6px;
    padding: 2px 8px;
    white-space: nowrap;
}

.status-message.visible {
    opacity: 1;
}

.status-message.success { color: #10b981; }
.status-message.error   { color: #ef4444; }
.status-message.info    { color: var(--primary); }

.actions {
    display: flex;
    gap: 8px;
}

.btn svg {
    vertical-align: middle;
    margin-right: 4px;
}

/* Timer */
.timer-block {
    display: flex;
    align-items: center;
    gap: 8px;
}

.timer-display {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    min-width: 58px;
}

.btn-pause {
    background: var(--primary);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all 0.2s;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

.btn-pause:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

/* Paused blur */
.paused-blur {
    filter: blur(14px) brightness(0.5);
    pointer-events: none;
    user-select: none;
    transition: filter 0.3s;
}

/* Shared game banner */
.shared-banner {
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.35);
    border-radius: 12px;
    padding: 14px 18px;
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.7;
}

.shared-banner strong {
    color: var(--text);
}

.shared-banner .badge {
    display: inline-block;
    background: rgba(99, 102, 241, 0.25);
    color: #818cf8;
    border-radius: 6px;
    padding: 1px 7px;
    font-size: 0.78rem;
    font-weight: 700;
    margin-left: 4px;
}

.shared-banner .badge.warn {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

.btn {
    padding: 10px 18px;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-main);
    font-size: 1rem;
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    line-height: 1;
}

.btn-primary,

.btn-primary:hover,

.btn-secondary,
#btn-scan,
#btn-mag-reset {
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

.btn-secondary:hover,
#btn-scan:hover,
#btn-mag-reset:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    color: white;
}

.btn-secondary:active,
#btn-scan:active,
#btn-mag-reset:active {
    background: var(--primary-hover);
    transform: translateY(0);
}

.grid-container {
    position: relative;
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    aspect-ratio: 1 / 1;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 6px;
    user-select: none;
    touch-action: none;
    max-width: 450px;
    margin: 0 auto;
}

.cell {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(12px, 4vw, 18px);
    /* Larger on small screens */
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    transition: transform 0.1s;
    position: relative;
    z-index: 2;
}

.cell.active {
    color: #fff;
    font-weight: 700;
    text-shadow: 0 0 10px var(--primary);
}

.selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

#pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(14px);
    z-index: 10;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 32px;
    border-radius: 16px;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

#pause-overlay.visible {
    display: flex;
}

#pause-btn-slot {
    pointer-events: auto;
}

#pause-btn-slot .btn-pause {
    pointer-events: auto;
    touch-action: auto;
    width: 64px;
    height: 64px;
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.45);
}

.pause-message {
    font-family: var(--font-heading);
    font-size: 3.5rem;
    color: white;
    font-weight: 900;
    letter-spacing: 0.15em;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    user-select: none;
    animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        opacity: 0.9;
    }

    50% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(0.95);
        opacity: 0.9;
    }
}

.selection-line {
    position: absolute;
    background: var(--highlight);
    border-radius: 999px;
    transform-origin: center center;
    pointer-events: none;
    transition: width 0.05s linear;
    transform: translate(-50%, -50%) rotate(var(--angle, 0deg));
}

.circles-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.circle {
    position: absolute;
    border: 2px solid var(--circle-color);
    border-radius: 999px;
    background: var(--found-circle);
    transform-origin: center center;
    pointer-events: none;
    transform: translate(-50%, -50%) rotate(var(--angle, 0deg)) scale(var(--scale, 1));
    animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes pop {
    0% {
        opacity: 0;
        --scale: 0;
    }

    100% {
        opacity: 1;
        --scale: 1;
    }
}

@property --scale {
    syntax: '<number>';
    initial-value: 1;
    inherits: true;
}

.word-list-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.list-container {
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    padding-bottom: 4px;
}

.list-container:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.list-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    list-style: none;
    padding: 4px 0 10px;
    user-select: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 0;
}

/* Hide default triangle across browsers */
.list-heading::-webkit-details-marker {
    display: none;
}

.list-heading::marker {
    display: none;
}

.list-heading h3 {
    font-family: var(--font-heading);
    color: var(--text);
    font-size: 1.1rem;
    margin: 0;
    flex: 1;
}

/* Chevron arrow */
.list-heading::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-right: 2px;
}

details[open]>.list-heading::before {
    transform: rotate(-135deg);
}

.list-count {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.07);
    border-radius: 20px;
    padding: 1px 8px;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.word-list-scroll {
    max-height: 180px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 2px 6px;
}

.word-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
}

.word-item {
    font-size: 0.9rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    /* Changed from space-between */
}

.word-item:hover {
    color: var(--text);
}

.word-item.found {
    /* Removed decoration */
    color: var(--text-muted);
}

.btn-undo {
    display: none;
    background: rgba(220, 38, 38, 0.1);
    color: #ef4444;
    border: none;
    border-radius: 4px;
    width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    margin-left: 4px;
    /* Reduced margin to be close to word */
    line-height: 1;
    flex-shrink: 0;
}

.word-item:hover .btn-undo {
    display: block;
}

.btn-undo:hover {
    background: #ef4444;
    color: white;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--modal-bg);
    padding: 30px;
    border-radius: 24px;
    text-align: center;
    min-width: 250px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

.btn-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.btn-menu {
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.2);
}

.btn-menu:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

/* Heatmap Hint */
.cell.hint {
    background: radial-gradient(circle, var(--glow-color-alpha, rgba(234,179,8,0.4)) 0%, transparent 70%);
    animation: pulse 0.8s infinite alternate;
}

.solved-content h2 {
    font-size: 3rem;
    margin-bottom: 10px;
    color: var(--success);
    font-family: var(--font-heading);
}

.remaining-letters {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin: 20px 0;
    letter-spacing: 0.1em;
    word-break: break-all;
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 12px;
}

/* Camera Overlay */
.camera-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

.camera-overlay.visible {
    pointer-events: auto;
}

.camera-container {
    position: relative;
    width: 90vw;
    height: 90vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: #000;
}

#video,
#selection-canvas {
    position: absolute;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.camera-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
}

.camera-controls.no-fade {
    background: none;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.btn-icon {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 24px;
    cursor: pointer;
    z-index: 2010;
}

.scan-instruction {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 20px;
    border-radius: 99px;
    font-size: 0.9rem;
    font-weight: 500;
}

.main-controls {
    display: flex;
    gap: 15px;
}

@media (max-width: 480px) {
    .grid-container {
        padding: 2px;
        border-radius: 8px;
    }

    .app-container {
        padding: 10px;
        gap: 16px;
    }

    h1 {
        font-size: 2rem;
    }

    .btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
}

@media (min-width: 800px) {
    .app-container {
        max-width: 900px;
    }

    main {
        display: flex;
        gap: 32px;
        align-items: flex-start;
    }

    .grid-container {
        flex: 0 0 450px;
        margin: 0;
    }

    .word-list-section {
        flex: 1;
        min-width: 220px;
        max-height: calc(100vh - 180px);
        overflow-y: auto;
        position: sticky;
        top: 20px;
        /* Thin custom scrollbar */
        scrollbar-width: thin;
        scrollbar-color: rgba(99,102,241,0.4) transparent;
    }

    /* Fully expand word lists on desktop — no truncation */
    .word-list-scroll {
        max-height: none;
        overflow: visible;
    }

    /* Hide the chevron toggle — lists are always open on desktop */
    .list-heading {
        cursor: default;
        pointer-events: none;
    }
    .list-heading::before {
        display: none;
    }
}

/* Puzzles Tree styles */
.puzzles-content {
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
}

.puzzles-content h2 {
    color: var(--text);
    margin-bottom: 15px;
    text-align: center;
}

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

.pub-expander {
    margin: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.pub-header {
    color: var(--primary);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    padding: 6px 0;
    outline: none;
    display: flex;
    align-items: center;
    gap: 10px;
    list-style: none;
    /* Remove default arrow */
}

.pub-header::-webkit-details-marker {
    display: none;
    /* Remove default arrow Chrome/Safari */
}

.pub-header::before {
    content: '\25B8';
    /* Right pointing small triangle */
    font-size: 0.8rem;
    transition: transform 0.2s;
    width: 1em;
    display: inline-block;
    text-align: center;
}

details[open] .pub-header::before {
    transform: rotate(90deg);
}

.pub-header:hover {
    color: var(--primary-hover);
}

.pub-expander ul {
    list-style: none;
    padding-left: 15px;
    margin-bottom: 10px;
}

.dt-node {
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 2px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.dt-node:hover {
    color: var(--text);
}

.dt-node-info {
    flex: 1;
}

.btn-delete-time {
    flex-shrink: 0;
    background: rgba(220, 38, 38, 0.1);
    color: #ef4444;
    border: 1px solid rgba(220, 38, 38, 0.25);
    border-radius: 4px;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    padding: 0;
}

.dt-node:hover .btn-delete-time {
    opacity: 1;
}

.btn-delete-time:hover {
    background: #ef4444;
    color: white;
}

/* Home Screen & Visibility Utilities */
.hidden-view {
    display: none !important;
}

.home-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    flex: 1;
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 300px;
}

.btn-large {
    padding: 16px 24px;
    font-size: 1.1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    border-radius: 14px;
}

/* Settings and Magnifier */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
}

.setting-row select,
.setting-row input[type="color"] {
    background: var(--card-bg);
    color: var(--text);
    border: 1px solid rgba(128, 128, 128, 0.2);
    padding: 8px;
    border-radius: 6px;
    font-family: var(--font-main);
}

.setting-row label {
    font-size: 0.95rem;
    font-weight: 600;
}

.magnifier {
    position: fixed;
    width: 170px;
    height: 170px;
    border-radius: 50%;
    border: 3px solid var(--text);
    overflow: hidden;
    background: var(--bg-gradient);
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.magnifier-inner {
    position: absolute;
    transform-origin: top left;
    /* Transformation initialized via JS */
}

/* Settings Sliders */
input[type="range"] {
    accent-color: var(--primary);
    cursor: pointer;
}

/* Interactive Preview Zone */
.mag-preview-zone {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
    margin: 10px 0;
    cursor: crosshair;
    border: 1px dashed rgba(255, 255, 255, 0.2);
}

.mag-preview-finger {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
    z-index: 2;
}

.mag-preview-lens {
    position: absolute;
    border: 2px solid #fff;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#mag-preview-text {
    font-weight: bold;
    color: #fff;
    font-size: 14px;
}

.feedback-response {
    margin-top: 10px;
    font-size: 0.9rem;
    padding: 10px;
    border-radius: 8px;
    display: none;
}

.feedback-response.success {
    display: block;
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.feedback-response.error {
    display: block;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Hidden elements */
.hidden {
    display: none !important;
}

/* OCR progress ring */
.ocr-progress-ring {
    filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.6));
}

.ocr-progress-ring__track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 6;
}

.ocr-progress-ring__fill {
    fill: none;
    stroke: var(--primary);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 60 214;
    stroke-dashoffset: 0;
    transform-origin: 40px 40px;
    animation: ocr-ring-spin 1s linear infinite;
}

@keyframes ocr-ring-spin {
    to { transform: rotate(360deg); }
}

/* --- Grid Editor --- */
.editor-scroll-wrapper {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.editor-scroll-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 8px;
    /* On touch devices, add bottom padding so controls can scroll above the keyboard */
    padding-bottom: env(keyboard-inset-height, 50vh);
}

.editor-grid {
    display: grid;
    background: var(--card-bg);
    border-radius: 12px;
    padding: 4px;
    gap: 1px;
    min-width: min-content;
}

.editor-cell {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(11px, 3.5vw, 16px);
    color: var(--text);
    aspect-ratio: 1;
    min-width: 24px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    background: rgba(255, 255, 255, 0.04);
    user-select: none;
}

.editor-cell:hover {
    background: rgba(99, 102, 241, 0.15);
}

.editor-cell.selected {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
    z-index: 1;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

/* Drag handles for move-row mode */
.editor-drag-handles {
    display: none;
    grid-template-columns: 24px;
    gap: 1px;
    margin-right: 4px;
    padding: 4px 0; /* Match editor-grid padding */
}

.editor-drag-handles.active {
    display: grid;
}

.drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    color: var(--text-muted);
    font-size: 14px;
    user-select: none;
    border-radius: 4px;
    transition: background 0.15s;
    width: 24px;
    aspect-ratio: 1; /* Match cell aspect ratio */
}

.drag-handle:hover {
    background: rgba(99, 102, 241, 0.15);
    color: var(--text);
}

.drag-handle:active {
    cursor: grabbing;
}

.drag-handle.drag-over {
    background: rgba(99, 102, 241, 0.3);
    box-shadow: 0 -2px 0 var(--primary) inset;
}

/* Floating effect for the row being moved */

.row-dragging {
    opacity: 0.7;
    transform: scale(1.02) translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
    z-index: 10;
    background: rgba(99, 102, 241, 0.2) !important;
    position: relative;
}

/* Floating inline cell toolbar — fixed to viewport so it's never clipped by overflow containers */
.cell-toolbar-float {
    position: fixed;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
    padding: 7px 8px;
    background: var(--modal-bg);
    border: 1px solid rgba(99, 102, 241, 0.5);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
    z-index: 3100;
    pointer-events: all;
    white-space: nowrap;
    min-width: 180px;
    --arrow-left: 50%;
}

.cell-toolbar-float::before {
    content: '';
    position: absolute;
    top: -6px;
    left: var(--arrow-left);
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid rgba(99, 102, 241, 0.5);
}

.cell-toolbar-row {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

.btn-tool-shift {
    flex: 1;
    padding: 5px 6px;
    font-size: 0.78rem;
    text-align: center;
}

.btn-tool-nav {
    padding: 4px 8px;
    font-size: 0.78rem;
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.3);
}

.btn-tool-confirm {
    padding: 4px 10px;
    font-size: 1rem;
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.35);
}

.btn-tool-confirm:hover {
    background: rgba(16, 185, 129, 0.3);
}

.cell-edit-input {
    width: 40px;
    height: 36px;
    text-align: center;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 700;
    border: 2px solid var(--primary);
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.1);
    color: var(--text);
    text-transform: uppercase;
}

.btn-tool {
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-tool:hover {
    background: rgba(99, 102, 241, 0.2);
}

.btn-delete-word:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* Admin Controls */
.btn-admin-action {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    color: var(--text-muted);
    padding: 2px 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    font-weight: 600;
}

.btn-admin-action.approve {
    color: #10b981;
    border-color: rgba(16,185,129,0.3);
    background: rgba(16,185,129,0.1);
}

.btn-admin-action.approve:hover {
    background: rgba(16,185,129,0.2);
    transform: scale(1.1);
}

.btn-admin-action.delete {
    color: #ef4444;
    border-color: rgba(239,68,68,0.3);
    background: rgba(239,68,68,0.1);
}

.btn-admin-action.delete:hover {
    background: rgba(239,68,68,0.2);
    transform: scale(1.1);
}

.btn-tool:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.editor-size-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 15px;
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 600;
    flex-wrap: wrap;
}

.editor-size-row select {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text);
    font-family: var(--font-main);
    font-size: 0.95rem;
    cursor: pointer;
}

/* --- Word Correction UI --- */
.word-editor-header {
    padding: 15px 15px 5px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.word-editor-header h3 {
    margin: 0;
    color: var(--text);
    font-size: 1.1rem;
}

.word-correction-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
    align-content: start;
}

.word-editor-footer {
    padding: 10px 15px 15px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.word-count-row {
    padding: 5px 0 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

.add-word-module {
    margin-bottom: 15px;
}

.add-word-input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.add-word-input-group input {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--primary);
    background: var(--card-bg);
    color: var(--text);
    font-family: var(--font-main);
    text-transform: uppercase;
}

.add-word-actions {
    display: flex;
    gap: 4px;
}

.btn-icon-small {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    transition: opacity 0.2s;
}

.btn-icon-small.success {
    background: #10b981;
    color: white;
}

.btn-icon-small.danger {
    background: #ef4444;
    color: white;
}

.word-correction-item {
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.word-correction-item textarea {
    flex: 1;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text);
    font-family: var(--font-main);
    text-transform: uppercase;
    font-weight: 600;
    font-size: 0.9rem;
    min-width: 0;
    resize: none;
    line-height: 1.3;
    overflow: hidden;
}

.word-correction-item textarea.not-found {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
}

.btn-delete-word {
    width: 32px;
    height: 32px;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.editor-navigation {
    display: flex;
    gap: 10px;
}

.btn-small {
    padding: 8px 15px;
    font-size: 0.9rem;
}

/* Settings Color Picker Styling */
#highlight-color-picker {
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.1);
    transition: transform 0.2s;
}

#highlight-color-picker:hover {
    transform: scale(1.05);
    border-color: var(--primary);
}

#btn-mag-back:hover {
    color: var(--primary) !important;
    transform: translateX(-2px);
}

#btn-mag-back svg {
    transition: transform 0.2s;
}

#ocr-loading {
    display: none;
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 3000;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
}
#ocr-loading.active {
    display: flex !important;
}

/* Scan panel utility — replaces inline styles on scan overlay children */
.scan-panel {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--bg-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.scan-panel--2000 { z-index: 2000; }
.scan-panel--2100 { z-index: 2100; }
.scan-panel--2200 { z-index: 2200; overflow-y: auto; }
.scan-panel--padded { padding: 20px; }

/* editor-grid-area */
.editor-grid-area {
    display: flex;
    align-items: flex-start;
    position: relative;
}

/* editor-navigation variants */
.editor-navigation--padded { padding: 10px 15px; flex-shrink: 0; }
.editor-navigation--footer { margin-top: auto; padding: 20px 0; }

/* word-error-message */
.word-error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 10px 15px;
}
.word-error-message p {
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: center;
    color: var(--error);
}

/* Zoom container */
.zoom-container {
    display: none;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    background: rgba(0,0,0,0.3);
    margin-top: 10px;
}
.zoom-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Save-for-community card */
.save-card {
    background: rgba(255,255,255,0.03);
    padding: 20px;
    border-radius: 16px;
    margin-bottom: 25px;
    border: 1px solid rgba(255,255,255,0.05);
}
.save-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.save-field-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.save-field-row label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: 4px;
}
.save-field-row input {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.2);
    color: var(--text);
    font-family: var(--font-main);
}

/* Scan correction hint */
.scan-correction-hint {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(99,102,241,0.08);
    border-bottom: 1px solid rgba(99,102,241,0.15);
    text-align: center;
}

/* ── Scan preview pane ────────────────────────────────────────────────────── */
.scan-preview-pane {
    flex-shrink: 0;
    flex-grow: 0;
    height: 100px;
    overflow: auto;
    background: #000;
    -webkit-overflow-scrolling: touch;
}

.scan-preview-img {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    -webkit-user-drag: none;
    filter: brightness(1.15) contrast(1.05);
}

/* ── Resize handle ────────────────────────────────────────────────────────── */
.preview-resize-handle {
    flex-shrink: 0;
    height: 14px;
    background: var(--card-bg);
    border-top: 1px solid rgba(255,255,255,0.08);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
    touch-action: none;
    user-select: none;
    flex-shrink: 0;
}

.preview-resize-handle:hover {
    background: rgba(99,102,241,0.15);
}

.preview-resize-handle:active {
    background: rgba(99,102,241,0.25);
}

.preview-resize-grip {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.25);
}
