:root {
    color-scheme: light dark;
    --bg: #0f172a;
    --surface: #111827;
    --card: rgba(17, 24, 39, 0.8);
    --border: rgba(255, 255, 255, 0.08);
    --primary: #3a7afe;
    --primary-hover: #2557d6;
    --text: #e2e8f0;
    --text-muted: rgba(226, 232, 240, 0.7);
    --danger: #f87171;
    --divider: rgba(255, 255, 255, 0.12);
    --sidebar-width: clamp(0px, 90vw, 280px);
    --panel-light-bg: rgba(248, 250, 252, 0.96);
    --panel-light-text: #0f172a;
    --panel-light-muted: rgba(15, 23, 42, 0.6);
    --panel-light-border: rgba(15, 23, 42, 0.12);
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at top, #1e3a8a, #0f172a 60%);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}

#app {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.view {
    display: none;
    width: 100%;
    height: 100%;
}

.view.active {
    display: flex;
}

#workspace-view {
    flex-direction: column;
}

#deck-selection {
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.selection-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 3rem;
    width: min(480px, 90vw);
    box-shadow: 0 20px 70px rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(18px);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.selection-card h1 {
    margin: 0;
    font-size: clamp(2rem, 2vw + 1rem, 2.8rem);
}

.subtitle {
    margin: 0;
    color: var(--text-muted);
}

.selection-actions {
    display: flex;
    justify-content: flex-end;
}

.selection-settings {
    position: relative;
    display: inline-flex;
}

.selection-settings-menu {
    top: calc(100% + 0.4rem);
    right: 0;
}

.deck-list {
    display: grid;
    gap: 0.75rem;
}

.deck-list button {
    padding: 0.9rem 1.1rem;
    background: rgba(59, 130, 246, 0.12);
    border-radius: 14px;
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.deck-list button:hover {
    background: rgba(59, 130, 246, 0.24);
    transform: translateY(-2px);
}

button.primary {
    background: linear-gradient(120deg, var(--primary), #60a5fa);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 0.9rem 1.4rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

button.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(58, 122, 254, 0.35);
}

button.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: inherit;
    padding: 0.6rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

button.icon-button {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.06);
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.workspace-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    padding: 0.4rem clamp(0.75rem, 2vw, 1rem);
    backdrop-filter: blur(12px);
    background: var(--panel-light-bg);
    border-bottom: 1px solid var(--panel-light-border);
    color: var(--panel-light-text);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
    gap: 0.75rem;
    align-items: center;
}

.workspace-header .left-controls,
.workspace-header .right-controls {
    color: inherit;
}

.workspace-header button.primary {
    padding: 0.55rem 1.1rem;
}

.workspace-header button.ghost,
.workspace-header button.icon-button {
    border-color: var(--panel-light-border);
    color: var(--panel-light-text);
}

.workspace-header button.ghost {
    background: rgba(148, 163, 184, 0.14);
    padding: 0.45rem 0.85rem;
}

.workspace-header button.ghost:hover {
    background: rgba(148, 163, 184, 0.22);
}

.workspace-header button.icon-button {
    background: rgba(148, 163, 184, 0.18);
}


.left-controls {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.right-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 0 0 auto;
}

.toolbar-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    margin-right: 0.5rem;
    flex: 0 0 auto;
}

.toolbar-nav button {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
    gap: 0.35rem;
    border-radius: 9px;
    min-width: 0;
}

#back-button,
#toggle-sidebar {
    padding-inline: 0.3rem;
}

.toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    padding-block: 0.25rem;
    flex-wrap: nowrap;
}

.toolbar-scroll {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
}

.toolbar-scroll > * {
    flex: 0 0 auto;
}

.toolbar-scroll::-webkit-scrollbar {
    display: none;
}

.toolbar-scroll .field {
    flex: 0 0 auto;
}

.toolbar-scroll .field--label {
    flex: 1 1 220px;
}

@media (min-width: 1081px) {
    .left-controls {
        overflow: visible;
    }

    .toolbar-scroll .field--label {
        flex: 1 1 clamp(180px, 33%, 320px);
        max-width: clamp(180px, 33%, 320px);
    }
}

.tools-menu {
    position: relative;
    display: flex;
}

.tools-menu .menu {
    top: calc(100% + 0.4rem);
    right: 0;
}

.tools-menu-anchor {
    display: none;
    align-items: center;
}

.tools-menu-anchor.tools-menu-anchor--active {
    display: flex;
}

.tools-menu--tablet {
    margin-left: 0.75rem;
}

.toolbar label {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--panel-light-muted);
    gap: 0.25rem;
    white-space: nowrap;
}

.toolbar input[type="number"],
.toolbar input[type="text"],
.toolbar input[type="color"] {
    background: rgba(148, 163, 184, 0.18);
    border: 1px solid var(--panel-light-border);
    border-radius: 10px;
    color: var(--panel-light-text);
    min-width: 0;
    height: 34px;
}

.toolbar input[type="number"],
.toolbar input[type="text"] {
    padding: 0 0.6rem;
    line-height: 1.2;
}

.toolbar input[type="text"] {
    -webkit-appearance: none;
}

.toolbar input[type="number"] {
    width: 11ch;
    text-align: right;
}

.toolbar input[type="text"] {
    flex: 1 1 180px;
    min-width: 140px;
}

#input-label {
    max-height: 34px;
    line-height: 1.2;
    padding: 0 0.6rem;
    resize: none;
}

.toolbar input[type="color"] {
    padding: 0.2rem;
}

@media (max-width: 1080px) {
    .workspace-header {
        gap: 0.5rem;
    }

    .toolbar {
        gap: 0.4rem;
    }

    .toolbar-scroll {
        gap: 0.4rem;
    }

    .workspace-header button.ghost,
    .workspace-header button.primary {
        padding-block: 0.35rem;
        border-radius: 10px;
    }

    .workspace-header button.ghost .label {
        font-size: 0.82rem;
    }
}

@media (max-width: 880px) {
    .workspace-header {
        padding-inline: 0.75rem;
    }

    .toolbar label {
        font-size: 0.68rem;
    }

    .toolbar input[type="text"] {
        flex-basis: 160px;
    }

    .toolbar-scroll {
        gap: 0.35rem;
    }
}

.workspace-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

#history-sidebar {
    order: 1;
}

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    flex-basis: var(--sidebar-width);
    background: var(--panel-light-bg);
    border-right: 1px solid var(--panel-light-border);
    color: var(--panel-light-text);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
    max-height: 100vh;
    transition: opacity 0.3s ease, width 0.3s ease, flex-basis 0.3s ease, padding 0.3s ease,
        margin 0.3s ease, max-height 0.3s ease;
}

.planning-sidebar {
    border-left: 1px solid var(--panel-light-border);
    border-right: none;
    gap: 0.75rem;
    order: 3;
    margin-left: auto;
}

.planning-sidebar.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.planning-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
    overflow: hidden;
}

.planning-actions {
    display: flex;
    gap: 0.5rem;
}

.planning-actions button {
    flex: 1;
    white-space: nowrap;
}

.planning-actions .ghost.danger {
    color: #b91c1c;
    border-color: rgba(248, 113, 113, 0.45);
}

.planning-actions .ghost.danger:hover:not(:disabled) {
    background: rgba(248, 113, 113, 0.18);
}

.planning-job-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.planning-job-list .list-empty {
    padding: 0.5rem 0;
}

.planning-toggle {
    justify-content: flex-start;
    width: 100%;
    gap: 0.5rem;
    font-weight: 600;
    text-align: left;
}

.planning-toggle::before {
    content: '◉';
    font-size: 0.8rem;
    opacity: 0.6;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.planning-toggle.active::before {
    content: '⬤';
    opacity: 1;
    transform: scale(1.1);
}

.planning-toggle.active {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(59, 130, 246, 0.45);
    color: #1e3a8a;
}

.planning-toggle:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.planning-job-entry {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.planning-job-entry .planning-job-toggle {
    flex: 1;
}

.planning-job-delete {
    border: none;
    background: rgba(248, 113, 113, 0.12);
    color: var(--danger);
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.planning-job-delete:hover {
    background: rgba(248, 113, 113, 0.22);
    transform: translateY(-1px);
}

.planning-job-delete:focus-visible {
    outline: 2px solid rgba(248, 113, 113, 0.6);
    outline-offset: 2px;
}

.planning-job-delete:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.planning-job-label {
    flex: 1;
}

.planning-job-meta {
    font-size: 0.75rem;
    color: var(--panel-light-muted);
}

.sidebar.hidden {
    opacity: 0;
    width: 0;
    flex-basis: 0;
    padding: 0;
    margin: 0;
    max-height: 0;
    pointer-events: none;
}

.sidebar h2 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--panel-light-muted);
}

.list-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.search-field {
    display: block;
}

.search-field input[type='search'] {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    border: 1px solid var(--panel-light-border);
    background: rgba(148, 163, 184, 0.18);
    color: var(--panel-light-text);
    font-size: 0.9rem;
}

.sort-buttons {
    display: flex;
    gap: 0.5rem;
}

.sort-button {
    flex: 1;
    justify-content: center;
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 10px;
    background: rgba(148, 163, 184, 0.12);
    border-color: rgba(148, 163, 184, 0.32);
}

.sort-button.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.45);
    color: #1e3a8a;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

#history-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    font-size: 0.9rem;
    flex: 1;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.item-summary {
    background: rgba(37, 99, 235, 0.08);
    border-radius: 12px;
    padding: 0.75rem 0.85rem;
    border: 1px solid rgba(37, 99, 235, 0.18);
    color: var(--panel-light-text);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.item-summary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.item-summary-label {
    font-weight: 600;
    font-size: 0.95rem;
}

.item-summary-detail {
    font-size: 0.8rem;
    color: var(--panel-light-muted);
}

.item-summary-comment {
    font-size: 0.82rem;
    color: var(--panel-light-text);
}

.item-history-button {
    font-size: 0.75rem;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
}

.list-empty {
    font-size: 0.85rem;
    color: var(--panel-light-muted);
}

.nav-controls button {
    width: auto;
    flex: 0 0 auto;
}

@media (max-width: 600px) {
    .nav-controls button {
        width: 100%;
    }
}

.workspace-container {
    position: relative;
    flex: 1;
    overflow: hidden;
    background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.18), transparent 42%),
        radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.24), transparent 48%),
        rgba(15, 23, 42, 0.55);
    order: 2;
    touch-action: none;
}

.workspace-container.planning-locked .item,
.workspace-container.planning-locked .deck-area {
    pointer-events: none;
}

.workspace-container.planning-hide-current .workspace-content > .item {
    opacity: 0;
    visibility: hidden;
}

.workspace-container.planning-mode-active .workspace-content > .item,
.workspace-container.planning-mode-active .workspace-content > .deck-area {
    pointer-events: none;
}

.workspace-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: 0 0;
    width: 2000px;
    height: 2000px;
    background-image: linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
    background-size: 60px 60px;
    border-radius: 40px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    touch-action: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.planning-overlays {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;
}

.planning-editing-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
}

.planning-editing-layer .item {
    pointer-events: none;
}

.planning-editing-layer .deck-area {
    pointer-events: none;
}

.planning-editing-layer .planning-edit-deck-area .resize-handle {
    display: none;
}

.workspace-container.planning-mode-active .planning-editing-layer .item {
    pointer-events: auto;
}

.planning-edit-item {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35);
}

.planning-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.planning-overlay-item {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-origin: 50% 50%;
    border-radius: 0;
    border: 1px dashed rgba(14, 165, 233, 0.6);
    background: rgba(14, 165, 233, 0.2);
    color: #0f172a;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.01em;
    padding: 0.35rem;
    box-shadow: 0 10px 25px rgba(14, 165, 233, 0.2);
    font-size: 1.4rem;
    white-space: normal;
    z-index: 1;
}

.planning-overlay-item.deck-layer-item {
    z-index: 0;
    box-shadow: 0 6px 18px rgba(14, 165, 233, 0.18);
}

.planning-overlay-item.item {
    background: rgba(59, 130, 246, 0.28);
    border-color: rgba(59, 130, 246, 0.55);
    color: #0f172a;
    clip-path: none;
}

.planning-overlay-item.item.has-dark-text {
    color: #fff;
}

.planning-overlay-item.item[data-shape='circle'] {
    border-radius: 50%;
}

.planning-overlay-item.item[data-shape='triangle-right'] {
    border-radius: 0;
    clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.planning-overlay-item.item[data-shape='triangle-equilateral'] {
    border-radius: 0;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.planning-overlay-item.deck-area {
    background: rgba(248, 250, 252, 0.45);
    border-color: rgba(148, 163, 184, 0.6);
    color: #1f2937;
}

.planning-overlay-item .overlay-label {
    pointer-events: none;
}

.planning-job-toggle.editing::after {
    content: ' · editing';
    margin-left: 0.4rem;
    font-size: 0.85rem;
    color: var(--primary);
    letter-spacing: 0.01em;
}

.item,
.deck-area {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    font-weight: 600;
    font-size: 2rem;
    text-align: center;
    padding: 0.5rem;
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.2s ease;
    touch-action: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.item {
    border-radius: 0;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.4);
    z-index: 1;
    clip-path: none;
}

.item-search-highlight {
    border-color: #facc15 !important;
    box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.35), 0 0 18px rgba(250, 204, 21, 0.65);
    animation: item-search-highlight-pulse 1.2s ease-in-out infinite;
}

@keyframes item-search-highlight-pulse {
    0%,
    100% {
        box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.3), 0 0 10px rgba(250, 204, 21, 0.45);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(250, 204, 21, 0.55), 0 0 22px rgba(250, 204, 21, 0.85);
    }
}

.item.item-backloaded {
    border-width: 4px;
    border-style: solid;
    border-color: transparent;
    border-image-slice: 1;
    border-image-source: repeating-linear-gradient(
        135deg,
        #000000 0px,
        #000000 10px,
        #facc15 10px,
        #facc15 20px
    );
}

.item[data-comment]:not([data-comment=''])::after {
    content: attr(data-comment);
    position: absolute;
    bottom: calc(100% + 0.75rem);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    padding: 0.45rem 0.75rem;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    white-space: pre-line;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.4);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    min-width: min(30ch, 280px);
    max-width: min(32ch, 320px);
    text-align: left;
    word-break: normal;
    overflow-wrap: break-word;
    z-index: 5;
}

.item[data-comment]:not([data-comment='']):hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.item-label {
    pointer-events: none;
    width: 100%;
    text-align: center;
    line-height: 1.2;
}

.item:active {
    cursor: grabbing;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.55);
}

.item.deck-layer-item {
    z-index: 0;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.35);
}

.item[data-shape='circle'] {
    border-radius: 50%;
}

.item[data-shape='triangle-right'] {
    border-radius: 0;
    clip-path: polygon(0 0, 100% 100%, 0 100%);
}

.item[data-shape='triangle-equilateral'] {
    border-radius: 0;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

.deck-area {
    background: #fff;
    color: #0f172a;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 0;
    box-shadow: none;
    z-index: 0;
    backdrop-filter: none;
}

.deck-area .deck-name {
    position: absolute;
    top: 0;
    left: 0;
    transform: translateY(calc(-100% - 0.4rem));
    font-size: 1.7rem;
    font-weight: 600;
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    padding: 0.25rem 0.6rem;
    border-radius: 0.6rem;
    letter-spacing: 0.01em;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.35);
}

.deck-area .deck-area-guides {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: none;
}

.deck-area.show-resize-guides .deck-area-guides {
    display: block;
}

.deck-area .deck-area-guide {
    position: absolute;
    color: #0f172a;
    font-size: 1.2rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.deck-area .deck-area-guide-width {
    left: 0;
    right: 0;
    top: 50%;
    border-top: 2px dashed rgba(15, 23, 42, 0.35);
}

.deck-area .deck-area-guide-width .deck-area-guide-label {
    position: absolute;
    top: calc(100% + 0.6rem);
    left: 50%;
    transform: translate(-50%, 0);
    background: rgba(248, 250, 252, 0.95);
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
    white-space: nowrap;
}

.deck-area .deck-area-guide-height {
    top: 0;
    bottom: 0;
    left: 50%;
    border-left: 2px dashed rgba(15, 23, 42, 0.35);
}

.deck-area .deck-area-guide-height .deck-area-guide-label {
    position: absolute;
    left: calc(100% + 0.6rem);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(248, 250, 252, 0.95);
    padding: 0.35rem 0.8rem;
    border-radius: 999px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
    white-space: nowrap;
}

.deck-area.locked {
    border-style: dashed;
    cursor: default;
}

.deck-area.locked .resize-handle {
    display: none;
}

.deck-area.name-hidden .deck-name {
    display: none;
}

.deck-area:active {
    cursor: grabbing;
    box-shadow: none;
}

.deck-area.locked:active {
    cursor: default;
}

.deck-area .resize-handle {
    background: rgba(15, 23, 42, 0.35);
}

.item.locked {
    cursor: default;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
}

.item.locked .resize-handle {
    display: none;
}

.resize-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.9);
    bottom: 8px;
    right: 8px;
    cursor: nwse-resize;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.4);
    touch-action: none;
}

.measure-toggle.active {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.4);
    color: var(--panel-light-text);
    box-shadow: 0 8px 18px rgba(59, 130, 246, 0.2);
}

.workspace-container.measure-mode {
    cursor: crosshair;
}

.workspace-container.measure-mode .item,
.workspace-container.measure-mode .deck-area {
    cursor: crosshair;
}

.measure-instructions {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.85);
    color: #fff;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
    box-shadow: 0 18px 35px rgba(15, 23, 42, 0.35);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 20;
}

.measure-instructions.visible {
    opacity: 1;
}

.measurement-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    --measurement-scale: 1;
}

.measurement-point {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.35);
    transform-origin: center;
    transform: translate(-50%, -50%) scale(var(--measurement-scale));
}

.measurement-line {
    position: absolute;
    height: calc(2px * var(--measurement-scale));
    background: var(--primary);
    transform-origin: 0 50%;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12);
}

.measurement-label {
    position: absolute;
    transform-origin: center;
    transform: translate(-50%, -50%) scale(var(--measurement-scale));
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    padding: 0.25rem 0.55rem;
    border-radius: 0.6rem;
    font-size: 0.95rem;
    white-space: nowrap;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.35);
    pointer-events: none;
}

.item .resize-handle {
    cursor: grab;
}

.item .resize-handle:active {
    cursor: grabbing;
}

.menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: rgba(248, 250, 252, 0.96);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 14px;
    padding: 0.75rem;
    display: none;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 180px;
    z-index: 1000;
    box-shadow: 0 24px 50px rgba(15, 23, 42, 0.18);
    color: #0f172a;
}

.menu.open {
    display: flex;
}

.menu button {
    border: none;
    background: rgba(15, 23, 42, 0.04);
    color: inherit;
    padding: 0.6rem 0.85rem;
    text-align: left;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.menu button.active {
    background: rgba(59, 130, 246, 0.22);
    border: 1px solid rgba(59, 130, 246, 0.32);
}

.menu button:hover {
    background: rgba(59, 130, 246, 0.18);
    transform: translateY(-1px);
}

.menu button.danger {
    color: #b91c1c;
}

.menu button.danger:hover {
    background: rgba(248, 113, 113, 0.22);
}

.deck-settings-panel {
    display: none;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.45rem;
    padding-top: 0.45rem;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.deck-settings-panel.open {
    display: flex;
}

.deck-settings-section {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.deck-settings-section + .deck-settings-section {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(15, 23, 42, 0.08);
}

.deck-settings-panel button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

.deck-modify-notice {
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    order: -1;
    align-self: stretch;
    display: none;
    flex-direction: column;
    gap: 0.25rem;
    align-items: center;
}

.deck-modify-notice.active {
    display: flex;
}

.deck-modify-warning {
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.deck-modify-escape {
    color: var(--danger);
    letter-spacing: 0.05em;
}

.workspace-header.modify-mode {
    background: #1d4ed8;
    color: #fff;
    border-bottom-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 36px rgba(29, 78, 216, 0.35);
}

.workspace-header.modify-mode .deck-modify-notice {
    display: flex;
}

.workspace-header.modify-mode button.ghost,
.workspace-header.modify-mode button.icon-button {
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
}

.workspace-header.modify-mode button.ghost:hover,
.workspace-header.modify-mode button.icon-button:hover {
    background: rgba(255, 255, 255, 0.24);
}

.workspace-header.modify-mode .toolbar label {
    color: rgba(255, 255, 255, 0.85);
}

.workspace-header.modify-mode .toolbar input[type="number"],
.workspace-header.modify-mode .toolbar input[type="text"],
.workspace-header.modify-mode .toolbar input[type="color"] {
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
}

.workspace-header.modify-mode #tools-menu {
    background: rgba(15, 23, 42, 0.96);
    color: #f8fafc;
    border-color: rgba(255, 255, 255, 0.18);
}

.workspace-header.modify-mode #tools-menu button {
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
}

.workspace-header.modify-mode #tools-menu button:hover {
    background: rgba(255, 255, 255, 0.16);
}

.workspace-header.modify-mode #tools-menu .deck-settings-panel {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.workspace-header.modify-mode #tools-menu .deck-settings-section + .deck-settings-section {
    border-top-color: rgba(255, 255, 255, 0.2);
}

.workspace-header.planning-mode {
    background: linear-gradient(120deg, rgba(250, 204, 21, 0.26), rgba(248, 250, 252, 0.96));
    border-bottom-color: rgba(250, 204, 21, 0.35);
    box-shadow: 0 12px 36px rgba(250, 204, 21, 0.25);
}

.workspace-header.modify-mode.planning-mode {
    background: #1d4ed8;
    border-bottom-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 36px rgba(29, 78, 216, 0.35);
    color: #fff;
}

.planning-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    color: #854d0e;
    background: rgba(250, 204, 21, 0.24);
    border: 1px solid rgba(202, 138, 4, 0.4);
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.planning-indicator[hidden] {
    display: none;
}

.context-menu {
    position: fixed;
    top: 0;
    left: 0;
    transform: translate(-1000px, -1000px);
    min-width: unset;
    width: max-content;
    max-width: 220px;
    padding: 0.5rem;
}

.context-menu.open {
    display: flex;
}

.context-menu button {
    white-space: nowrap;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 1500;
}

.modal-panel {
    background: var(--panel-light-bg);
    border-radius: 20px;
    border: 1px solid var(--panel-light-border);
    padding: 1.5rem;
    max-width: min(420px, 90vw);
    max-height: min(640px, 90vh);
    width: 100%;
    color: var(--panel-light-text);
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.35);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.modal-panel h2 {
    margin: 0;
    font-size: 1.35rem;
}

.modify-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.modify-form fieldset {
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 14px;
    padding: 0.9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.modify-form legend {
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--panel-light-muted);
    margin-bottom: 0.4rem;
}

.modify-form input[type='number'],
.modify-form input[type='text'],
.modify-form input[type='color'] {
    border-radius: 10px;
    border: 1px solid var(--panel-light-border);
    padding: 0.55rem 0.75rem;
    background: rgba(148, 163, 184, 0.15);
    color: var(--panel-light-text);
    font-size: 0.95rem;
}

.modify-form input[type='color'] {
    padding: 0.2rem;
    height: 42px;
    width: 72px;
}

.shape-button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.shape-option-button {
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.shape-option-button.active {
    background: var(--primary);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 10px 24px rgba(58, 122, 254, 0.25);
}

.deck-layer-button {
    align-self: flex-start;
}

.modify-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.modify-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.modify-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.modify-section-header h3 {
    margin: 0;
    font-size: 1rem;
}

.attachment-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.attachment-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.attachment-item a {
    color: inherit;
    text-decoration: none;
    font-weight: 500;
}

.attachment-item a:hover {
    text-decoration: underline;
}

.attachment-remove {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 999px;
}

.attachment-empty {
    font-size: 0.85rem;
    color: var(--panel-light-muted);
}

.item[data-has-attachments='true']::after {
    content: '\1F4CE';
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 1.2rem;
    pointer-events: none;
}

.zoom-indicator {
    font-size: 0.9rem;
    color: var(--panel-light-muted);
}

@media (min-width: 768px) and (max-width: 1180px) and (pointer: coarse) {
    .workspace-header {
        position: relative;
        align-items: center;
        gap: 0.75rem;
    }

    .left-controls {
        flex: 1 1 auto;
        flex-wrap: nowrap;
        align-items: center;
        gap: 1rem;
    }

    .nav-controls {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        min-width: 0;
        flex: 0 1 auto;
    }

    .nav-controls button {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .toolbar {
        flex: 1 1 auto;
        align-items: center;
        gap: 0.6rem;
        min-width: 0;
    }

    .toolbar label {
        flex: 0 1 auto;
    }

    .toolbar input[type="number"] {
        width: 5ch;
    }

    .toolbar input[type="text"] {
        flex: 1 1 160px;
        min-width: 0;
    }

    #create-item,
    .tools-menu {
        flex: 0 0 auto;
    }

    .right-controls {
        margin-left: auto;
        align-items: center;
    }

    .zoom-indicator {
        position: static;
        background: transparent;
        color: var(--panel-light-muted);
        padding: 0;
        border-radius: 0;
        font-weight: 600;
        box-shadow: none;
    }

    .tools-menu-anchor.tools-menu-anchor--active {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
}

@media (max-width: 900px) {
    .workspace-header {
        flex-direction: column;
        align-items: stretch;
    }

    .left-controls {
        width: 100%;
        justify-content: space-between;
    }

    .toolbar {
        width: 100%;
    }

    .workspace-body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-basis: auto;
        border-right: none;
        border-bottom: 1px solid var(--panel-light-border);
    }

    .sidebar.hidden {
        width: 100%;
        flex-basis: auto;
        max-height: 0;
        opacity: 0;
        padding: 0;
    }
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f8fafc;
        --surface: rgba(255, 255, 255, 0.9);
        --card: rgba(255, 255, 255, 0.86);
        --border: rgba(15, 23, 42, 0.08);
        --primary: #2563eb;
        --primary-hover: #1d4ed8;
        --text: #0f172a;
        --text-muted: rgba(15, 23, 42, 0.6);
        --danger: #dc2626;
        --divider: rgba(15, 23, 42, 0.12);
    }

    body {
        background: radial-gradient(circle at top, #bfdbfe, #eff6ff 65%);
    }

    .workspace-container {
        background: radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 40%),
            radial-gradient(circle at bottom right, rgba(14, 165, 233, 0.2), transparent 45%),
            #f1f5f9;
    }
}
