* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #e0e0e0;
    background: #1a1a1a;
    padding: 2rem;
}

.container {
    max-width: none;
    width: 100%;
    margin: 0;
}

.nav-back {
    margin-bottom: 2rem;
}

.nav-back a {
    color: var(--ember-accent-strong);
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s;
}

.nav-back a:hover {
    opacity: 0.8;
}

header {
    text-align: left;
    margin-bottom: 1.25rem;
}

.page-generator-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    margin: 1.5rem 0 1rem;
    letter-spacing: 0.02em;
}

.screen-shell {
    background: #252525;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 1.5rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.screen-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.screen-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: flex-end;
}

.panel-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.settings-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.55rem;
    padding: 0.35rem 0.45rem;
    border: 1px solid #333;
    border-radius: 8px;
    background: #1f1f1f;
}

.settings-label {
    color: #9aa0a6;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    margin-right: 0.15rem;
}

.screen-title {
    color: #f5f5f5;
    font-size: 1.1rem;
    font-weight: 600;
}

.screen-meta {
    color: #9aa0a6;
    font-size: 0.9rem;
}

.add-panel-btn {
    border: 1px solid var(--ember-accent-strong);
    background: rgba(107, 155, 209, 0.12);
    color: #c6e1ff;
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.add-panel-btn:hover {
    background: rgba(107, 155, 209, 0.25);
    border-color: #90ceff;
    transform: translateY(-1px);
}

.layout-setting-select {
    min-width: 200px;
    border: 1px solid #3a4b5e;
    background: #151515;
    color: #c7d5e4;
    border-radius: 6px;
    padding: 0.4rem 0.55rem;
    font-size: 0.85rem;
}

.layout-setting-select:focus {
    outline: none;
    border-color: var(--ember-accent-strong);
}

.layout-action-btn {
    border: 1px solid #4b4b4b;
    background: #202020;
    color: #d4d4d4;
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.layout-action-btn:hover {
    border-color: var(--ember-accent-strong);
    background: rgba(107, 155, 209, 0.12);
    transform: translateY(-1px);
}

@media (max-width: 980px) {
    .screen-controls {
        width: 100%;
        justify-content: space-between;
    }

    .settings-controls {
        width: 100%;
    }

    .layout-setting-select {
        flex: 1 1 220px;
        min-width: 0;
    }
}

.panel-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-auto-rows: 160px;
    grid-auto-flow: row dense;
    gap: 1rem;
    padding-bottom: 40vh;
}

.panel {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    min-height: 160px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
    position: relative;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel.drag-over {
    background: #2a2a2a;
    border: 2px solid var(--ember-accent-strong);
    box-shadow: 0 0 0 3px rgba(107, 155, 209, 0.15), inset 0 0 0 1px rgba(255, 255, 255, 0.02);
    transform: scale(1.01);
}

.panel-header {
    padding: 0.5rem 0.9rem;
    border-bottom: 1px solid #2f2f2f;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.panel-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.25rem 0;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: auto;
    flex-shrink: 0;
}

.panel-type-select {
    background: #151515;
    color: #c7d5e4;
    border: 1px solid #3a4b5e;
    border-radius: 5px;
    padding: 0.2rem 0.45rem;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    max-width: 100%;
}

.panel-type-select:hover,
.panel-type-select:focus {
    border-color: var(--ember-accent-strong);
    outline: none;
}

.panel-close-btn {
    appearance: none;
    -webkit-appearance: none;
    width: 26px;
    aspect-ratio: 1 / 1;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    flex: 0 0 26px;
    box-sizing: border-box;
    padding: 0;
    border-radius: 50%;
    border: 1px solid #4a4a4a;
    background: #202020;
    color: #c7c7c7;
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s, transform 0.2s;
}

.panel-close-btn:hover {
    color: #ffb3b3;
    border-color: #ff6b6b;
    background: rgba(255, 107, 107, 0.18);
    transform: scale(1.05);
}

.panel-close-btn:active {
    transform: scale(0.96);
}

.panel.dragging-panel {
    transform: scale(1.04) !important;
    opacity: 0.48;
    box-shadow: 0 16px 48px rgba(107, 155, 209, 0.7), 0 0 0 1px rgba(107, 155, 209, 0.4);
    border-color: var(--ember-accent-strong);
    z-index: 1000;
    cursor: grabbing !important;
}

.panel.drag-over .panel-header {
    background: rgba(107, 155, 209, 0.25);
    border-bottom-color: var(--ember-accent-strong);
}

.panel-title {
    font-size: 0.95rem;
    color: #e0e0e0;
    font-weight: 600;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    user-select: none;
    padding: 0.4rem 0.7rem;
    border-radius: 4px;
    border: 1px solid transparent;
    background: rgba(107, 155, 209, 0.08);
    min-width: 0;
    flex: 1 1 auto;
}

.panel-title:hover {
    background: rgba(107, 155, 209, 0.25);
    border-color: rgba(107, 155, 209, 0.4);
    color: #90ceff;
}

.panel-title-input {
    font-size: 0.95rem;
    color: #e0e0e0;
    font-weight: 600;
    background: #0a0a0a;
    border: 1px solid var(--ember-accent-strong);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    outline: none;
    font-family: inherit;
}

.panel-title-input:focus {
    box-shadow: 0 0 0 2px rgba(107, 155, 209, 0.3);
}

.panel.dragging-panel .panel-title {
    color: #90ceff;
    text-shadow: 0 0 8px rgba(107, 155, 209, 0.4);
}

.panel.dragging-panel .panel-title {
    color: #90ceff;
    text-shadow: 0 0 8px rgba(107, 155, 209, 0.4);
}

.panel.drag-over .panel-title {
    color: var(--ember-accent-strong);
}

.panel-drag-handle {
    position: relative;
    height: 20px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(107, 155, 209, 0.15);
    cursor: grab;
    user-select: none;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 0.6rem;
    box-sizing: border-box;
}

.panel-drag-handle::after {
    content: '☰';
    position: absolute;
    right: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ember-accent-strong);
    font-size: 1.5rem;
    opacity: 0.5;
    transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    line-height: 1;
    padding: 0;
}

.panel-drag-handle:hover {
    background: rgba(107, 155, 209, 0.1);
    border-bottom-color: rgba(107, 155, 209, 0.3);
}

.panel-drag-handle:hover::after {
    opacity: 1;
    color: #90ceff;
}

.panel-drag-handle:active {
    cursor: grabbing;
    background: rgba(107, 155, 209, 0.2);
}

.drag-ghost {
    position: fixed;
    pointer-events: none;
    background: #0a0a0a;
    border: 1px solid var(--ember-accent-strong);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(107, 155, 209, 0.6);
    opacity: 0.85;
    padding: 0.4rem 0.6rem;
    color: var(--ember-accent-strong);
    font-weight: 600;
    font-size: 0.85rem;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    z-index: 10000;
    transform: scale(1);
}

.panel-body {
    padding: 0.9rem;
    color: #9aa0a6;
    font-size: 0.9rem;
    flex: 1;
    min-height: 0;
}

.panel-placeholder {
    color: #9aa0a6;
}

.notes-wrap {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
}

.notes-toolbar-spacer {
    flex: 1 1 auto;
}

.notes-toolbar {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    align-items: center;
    padding: 0.35rem;
    background: #121212;
    border: 1px solid #2d2d2d;
    border-radius: 6px;
    overflow-x: auto;
}

.notes-tool-btn,
.notes-format-select {
    background: #1d1d1d;
    color: #ffffff;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    font-size: 0.78rem;
    line-height: 1;
}

.notes-tool-btn {
    min-width: 28px;
    height: 28px;
    padding: 0 0.45rem;
    cursor: pointer;
    font-weight: 700;
}

.notes-format-select {
    height: 28px;
    padding: 0 0.45rem;
    font-weight: 500;
}

.notes-tool-btn:hover,
.notes-format-select:hover,
.notes-tool-btn:focus,
.notes-format-select:focus {
    border-color: var(--ember-accent-strong);
    color: #e8f3ff;
    outline: none;
}

.notes-theme-toggle {
    min-width: 38px;
    font-size: 0.95rem;
    padding: 0;
}

.notes-wrap[data-theme="light"] .notes-toolbar {
    background: #f4eadc;
    border-color: #d8c6ae;
}

.notes-wrap[data-theme="light"] .notes-tool-btn,
.notes-wrap[data-theme="light"] .notes-format-select {
    background: #fffaf2;
    color: #000000;
    border-color: #cdbca6;
}

.notes-wrap[data-theme="light"] .notes-tool-btn:hover,
.notes-wrap[data-theme="light"] .notes-format-select:hover,
.notes-wrap[data-theme="light"] .notes-tool-btn:focus,
.notes-wrap[data-theme="light"] .notes-format-select:focus {
    color: #000000;
}

.notes-wrap[data-theme="dark"] .notes-tool-btn,
.notes-wrap[data-theme="dark"] .notes-format-select {
    box-shadow: inset 0 0 0 0 rgba(137, 192, 255, 0);
}

.notes-wrap[data-theme="dark"] .notes-tool-btn:hover,
.notes-wrap[data-theme="dark"] .notes-tool-btn:focus,
.notes-wrap[data-theme="dark"] .notes-format-select:hover,
.notes-wrap[data-theme="dark"] .notes-format-select:focus {
    background: #263446;
}

.notes-wrap[data-theme="light"] .notes-tool-btn:hover,
.notes-wrap[data-theme="light"] .notes-tool-btn:focus,
.notes-wrap[data-theme="light"] .notes-format-select:hover,
.notes-wrap[data-theme="light"] .notes-format-select:focus {
    background: #f2e5d2;
}

.notes-editor {
    flex: 1;
    min-height: 100px;
    border: 1px solid #2d2d2d;
    border-radius: 6px;
    background: #101010;
    color: #ffffff;
    padding: 0.6rem 0.7rem;
    overflow: auto;
    line-height: 1.5;
}

.notes-editor,
.notes-editor * {
    color: inherit;
}

.notes-editor h1,
.notes-editor h2,
.notes-editor h3 {
    margin: 0.35rem 0 0.2rem;
    line-height: 1.25;
}

.notes-editor h1 {
    font-size: 1.28rem;
}

.notes-editor h2 {
    font-size: 1.14rem;
}

.notes-editor h3 {
    font-size: 1.03rem;
}

.notes-editor:focus {
    border-color: var(--ember-accent-strong);
    box-shadow: 0 0 0 2px rgba(107, 155, 209, 0.22);
    outline: none;
}

.notes-editor:empty::before {
    content: "Write session notes here...";
    color: #6f6f6f;
}

.notes-editor ul,
.notes-editor ol {
    margin: 0.35rem 0;
    padding-left: 1.6rem;
    list-style-position: outside;
}

.notes-editor li {
    margin: 0.12rem 0;
}

.notes-editor li::marker {
    color: inherit;
}

.notes-editor blockquote {
    border-left: 3px solid var(--ember-accent-strong);
    margin: 0.35rem 0;
    padding-left: 0.55rem;
}

.notes-wrap[data-theme="light"] .notes-editor {
    background: #fffaf0;
    border-color: #d8c6ae;
    color: #000000;
}

.notes-wrap[data-theme="light"] .notes-editor:focus {
    box-shadow: 0 0 0 2px rgba(136, 92, 41, 0.18);
}

.notes-wrap[data-theme="light"] .notes-editor:empty::before {
    color: #8c7d6b;
}

.sketch-wrap {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
}

.sketch-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem;
    background: #121212;
    border: 1px solid #2d2d2d;
    border-radius: 6px;
}

.sketch-tool-btn,
.sketch-size-input,
.sketch-clear-btn {
    background: #1d1d1d;
    color: #d7d7d7;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    height: 28px;
}

.sketch-tool-btn,
.sketch-clear-btn {
    padding: 0 0.55rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.sketch-tool-btn:hover,
.sketch-clear-btn:hover,
.sketch-size-input:hover,
.sketch-tool-btn:focus,
.sketch-clear-btn:focus,
.sketch-size-input:focus {
    border-color: var(--ember-accent-strong);
    outline: none;
}

.sketch-tool-btn.is-active {
    border-color: var(--ember-accent-strong);
    background: linear-gradient(180deg, rgba(107, 155, 209, 0.42), rgba(107, 155, 209, 0.22));
    color: #e8f3ff;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.08),
        0 0 0 2px rgba(107, 155, 209, 0.18),
        0 0 0 4px rgba(159, 211, 255, 0.18);
    transform: translateY(-1px) scale(1.08);
    z-index: 1;
}

.sketch-tool-btn.is-active:hover,
.sketch-tool-btn.is-active:focus {
    border-color: #9fd3ff;
    background: linear-gradient(180deg, rgba(107, 155, 209, 0.52), rgba(107, 155, 209, 0.28));
}

.sketch-tool-btn.is-active::after {
    content: "";
    position: absolute;
    inset: -2px;
    border-radius: 6px;
    border: 1px solid rgba(159, 211, 255, 0.25);
    pointer-events: none;
}

.sketch-tool-btn {
    position: relative;
}

.sketch-tool-btn.is-active:active {
    transform: translateY(0) scale(1.08);
}

.sketch-size-input {
    width: 100px;
    cursor: pointer;
    padding: 0 0.2rem;
}

.sketch-color-input {
    width: 30px;
    height: 28px;
    padding: 0;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    background: #101010;
    cursor: pointer;
}

.sketch-color-input:hover,
.sketch-color-input:focus {
    border-color: var(--ember-accent-strong);
    outline: none;
}

.sketch-canvas-wrap {
    flex: 1;
    min-height: 0;
    border: 1px solid #2d2d2d;
    border-radius: 6px;
    background: #ffffff;
    overflow: hidden;
}

.sketch-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
    background: #ffffff;
}

.web-wrap {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
}

.web-toolbar {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    padding: 0.35rem;
    background: #121212;
    border: 1px solid #2d2d2d;
    border-radius: 6px;
}

.web-url-input {
    flex: 1;
    min-width: 0;
    height: 30px;
    background: #0f0f0f;
    color: #e2e2e2;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    padding: 0 0.6rem;
    font-size: 0.82rem;
}

.web-url-input:focus {
    outline: none;
    border-color: var(--ember-accent-strong);
}

.web-action-btn {
    height: 30px;
    padding: 0 0.7rem;
    background: #1d1d1d;
    color: #d7d7d7;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.web-action-btn:hover,
.web-action-btn:focus {
    border-color: var(--ember-accent-strong);
    color: #e8f3ff;
    outline: none;
}

.web-frame-wrap {
    flex: 1;
    min-height: 0;
    border: 1px solid #2d2d2d;
    border-radius: 6px;
    overflow: hidden;
    background: #ffffff;
    position: relative;
}

.web-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #ffffff;
}

.web-status {
    color: #9aa0a6;
    font-size: 0.82rem;
    padding: 0.45rem 0.55rem;
}

.local-file-input {
    display: none;
}

.local-file-name {
    flex: 1;
    min-width: 0;
    color: #c7d5e4;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 0.2rem;
}

.local-file-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: none;
    background: #ffffff;
}

.local-file-pdf {
    display: none;
}

.panel-grid-empty {
    grid-column: 1 / -1;
    border: 1px dashed #3a3a3a;
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
    color: #9aa0a6;
    background: rgba(255, 255, 255, 0.01);
    font-size: 0.95rem;
}

.panel-handle {
    position: absolute;
    background: transparent;
}

.panel-handle--n,
.panel-handle--s {
    left: 6px;
    right: 6px;
    height: 8px;
}

.panel-handle--n {
    top: 0;
    cursor: ns-resize;
}

.panel-handle--s {
    bottom: 0;
    cursor: ns-resize;
}

.panel-handle--e,
.panel-handle--w {
    top: 6px;
    bottom: 6px;
    width: 8px;
}

.panel-handle--e {
    right: 0;
    cursor: ew-resize;
}

.panel-handle--w {
    left: 0;
    cursor: ew-resize;
}

.panel-handle--n {
    border-top: 2px solid var(--ember-accent-strong);
}

.panel-handle--s {
    border-bottom: 2px solid var(--ember-accent-strong);
}

.panel-handle--w {
    border-left: 2px solid var(--ember-accent-strong);
}

.panel-handle--e {
    border-right: 2px solid var(--ember-accent-strong);
}

.panel-handle--n:hover,
.panel-handle--s:hover,
.panel-handle--e:hover,
.panel-handle--w:hover {
    background: rgba(107, 155, 209, 0.15);
    box-shadow: inset 0 0 0 1px rgba(107, 155, 209, 0.75);
}

@media (max-width: 1100px) {
    body {
        padding: 1rem;
    }

    .screen-shell {
        padding: 1rem;
    }

    .screen-header {
        align-items: flex-start;
    }

    .screen-controls {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0.7rem;
    }

    .panel-controls {
        justify-content: space-between;
    }

    .settings-controls {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
        align-items: center;
    }

    .settings-label,
    .layout-setting-select {
        grid-column: 1 / -1;
    }

    .layout-setting-select {
        width: 100%;
        min-width: 0;
    }

    .layout-action-btn {
        width: 100%;
        min-height: 34px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 0.75rem;
    }

    .page-generator-title {
        margin: 1rem 0 0.8rem;
        font-size: 1.25rem;
    }

    .screen-shell {
        border-radius: 8px;
        padding: 0.75rem;
    }

    .panel-grid {
        grid-template-columns: minmax(0, 1fr);
        grid-auto-rows: minmax(240px, auto);
        gap: 0.75rem;
        padding-bottom: 28vh;
    }

    .panel {
        min-height: 240px;
        grid-column: 1 / -1 !important;
    }

    .panel-header {
        padding: 0.45rem 0.6rem;
    }

    .panel-header-content {
        align-items: flex-start;
        gap: 0.45rem;
    }

    .panel-title {
        width: 100%;
        font-size: 0.9rem;
    }

    .panel-actions {
        width: 100%;
        margin-left: 0;
        gap: 0.45rem;
    }

    .panel-type-select {
        flex: 1 1 auto;
        min-height: 34px;
    }

    .panel-close-btn {
        width: 30px;
        height: 30px;
        min-width: 30px;
        min-height: 30px;
    }

    .panel-handle--e,
    .panel-handle--w {
        display: none;
    }

    .web-toolbar {
        flex-wrap: wrap;
        align-items: stretch;
    }

    .web-url-input {
        flex: 1 1 100%;
        height: 34px;
    }

    .web-action-btn,
    .sketch-tool-btn,
    .sketch-clear-btn {
        min-height: 34px;
    }

    .web-action-btn {
        flex: 1 1 calc(50% - 0.2rem);
    }

    .local-file-name {
        flex: 1 1 100%;
        order: 99;
    }
}

@media (max-width: 480px) {
    .settings-controls {
        grid-template-columns: 1fr;
    }

    .panel-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .screen-meta,
    .add-panel-btn {
        width: 100%;
    }

    .add-panel-btn {
        min-height: 36px;
    }

    .web-action-btn {
        flex-basis: 100%;
    }
}
