/* ============================================================
   CECG — Cepheus Engine Character Generator
   Tile-based responsive UI
   ============================================================ */

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

:root {
    --bg: #1a1a2e;
    --bg-surface: #16213e;
    --bg-tile: #0f3460;
    --bg-tile-header: #1a1a4e;
    --accent: #e94560;
    --text: #eee;
    --text-muted: #999;
    --border: #2a2a5e;
    --radius: 8px;
    --shadow: 0 4px 12px rgba(0,0,0,0.4);
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ============================================================
   APP HEADER
   ============================================================ */

.app-header {
    text-align: center;
    padding: 1.5rem 1rem 1rem;
    background: var(--bg-surface);
    border-bottom: 2px solid var(--accent);
}

.app-title {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text);
}

.app-subtitle {
    font-size: 0.95rem;
    color: var(--accent);
    font-weight: 400;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-top: 0.2rem;
}

/* ============================================================
   WORKSPACE — contains all tiles
   ============================================================ */

.workspace {
    padding: 1rem;
    min-height: calc(100vh - 100px);
}

/* ============================================================
   TILES
   ============================================================ */

.tile {
    background: var(--bg-tile);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow var(--transition);
}

.tile:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}

.tile.flash {
    box-shadow: 0 0 20px var(--accent);
}

/* Tile Header */
.tile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.8rem;
    background: var(--bg-tile-header);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.tile-title {
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.tile-controls {
    display: flex;
    gap: 0.4rem;
}

.tile-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.tile-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Tile Body */
.tile-body {
    padding: 0.8rem;
    overflow: auto;
}

.tile.minimized .tile-body {
    display: none;
}

.tile.minimized {
    border-radius: var(--radius);
}

/* Tile collapse arrow */
.tile-arrow {
    margin-right: 0.5rem;
    font-size: 0.7rem;
    transition: transform var(--transition);
    display: inline-block;
}

.tile.minimized .tile-arrow {
    transform: rotate(-90deg);
}

/* ============================================================
   DEMO CONTENT INSIDE TILES
   ============================================================ */

.tile-demo {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

/* Generate button */
.btn-generate {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.03em;
}

.btn-generate:hover {
    background: #ff5577;
    transform: translateY(-1px);
}

.btn-generate:active {
    transform: translateY(0);
}

/* Form fields */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.field-group label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.field-group select,
.field-group input {
    background: var(--bg-surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.5rem 0.6rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
}

.field-group select:focus,
.field-group input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Character sheet */
.sheet-line {
    padding: 0.15rem 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.sheet-line.mono {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    letter-spacing: 0.1em;
}

.sheet-section {
    font-size: 0.75rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: 0.3rem;
    font-weight: 600;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.4rem 0;
}

/* History log */
.log-entry {
    padding: 0.2rem 0;
    font-size: 0.85rem;
    line-height: 1.4;
    color: var(--text-muted);
    border-left: 2px solid var(--border);
    padding-left: 0.6rem;
    margin-bottom: 0.15rem;
}

.log-entry:nth-child(odd) {
    color: var(--text);
}

/* ============================================================
   PHONE LAYOUT (< 768px) — Accordion
   ============================================================ */

@media (max-width: 767px) {
    .app-header {
        padding: 1rem 0.8rem 0.8rem;
    }

    .app-title {
        font-size: 1.4rem;
    }

    .app-subtitle {
        font-size: 0.8rem;
    }

    .workspace {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .tile {
        width: 100%;
    }

    /* On phone, minimize/maximize buttons hidden — just tap header to toggle */
    .tile-btn-min,
    .tile-btn-max {
        display: none;
    }
}

/* ============================================================
   TABLET LAYOUT (768px – 1400px) — Two-column grid
   ============================================================ */

@media (min-width: 768px) and (max-width: 1400px) {
    .workspace {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.8rem;
        padding: 0.8rem;
    }

    .tile {
        width: 100%;
    }

    /* Let a tile span both columns if needed */
    .tile.wide {
        grid-column: span 2;
    }
}

/* ============================================================
   DESKTOP LAYOUT (> 1400px) — Free-form draggable windows
   ============================================================ */

@media (min-width: 1401px) {
    .workspace {
        position: relative;
        min-height: calc(100vh - 100px);
        padding: 1rem;
    }

    .tile {
        position: absolute;
        min-width: 280px;
        min-height: 150px;
        resize: both;
        overflow: auto;
    }

    .tile-header {
        cursor: grab;
    }

    .tile-header:active {
        cursor: grabbing;
    }

    /* Default positions for the 3 demo tiles */
    #tile-generate {
        left: 20px;
        top: 10px;
        width: 300px;
    }

    #tile-character-sheet {
        left: 340px;
        top: 10px;
        width: 420px;
    }

    #tile-history-log {
        left: 20px;
        top: 340px;
        width: 740px;
    }
}

/* ============================================================
   LAYOUT INDICATOR (shows current mode for testing)
   ============================================================ */

.layout-indicator {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    padding: 0.4rem;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    z-index: 1000;
}

/* ============================================================
   PRINT
   ============================================================ */

@media print {
    .app-header { border: none; }
    .tile { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
    .tile-controls { display: none; }
    .layout-indicator { display: none; }
    body { background: #fff; color: #000; }
}
