:root {
    --bg: #0f172a;
    --panel: #111827;
    --panel-soft: #1f2937;
    --surface: #f8fafc;
    --surface-grid: rgba(15, 23, 42, 0.06);
    --border: rgba(148, 163, 184, 0.25);
    --text: #e5e7eb;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --viewer: #94a3b8;
    --commenter: #f59e0b;
    --editor: #22c55e;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
select,
input[type="text"],
input[type="color"],
textarea {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

button {
    cursor: pointer;
    padding: 10px 12px;
    transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, opacity 120ms ease;
}

button:hover,
select:hover,
input:hover,
textarea:hover {
    border-color: rgba(56, 189, 248, 0.5);
}

button:hover {
    transform: translateY(-1px);
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    opacity: 0.46;
    cursor: not-allowed;
    transform: none;
}

button.active {
    background: rgba(56, 189, 248, 0.18);
    border-color: rgba(56, 189, 248, 0.85);
}

button.ghost,
.link-button {
    background: transparent;
}

button.danger {
    border-color: rgba(239, 68, 68, 0.4);
}

input[type="text"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
}

input[type="color"] {
    width: 100%;
    min-height: 40px;
    padding: 4px;
}

textarea {
    min-height: 96px;
    resize: vertical;
}

.app-shell {
    display: grid;
    grid-template-columns: 380px 1fr;
    height: 100%;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-right: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(17, 24, 39, 0.96));
    overflow: auto;
}

.sidebar h1 {
    margin: 0;
    font-size: 24px;
}

.sidebar p {
    margin: 0;
    color: var(--muted);
}

.panel {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.panel h2,
.panel h3 {
    margin: 0;
    font-size: 14px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #cbd5e1;
}

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

.panel-grid.triple {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.status-inline {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.workspace {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.workspace-header {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(12px);
}

.badge,
.presence-chip,
.timer-chip,
.vote-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-size: 13px;
}

.presence-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.presence-role {
    opacity: 0.8;
    font-size: 12px;
}

.role-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.role-dot.viewer {
    background: var(--viewer);
}

.role-dot.commenter {
    background: var(--commenter);
}

.role-dot.editor {
    background: var(--editor);
}

.workspace-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.viewport {
    position: relative;
    flex: 1;
    overflow: auto;
    background:
        linear-gradient(var(--surface-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--surface-grid) 1px, transparent 1px),
        var(--surface);
    background-size: 24px 24px, 24px 24px, auto;
}

.board-surface {
    position: relative;
    width: 5600px;
    height: 3600px;
    margin: 0;
}

.layer,
.svg-layer,
.cursor-layer {
    position: absolute;
    inset: 0;
}

.svg-layer {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.object-layer,
.comment-layer,
.cursor-layer {
    pointer-events: none;
}

.board-item,
.comment-pin,
.remote-cursor {
    pointer-events: auto;
}

.board-item {
    position: absolute;
    display: flex;
    flex-direction: column;
    border-radius: 16px;
    border: 2px solid rgba(15, 23, 42, 0.12);
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.12);
    overflow: hidden;
    user-select: none;
}

.board-item.selected {
    outline: 3px solid rgba(56, 189, 248, 0.85);
    outline-offset: 2px;
}

.board-item.primary-selected {
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2), 0 12px 36px rgba(15, 23, 42, 0.12);
}

.board-item[data-type="frame"] {
    background: rgba(255, 255, 255, 0.02);
    border: 2px dashed rgba(15, 23, 42, 0.35);
    box-shadow: none;
}

.board-item[data-type="sticky"] {
    padding: 12px;
    color: #1f2937;
    font-weight: 600;
}

.board-item[data-type="text"] {
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.92);
    color: #0f172a;
}

.board-item[data-type="shape"] {
    background: rgba(56, 189, 248, 0.12);
    color: #0f172a;
    align-items: center;
    justify-content: center;
}

.board-item[data-shape="ellipse"] {
    border-radius: 999px;
}

.board-item[data-type="image"] {
    background: #fff;
}

.board-item[data-type="image"] img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.board-item[data-type="file"],
.board-item[data-type="mindmap"] {
    padding: 12px;
    background: #ffffff;
    color: #0f172a;
}

.board-item[data-type="mindmap"] {
    border-radius: 999px;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-weight: 600;
}

.board-item .object-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 6px;
}

.board-item .object-subtitle {
    color: #475569;
    font-size: 12px;
}

.board-item .frame-label {
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.05);
    color: #0f172a;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.object-content {
    white-space: pre-wrap;
    word-break: break-word;
}

.object-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: auto;
}

.vote-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    display: inline-flex;
    gap: 4px;
    align-items: center;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
    background: rgba(15, 23, 42, 0.85);
    color: #fff;
}

.vote-action {
    margin-left: 6px;
    border: none;
    border-radius: 999px;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.resize-handle {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid #fff;
    cursor: nwse-resize;
}

.connector-line {
    stroke: #334155;
    stroke-width: 3;
    fill: none;
    marker-end: url(#arrowhead);
    cursor: pointer;
}

.connector-line.selected,
.pen-line.selected {
    stroke: var(--accent);
}

.pen-line {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 4;
    cursor: pointer;
}

.comment-pin {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 999px;
    background: #f8fafc;
    color: #0f172a;
    border: 2px solid rgba(15, 23, 42, 0.2);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.15);
    font-size: 12px;
    font-weight: 700;
}

.comment-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px;
    background: rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.comment-card.resolved {
    opacity: 0.65;
}

.comment-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.remote-cursor {
    position: absolute;
    transform: translate(-2px, -2px);
    pointer-events: none;
}

.remote-cursor::before {
    content: "";
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.22);
}

.remote-cursor span {
    position: absolute;
    top: 12px;
    left: 8px;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.88);
    color: white;
    font-size: 12px;
}

.selection-box {
    position: absolute;
    border: 1px solid rgba(56, 189, 248, 0.95);
    background: rgba(56, 189, 248, 0.12);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
    pointer-events: none;
}

.minimap-card {
    position: sticky;
    right: 16px;
    bottom: 16px;
    margin-left: auto;
    width: 268px;
    padding: 10px;
    border-radius: 16px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(15, 23, 42, 0.82);
    backdrop-filter: blur(12px);
    box-shadow: 0 18px 36px rgba(15, 23, 42, 0.22);
    z-index: 30;
}

.minimap-header {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #cbd5e1;
    margin-bottom: 8px;
}

.minimap-stage {
    position: relative;
    width: 240px;
    height: 154px;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    background: #f8fafc;
}

.minimap-stage canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.minimap-viewport-rect {
    position: absolute;
    border: 2px solid rgba(56, 189, 248, 0.95);
    background: rgba(56, 189, 248, 0.08);
    pointer-events: none;
    border-radius: 4px;
}

.helper-text,
.muted {
    color: var(--muted);
    font-size: 12px;
}

.hidden {
    display: none !important;
}

.download-link {
    color: var(--accent);
    text-decoration: none;
}

.download-link:hover {
    text-decoration: underline;
}


body.embed-mode .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
}

body.embed-mode .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px;
    padding: 10px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: none;
    overflow: auto;
}

body.embed-mode .sidebar .panel {
    min-width: 220px;
    flex: 1 1 260px;
    padding: 10px;
    gap: 8px;
}

body.embed-mode .sidebar .panel[data-panel="intro"],
body.embed-mode .sidebar .panel[data-panel="auth"],
body.embed-mode .sidebar .panel[data-panel="acl"],
body.embed-mode .sidebar .panel[data-panel="comments"] {
    display: none;
}

body.embed-mode .sidebar .panel[data-panel="connection"] {
    flex: 1 1 260px;
}

body.embed-mode .sidebar .panel[data-panel="tools"] {
    flex: 2 1 520px;
}

body.embed-mode .sidebar .panel[data-panel="templates"],
body.embed-mode .sidebar .panel[data-panel="inspector"] {
    flex: 1 1 320px;
}

body.embed-mode .sidebar .panel h2,
body.embed-mode .sidebar .panel h3 {
    font-size: 12px;
}

body.embed-mode .panel-grid.triple {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.embed-mode .workspace-header {
    padding: 10px 12px;
}

body.embed-mode .minimap-card {
    width: 220px;
}

body.embed-mode .minimap-stage {
    width: 192px;
    height: 124px;
}

@media (max-width: 1240px) {
    .app-shell {
        grid-template-columns: 340px 1fr;
    }

    .minimap-card {
        width: 220px;
    }

    .minimap-stage {
        width: 192px;
        height: 124px;
    }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .sidebar {
        max-height: 52vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .minimap-card {
        display: none;
    }
}
