/* ==========================================================================
   Doučebnice Whiteboard – Stylesheet
   ==========================================================================
   Branding barvy (přepište pro vlastní paletu Doučebnice):
     --c-primary       hlavní modrá
     --c-primary-dark  tmavší odstín
     --c-secondary     zelená / akcentová
     --c-accent        žlutá / oranžová
     --c-bg            pozadí stránky
     --c-surface       bílý povrch (toolbar, karty)
     --c-text          hlavní text
     --c-text-sec      sekundární text
   ========================================================================== */

:root {
    --c-primary: #033e78;
    --c-primary-dark: #022b55;
    --c-secondary: #ffd700;
    --c-accent: #ffd700;
    --c-bg: #f0f2f5;
    --c-surface: #ffffff;
    --c-text: #1f2937;
    --c-text-sec: #6b7280;
    --c-danger: #ef4444;
    --c-toolbar-shadow: 0 -2px 16px rgba(0, 0, 0, 0.1);
    --toolbar-h: 64px;
    --header-h: 52px;
    --radius: 12px;
}

/* ── Reset & base ─────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    background: var(--c-bg);
    color: var(--c-text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ── Header ───────────────────────────────────────────────────────── */
#app-header {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    right: 0;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--c-surface);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    z-index: 100;
}

#logo-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

#logo {
    height: 32px;
    width: auto;
}

#wb-name {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 1px solid transparent;
    background: transparent;
    font-size: 16px;
    font-weight: 700;
    color: var(--c-text);
    padding: 2px 12px;
    border-radius: 6px;
    width: 280px;
    text-align: center;
    outline: none;
    transition:
        border-color 0.15s,
        background 0.15s;
}
#wb-name:hover {
    background: rgba(0, 0, 0, 0.04);
}
#wb-name:focus {
    border-color: var(--c-primary);
    background: #fff;
}
#wb-name::placeholder {
    color: var(--c-text-sec);
    font-weight: 400;
}

#header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Connection status */
#connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--c-text-sec);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.connected {
    background: var(--c-secondary);
}
.status-dot.disconnected {
    background: var(--c-danger);
}

/* Room info */
#room-info {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--c-bg);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--c-text-sec);
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    color: var(--c-text-sec);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        color 0.15s,
        background 0.15s;
}
.icon-btn:hover {
    color: var(--c-primary);
    background: rgba(3, 62, 120, 0.1);
}

/* ── Teacher status banner ────────────────────────────────────────── */
#teacher-status {
    position: fixed;
    top: var(--header-h);
    left: 50%;
    transform: translateX(-50%);
    background: var(--c-accent);
    color: #fff;
    padding: 6px 20px;
    border-radius: 0 0 var(--radius) var(--radius);
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 90;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: opacity 0.3s;
}
#teacher-status.hidden {
    display: none;
}

.pulse-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff;
    animation: pulse 1.2s infinite;
}
@keyframes pulse {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(0.7);
    }
}

/* ── Canvas wrapper ───────────────────────────────────────────────── */
#canvas-wrapper {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: calc(var(--toolbar-h) + env(safe-area-inset-bottom, 0px));
    overflow: auto;
    background: var(--c-bg);
    touch-action: none;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
    contain: layout style;
}

#pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 20px;
    min-height: 100%;
    min-width: 100%;
    width: fit-content;
    box-sizing: border-box;
    will-change: transform;
}

/* ── Číslování stránek ──────────────────────────────────────────────── */
.page-wrap {
    position: relative;
}
.page-wrap::before {
    content: attr(data-page-num);
    position: absolute;
    top: 4px;
    left: -28px;
    font-size: 14px;
    color: #b0b0b0;
    font-weight: 600;
    pointer-events: none;
    user-select: none;
}

#btn-add-page {
    display: block;
    margin: 16px auto 32px;
    padding: 10px 24px;
    border: 2px dashed var(--c-primary);
    border-radius: 8px;
    background: transparent;
    color: var(--c-primary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.15s;
}
#btn-add-page:hover {
    background: rgba(3, 62, 120, 0.08);
}

/* Fabric.js vygeneruje wrapper .canvas-container – nastavíme border a shadow */
.canvas-container {
    border-radius: 4px;
    box-shadow: 0 2px 24px rgba(0, 0, 0, 0.12);
    touch-action: none;
    contain: strict;
}

/* ── Compass instruction overlay ──────────────────────────────────── */
#compass-instruction {
    position: fixed;
    bottom: calc(var(--toolbar-h) + 16px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--c-primary);
    color: #fff;
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 80;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(3, 62, 120, 0.3);
    transition: opacity 0.3s;
}
#compass-instruction.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ── Bottom Toolbar ───────────────────────────────────────────────── */
#toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--toolbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--c-surface);
    box-shadow: var(--c-toolbar-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    overflow: visible;
}

.toolbar-inner {
    display: flex;
    align-items: center;
    justify-content: safe center;
    gap: 4px;
    padding: 0 12px;
    height: 100%;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.toolbar-inner::-webkit-scrollbar {
    display: none;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.tool-separator {
    width: 1px;
    height: 32px;
    background: #e5e7eb;
    margin: 0 6px;
    flex-shrink: 0;
}

/* ── Tool button ──────────────────────────────────────────────────── */
.tool-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
    border-radius: 10px;
    background: var(--c-bg);
    cursor: pointer;
    font-size: 18px;
    color: var(--c-text);
    transition: all 0.15s ease;
    position: relative;
    touch-action: manipulation;
}
.tool-btn svg {
    pointer-events: none;
}

@media (hover: hover) {
    .tool-btn:hover {
        background: rgba(3, 62, 120, 0.1);
        border-color: var(--c-primary);
    }
}

.tool-btn.active {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary-dark);
    box-shadow: 0 2px 8px rgba(3, 62, 120, 0.35);
}
.tool-btn.active svg {
    stroke: #fff;
}

/* Teacher button special states */
#btn-teacher.active {
    background: var(--c-accent);
    color: var(--c-primary);
    border-color: #ccac00;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.4);
}
#btn-teacher.active svg {
    stroke: var(--c-primary);
}

/* ── Color swatches ──────────────────────────────────────────────── */
.color-swatches {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    touch-action: manipulation;
    transition:
        border-color 0.15s,
        transform 0.15s;
    padding: 0;
    outline: none;
    flex-shrink: 0;
}
.color-swatch:hover {
    transform: scale(1.15);
    border-color: rgba(0, 0, 0, 0.25);
}
.color-swatch.active {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 2px var(--c-primary);
    transform: scale(1.1);
}

/* ── Size indicator (dot inside cycling button) ──────────────────── */
.size-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

.size-dot {
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    transition:
        width 0.15s,
        height 0.15s;
}

/* ── Size button + popup ──────────────────────────────────────────── */
.size-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.size-btn {
    position: relative;
}

.size-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 9px;
    font-weight: 700;
    color: var(--c-primary);
    line-height: 1;
    pointer-events: none;
}

.size-popup {
    position: fixed;
    display: flex;
    align-items: center;
    gap: 2px;
    background: var(--c-surface);
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 4px 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 200;
    user-select: none;
}
.size-popup.hidden {
    display: none;
}

.size-popup-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.size-popup-btn:hover {
    background: rgba(3, 62, 120, 0.1);
}
.size-popup-btn:active {
    background: rgba(3, 62, 120, 0.2);
}

.size-popup-val {
    min-width: 28px;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
    color: var(--c-text);
}

/* ── Eraser mode popup ─────────────────────────────────────────────── */
.eraser-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.eraser-popup {
    position: fixed;
    display: flex;
    gap: 4px;
    background: var(--c-surface);
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 200;
}
.eraser-popup.hidden {
    display: none;
}

.eraser-mode-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border: 2px solid transparent;
    border-radius: 8px;
    background: var(--c-bg);
    cursor: pointer;
    touch-action: manipulation;
    font-size: 12px;
    font-weight: 500;
    color: var(--c-text);
    white-space: nowrap;
    transition: all 0.15s ease;
}
.eraser-mode-btn:hover {
    background: rgba(3, 62, 120, 0.08);
    border-color: var(--c-primary);
}
.eraser-mode-btn.active {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary-dark);
}
.eraser-mode-btn.active svg {
    stroke: #fff;
}
.eraser-mode-btn svg {
    pointer-events: none;
    flex-shrink: 0;
}

/* Eraser size controls inside popup */
.eraser-size-wrap {
    display: flex;
    align-items: center;
    gap: 2px;
    border-left: 1px solid #e5e7eb;
    padding-left: 4px;
    margin-left: 2px;
}
.eraser-size-wrap.hidden {
    display: none;
}

/* ── Zoom controls ─────────────────────────────────────────────────── */
.zoom-controls {
    gap: 4px;
}
#zoom-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--c-text-sec);
    min-width: 40px;
    text-align: center;
    user-select: none;
}

/* ── Utility ──────────────────────────────────────────────────────── */
.hidden {
    display: none !important;
}

/* ── Responsive (mobile) ──────────────────────────────────────────── */
@media (max-width: 720px) {
    :root {
        --toolbar-h: 56px;
        --header-h: 44px;
    }

    /* Header – compact */
    #app-header {
        padding: 0 8px;
    }

    #logo {
        height: 24px;
    }

    #wb-name {
        position: static;
        transform: none;
        width: 1px;
        flex: 1;
        min-width: 0;
        font-size: 14px;
        padding: 2px 8px;
        margin: 0 8px;
    }

    #header-right {
        gap: 8px;
    }

    #room-info {
        padding: 2px 6px;
        font-size: 11px;
    }

    #room-id {
        display: none;
    }

    /* Toolbar – tighter spacing on mobile */
    .toolbar-inner {
        justify-content: flex-start;
        gap: 2px;
        padding: 0 8px;
    }

    .tool-btn {
        width: 42px;
        height: 42px;
        font-size: 16px;
        border-radius: 8px;
        flex-shrink: 0;
    }

    .tool-separator {
        margin: 0 2px;
        height: 24px;
    }

    /* Canvas */
    #pages-container {
        padding: 8px;
        gap: 12px;
    }

    #btn-add-page {
        padding: 8px 16px;
        font-size: 13px;
        margin: 8px 0 16px;
    }

    /* Compass instruction */
    #compass-instruction {
        font-size: 12px;
        padding: 6px 14px;
    }
}

@media (max-width: 480px) {
    :root {
        --header-h: 40px;
    }

    #connection-status {
        display: none;
    }

    #room-info {
        padding: 0;
        border: none;
        background: none;
    }

    #wb-name {
        font-size: 13px;
        margin: 0 4px;
    }

    .tool-btn {
        width: 40px;
        height: 40px;
        font-size: 15px;
    }

    .size-badge {
        display: none;
    }

    .color-picker-wrap {
        width: 30px;
        height: 30px;
    }

    .color-swatch {
        width: 28px;
        height: 28px;
    }

    /* Zoom label – take less space */
    #zoom-label {
        min-width: 32px;
        font-size: 11px;
    }

    /* Password modal */
    .pw-modal {
        min-width: 0;
        width: calc(100vw - 32px);
        max-width: 340px;
        padding: 20px 16px;
    }
}
.pw-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.pw-modal-overlay.hidden {
    display: none;
}
.pw-modal {
    background: #fff;
    border-radius: 12px;
    padding: 24px 28px;
    min-width: 300px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
    text-align: center;
}
.pw-modal h3 {
    margin: 0 0 16px;
    color: var(--c-primary);
    font-size: 18px;
}
#pw-modal-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    font-size: 15px;
    border: 2px solid #ccc;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
}
#pw-modal-input:focus {
    border-color: var(--c-primary);
}
.pw-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    justify-content: center;
}
.pw-modal-btn {
    padding: 8px 22px;
    font-size: 14px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    touch-action: manipulation;
    transition: opacity 0.15s;
}
.pw-modal-btn:hover {
    opacity: 0.85;
}
.pw-modal-btn--cancel {
    background: #e0e0e0;
    color: #333;
}
.pw-modal-btn--ok {
    background: var(--c-primary);
    color: #fff;
}

/* ── Welcome modal ─────────────────────────────────────────────── */
.welcome-modal {
    max-width: 420px;
}
.welcome-modal h3 {
    margin: 0 0 12px;
    color: var(--c-primary);
    font-size: 18px;
}
.welcome-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--c-text-sec);
    margin: 0 0 18px;
}

/* ── Help modal ────────────────────────────────────────────────── */
.help-modal {
    max-width: 520px;
    text-align: left;
}
.help-modal h3 {
    text-align: center;
    margin: 0 0 16px;
    color: var(--c-primary);
    font-size: 20px;
}
.help-content {
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 4px;
}
.help-section {
    margin-bottom: 14px;
}
.help-section h4 {
    font-size: 15px;
    margin: 0 0 4px;
    color: var(--c-text);
}
.help-section p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--c-text-sec);
    margin: 0;
}

/* ── Auth wall (app hidden until authenticated) ────────────────── */
.app-hidden {
    display: none !important;
}

/* ── Image delete overlay (trash icon) ─────────────────────────── */
.image-delete-overlay {
    position: fixed;
    z-index: 150;
    pointer-events: none;
}
.image-delete-overlay.hidden {
    display: none;
}

.image-delete-btn {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--c-danger);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    transition:
        transform 0.15s,
        box-shadow 0.15s;
}
.image-delete-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.5);
}
.image-delete-btn svg {
    stroke: #fff;
    pointer-events: none;
}

/* ── Tutorial overlay ─────────────────────────────────────────────── */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 20000;
    background: rgba(0, 0, 0, 0.55);
    transition: background 0.3s;
}

.tutorial-spotlight {
    position: fixed;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    background: transparent;
    pointer-events: none;
    transition:
        left 0.35s ease,
        top 0.35s ease,
        width 0.35s ease,
        height 0.35s ease;
    z-index: 20001;
}

.tutorial-tooltip {
    position: fixed;
    background: var(--c-surface);
    border-radius: 14px;
    padding: 18px 20px 14px;
    max-width: 320px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 20002;
    transition:
        left 0.3s ease,
        top 0.3s ease;
    animation: tutorialFadeIn 0.25s ease;
}

@keyframes tutorialFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tutorial-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.tutorial-step-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--c-primary);
    background: rgba(3, 62, 120, 0.1);
    padding: 2px 10px;
    border-radius: 20px;
}

.tutorial-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--c-text-sec);
    font-size: 20px;
    cursor: pointer;
    transition: background 0.15s;
}
.tutorial-close:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--c-text);
}

.tutorial-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--c-text);
    margin: 0 0 6px;
}

.tutorial-text {
    font-size: 13px;
    line-height: 1.6;
    color: var(--c-text-sec);
    margin: 0 0 14px;
}

.tutorial-nav {
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.tutorial-btn {
    padding: 7px 18px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.15s;
}

.tutorial-btn--prev {
    background: var(--c-bg);
    color: var(--c-text);
}
.tutorial-btn--prev:hover {
    background: #e0e0e0;
}

.tutorial-btn--next {
    background: var(--c-primary);
    color: #fff;
}
.tutorial-btn--next:hover {
    background: var(--c-primary-dark);
}

/* ── Help modal – tutorial button ─────────────────────────────────── */
.help-tutorial-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 0;
    margin-top: 4px;
    margin-bottom: 16px;
    border: 2px solid var(--c-primary);
    border-radius: 10px;
    background: rgba(3, 62, 120, 0.06);
    color: var(--c-primary);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
}
.help-tutorial-btn:hover {
    background: var(--c-primary);
    color: #fff;
}

/* ── Help modal – keyboard shortcut table ─────────────────────────── */
.help-kbd-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
}
.help-kbd-table td {
    padding: 3px 0;
    font-size: 12px;
    color: var(--c-text-sec);
    line-height: 1.5;
}
.help-kbd-table td:first-child {
    width: 55%;
}

.help-kbd {
    display: inline-block;
    padding: 1px 7px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #f3f4f6;
    font-family: monospace;
    font-size: 11px;
    color: var(--c-text);
}

/* ── Graph modal ─────────────────────────────────────────────────────── */
.graph-modal {
    max-width: 560px;
    width: 90vw;
}
.graph-fn-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}
.graph-fn-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.graph-fn-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid rgba(0, 0, 0, 0.1);
}
.graph-fn-color-input {
    width: 0;
    height: 0;
    padding: 0;
    border: 0;
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.graph-fn-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--c-text);
    flex-shrink: 0;
}
.graph-fn-input {
    flex: 1;
    min-width: 120px;
    padding: 6px 10px;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: monospace;
    outline: none;
    transition: border-color 0.15s;
}
.graph-fn-input:focus {
    border-color: var(--c-primary);
}
.graph-fn-preview {
    width: 100%;
    min-height: 20px;
    padding-left: 36px;
    font-size: 13px;
    color: var(--c-text-sec);
}
.graph-fn-preview .katex {
    font-size: 1em;
}
.graph-fn-remove {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    color: var(--c-text-sec);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.graph-fn-remove:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--c-danger);
}

.graph-add-fn-btn {
    width: 100%;
    padding: 8px;
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    background: none;
    color: var(--c-text-sec);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
    margin-bottom: 14px;
}
.graph-add-fn-btn:hover {
    border-color: var(--c-primary);
    color: var(--c-primary);
}

.graph-range-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}
.graph-range-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--c-text);
}
.graph-range-label {
    font-weight: 600;
    width: 48px;
    flex-shrink: 0;
}
.graph-range-row label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--c-text-sec);
    font-size: 13px;
}
.graph-range-row input[type="number"] {
    width: 70px;
    padding: 5px 8px;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}
.graph-range-row input[type="number"]:focus {
    border-color: var(--c-primary);
}

.graph-pi-row {
    margin-bottom: 10px;
}
.graph-pi-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--c-text);
    cursor: pointer;
}
.graph-pi-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--c-primary);
}

.graph-kbd-toggle-btn {
    display: block;
    width: 100%;
    padding: 7px;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    background: var(--c-bg);
    color: var(--c-text-sec);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
    transition: border-color 0.15s, color 0.15s;
}
.graph-kbd-toggle-btn:hover {
    border-color: var(--c-primary);
    color: var(--c-primary);
}

.graph-math-kbd {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    margin-bottom: 14px;
}
.graph-math-kbd.hidden {
    display: none;
}
.graph-kbd-btn {
    padding: 8px 4px;
    border: 1.5px solid #d1d5db;
    border-radius: 6px;
    background: var(--c-surface);
    color: var(--c-text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.1s, border-color 0.1s;
    touch-action: manipulation;
}
.graph-kbd-btn:hover {
    background: var(--c-bg);
    border-color: var(--c-primary);
}
.graph-kbd-btn:active {
    background: rgba(3, 62, 120, 0.08);
}

/* ── Graph tooltip (canvas hover) ────────────────────────────────────── */
.graph-tooltip {
    position: fixed;
    z-index: 150;
    padding: 3px 8px;
    border-radius: 6px;
    background: rgba(31, 41, 55, 0.9);
    color: #fff;
    font-size: 12px;
    font-family: monospace;
    pointer-events: none;
    border-left: 3px solid #6b7280;
    white-space: nowrap;
    transition: left 0.05s, top 0.05s;
}
.graph-tooltip.hidden {
    display: none;
}

/* ── Graf overlay ovládání (tablet + desktop) ────────────────────────── */
.graph-controls {
    position: fixed;
    z-index: 160;
    display: flex;
    gap: 3px;
    transform: translateX(-50%);
    background: var(--c-surface);
    border-radius: 10px;
    padding: 3px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
    pointer-events: auto;
}
.graph-controls.hidden {
    display: none;
}
.graph-ctrl-btn {
    width: 32px;
    height: 32px;
    border: 1.5px solid #d1d5db;
    border-radius: 7px;
    background: var(--c-surface);
    color: var(--c-text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    transition: background 0.1s, border-color 0.1s;
}
.graph-ctrl-btn:hover {
    background: var(--c-bg);
    border-color: var(--c-primary);
}
.graph-ctrl-btn:active {
    background: rgba(3, 62, 120, 0.1);
}
