/* styles.css */
body { 
    margin: 0; 
    overflow: hidden; 
    font-family: 'Segoe UI', Roboto, sans-serif; 
    background-color: #121212; 
    color: #e0e0e0; 
    user-select: none; 
}

/* --- PANELS --- */
.panel {
    background: rgba(30, 30, 30, 0.95); 
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    z-index: 10;
    display: flex;
    flex-direction: column;
    transition: max-height 0.3s ease;
    overflow: visible; 
    border: 1px solid #444;
}

.panel-header {
    padding: 12px 15px;
    font-size: 24px; 
    font-weight: 800;
    color: #ffffff;
    border-bottom: 1px solid #444;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #252525;
    border-radius: 8px 8px 0 0;
    user-select: none;
    min-height: 50px; 
}
.panel-header:hover { background: #333; }

.panel-header-text {
    display: block; 
    white-space: nowrap;
}

.panel-body { padding: 12px; overflow-y: auto; max-height: 70vh; }
.panel.collapsed .panel-body { display: none; }
.panel.collapsed { max-height: 80px; overflow: hidden; } 
.arrow { font-size: 12px; color: #aaa; transition: transform 0.2s; }
.rotate-90 { transform: rotate(-90deg); }

/* --- SUB-SECTIONS --- */
.sub-header {
    background: #333; 
    padding: 10px 12px;
    font-weight: 700; 
    font-size: 18px; 
    color: #ffffff; 
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    margin-top: 10px;
    border: 1px solid #444;
    user-select: none;
}
.sub-header:hover { background: #444; }
.sub-content { padding: 5px; display: block; } 
.sub-content.collapsed { display: none; }

/* Positions */
#ui-panel { position: absolute; top: 20px; left: 20px; width: 340px; }
#gen-panel { position: absolute; top: 20px; right: 20px; width: 340px; } 
/* Increased min-width for Palette Panel to accommodate larger grid */
#palette-panel { position: absolute; bottom: 20px; left: 20px; width: auto; min-width: 340px; }

/* --- TEXT VISIBILITY OVERRIDES --- */
.panel-body label, .sub-content label {
    color: #ffffff !important;
    font-size: 16px !important; 
    font-weight: 600 !important;
    margin-bottom: 6px !important;
}

/* --- KIT SELECTION ROW (INSIDE FLYOUT) --- */
.kit-type-row {
    display: flex;
    gap: 4px; /* Tighter gap for flyout */
    margin-bottom: 10px;
    background: #222;
    padding: 4px;
    border-radius: 4px;
    border: 1px solid #444;
}

.kit-type-btn {
    flex: 1;
    padding: 8px 2px; /* Reduced side padding to fit text */
    font-size: 12px;  /* Slightly smaller to ensure fit */
    font-weight: 800; 
    text-align: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    color: #aaa;
    transition: all 0.2s;
    white-space: nowrap; /* Prevent wrapping */
}
.kit-type-btn:hover { color: #fff; background: #333; }
.kit-type-btn.active {
    background: #1976D2;
    color: #fff;
    border-color: #1565C0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* --- 4 COLUMN PALETTE GRID --- */
.palette-grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr); 
    gap: 15px; /* Increased gap */
    padding: 8px;
}
.main-color-circle {
    width: 48px; height: 48px; /* Larger circles */
    border-radius: 50%;
    border: 2px solid #444;
    box-shadow: 0 2px 5px rgba(0,0,0,0.4);
    cursor: pointer;
    transition: transform 0.1s;
    position: relative;
    margin: 0 auto;
}
.main-color-circle:hover { transform: scale(1.1); z-index: 2; border-color: #fff; }
.main-color-circle.active-parent {
    box-shadow: 0 0 0 3px #ffffff; 
    z-index: 5;
    transform: scale(1.05);
}

/* Flyout Menu */
#palette-flyout {
    position: absolute; left: 100%; top: 0; margin-left: 15px;
    background: #252525; padding: 10px; border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5); display: none; 
    flex-direction: column; gap: 5px; width: 260px; z-index: 20;
    border: 1px solid #444;
}
/* New class for bottom alignment */
#palette-flyout.align-bottom {
    top: auto;
    bottom: 0;
}
#palette-flyout.visible { display: flex; }

.sub-color-item {
    display: flex; align-items: center; padding: 8px; 
    border-radius: 4px; cursor: pointer; justify-content: space-between;
    color: #eee;
}
.sub-color-item:hover { background: #333; }
.sub-color-left { display: flex; align-items: center; }

.sub-color-left span { font-size: 15px !important; font-weight: 600; }

.sub-swatch {
    width: 24px; height: 24px; border-radius: 50%; 
    border: 1px solid #555; box-shadow: inset 0 0 2px rgba(0,0,0,0.5);
    margin-right: 10px;
}
.sub-color-item.active .sub-swatch { box-shadow: 0 0 0 2px #ffffff; border-color: #fff; }

.kit-controls { display: flex; align-items: center; gap: 4px; }
.kit-btn {
    width: 24px; height: 24px; border: 1px solid #555; background: #444;
    border-radius: 4px; cursor: pointer; font-size: 14px; line-height: 1;
    display: flex; justify-content: center; align-items: center; color: #fff;
}
.kit-btn:hover { background: #555; }
.kit-val { font-size: 13px; font-weight: bold; width: 20px; text-align: center; color: #eee; }

/* --- PARAMETERS --- */
.gen-input-row { display: flex; gap: 10px; margin-bottom: 10px; align-items: center; }
.gen-input-group { flex: 1; display: flex; align-items: center; justify-content: flex-end; }

.gen-input-group label { 
    margin-bottom: 0; margin-right: 8px; white-space: nowrap; 
    font-size: 15px !important; 
    color: #ffffff !important;
    flex: 1; text-align: left; 
}

.gen-input-group input[type="number"], .gen-input-group select { 
    width: 75px; padding: 4px 6px; height: 32px; 
    border: 1px solid #555; background: #333; color: #fff;
    border-radius: 4px; font-size: 14px; box-sizing: border-box; 
}

/* --- INTEGRATED BOX STYLING FOR DIMENSIONS --- */
#group-width, #group-height {
    background: #333; 
    border: 1px solid #555;
    border-radius: 4px;
    padding: 6px 8px;
    display: flex;
    align-items: center; 
    justify-content: space-between;
}

#group-width input, #group-height input {
    border: none !important;
    background: transparent !important;
    width: 50px !important;
    padding: 0 5px 0 0 !important;
    height: auto !important;
    text-align: right;
    font-weight: 700;
}
#group-width input:disabled, #group-height input:disabled {
    opacity: 1;
    color: #fff;
    padding-right: 0 !important;
}

.spinner-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-left: 5px; 
}

#group-width input:disabled ~ .spinner-btns, 
#group-height input:disabled ~ .spinner-btns {
    display: none;
}

.spin-btn {
    width: 18px;
    height: 14px;
    background-color: #777; 
    color: #000;           
    border: none;
    border-radius: 2px;
    font-size: 10px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.1s;
}
.spin-btn:hover { background-color: #999; }
.spin-btn:active { background-color: #bbb; }

.gen-input-group input[type="number"]::-webkit-outer-spin-button,
.gen-input-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none; margin: 0;
}
.gen-input-group input[type="number"] { -moz-appearance: textfield; }

#group-width label, #group-height label {
    margin: 0 !important;
    font-size: 15px !important;
    color: #ddd !important;
}

.gen-input-group input[type="range"] { width: 100px; margin: 0; accent-color: #1976D2; }

/* --- THICKNESS INDENTED SECTION --- */
#gen-thick-row {
    margin-left: 0px; /* ALIGN WITH WIDTH BOX */
    padding-left: 12px;
    border-left: 4px solid #555; /* Thicker, aligned line */
    padding-top: 8px;
    margin-top: 15px !important;
    border-top: 1px dashed #444;
}

/* Param Toggle */
.param-toggle { display: flex; background: #222; border-radius: 4px; margin-bottom: 12px; padding: 2px; border: 1px solid #444; }
.param-opt { 
    flex: 1; text-align: center; 
    font-size: 16px; 
    font-weight: 700; 
    padding: 10px; cursor: pointer; color: #888; border-radius: 3px; 
}
.param-opt.active { background: #1976D2; color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.hidden-opt { display: none !important; }

.gen-input-group > div > label {
    font-weight: 800 !important;
    font-size: 15px !important;
}
.info-span { 
    font-size: 14px !important; 
    color: #ffffff !important; 
    font-weight: 400 !important; 
}

/* --- SHAPE GRID --- */
.shape-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }

.shape-btn { 
    padding: 10px 2px; 
    border: 1px solid #aaa; 
    background: #d6d6d6; 
    color: #000000;      
    border-radius: 4px; 
    font-size: 13px; /* Reduced from 14px */
    font-weight: 700; 
    cursor: pointer; 
    text-align: center; 
    transition: background 0.2s;
    white-space: nowrap;
}
.shape-btn:hover { background: #ffffff; }
.shape-btn.active { 
    background: #1976D2; 
    color: white; 
    border-color: #1565C0; 
}

/* --- STYLE SWITCH (UPDATED TO GRID) --- */
.style-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: #222;
    border-radius: 6px;
    padding: 4px;
    margin-bottom: 14px;
    border: 1px solid #444;
}
.style-btn {
    padding: 10px;
    border: none;
    background: transparent;
    color: #888;
    font-weight: 700;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: all 0.2s;
    text-align: center;
}
.style-btn:hover { background: #333; color: #ddd; }
.style-btn.active {
    background: #1976D2;
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}


/* --- KIT LIST --- */
#kit-list-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 5px; color: #ddd; }
#kit-list-table th { text-align: left; border-bottom: 1px solid #555; padding: 6px; color: #fff; font-size: 15px; }
/* Set text color to white for table cells */
#kit-list-table td { padding: 8px 6px; border-bottom: 1px solid #333; vertical-align: middle; color: #ffffff; }
#kit-list-foot { font-weight: bold; background: #252525; border-top: 2px solid #555; }
.gen-empty-msg { font-size: 13px; color: #888; font-style: italic; padding: 10px; text-align: center; }

/* --- CONTROLS --- */
.control-group { margin-bottom: 10px; }
.mode-switch { display: flex; background: #222; border-radius: 6px; padding: 3px; margin-bottom: 14px; border: 1px solid #444; }
.mode-opt { 
    flex: 1; text-align: center; padding: 10px; cursor: pointer; border-radius: 4px; 
    font-size: 15px; 
    font-weight: 700; color: #888; transition: 0.2s; 
}
.mode-opt.active { background: #1976D2; color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }

.action-row { display: flex; gap: 10px; margin-top: 10px; }
.action-btn { 
    flex: 1; padding: 12px; border: none; border-radius: 4px; cursor: pointer; 
    font-size: 14px; 
    font-weight: 700; color: #ccc; transition: all 0.2s; 
    background: #333; opacity: 1.0; border: 1px solid #444;
}
.action-btn:hover { background: #444; color: #fff; }

.action-btn.active { 
    background: #1976D2; 
    color: #ffffff; 
    border-color: #1565C0;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.2), 0 2px 4px rgba(0,0,0,0.3);
}
.action-btn.danger { background: #b71c1c; color: white; border-color: #b71c1c; }
.action-btn.danger:hover { background: #d32f2f; }

.share-btn-style { background: #1976d2 !important; border-color: #1565C0 !important; color: white !important; }
.share-btn-style:hover { background: #115293 !important; }

#gen-btn { 
    background: #1976D2; width: 100%; margin-bottom: 15px; 
    padding: 12px; color: white; border: none; font-weight: 700;
    font-size: 16px; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.3); cursor: pointer; border-radius: 4px;
}
#gen-btn:hover { background: #1565C0; }

#hex-counter {
    position: absolute; bottom: 20px; right: 20px;
    background: rgba(30, 30, 30, 0.95); border-radius: 8px; 
    box-shadow: 0 4px 20px rgba(0,0,0,0.5); border: 1px solid #444;
    width: 260px; z-index: 9; max-height: 50vh; 
    /* CHANGED: Removed auto scroll from parent, will be on body */
    overflow-y: hidden; 
    display: flex; flex-direction: column;
    transition: all 0.3s ease; /* added transition for overlap collapse */
}

/* NEW: Dynamic class for yellow border warning */
#hex-counter.warning-border {
    border: 2px solid #ffcc00 !important;
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.4);
}

/* CHANGED: Make header flex column to fit warning nicely */
.summary-header { 
    padding: 12px 14px; background: #252525; border-bottom: 1px solid #444; 
    font-weight: 800; cursor: pointer; display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: stretch; 
    border-radius: 8px 8px 0 0; font-size: 16px; color: #fff; 
    position: sticky;
    top: 0;
    z-index: 10;
}
/* CHANGED: The content body handles the scrolling now */
#counter-content { 
    padding: 10px; font-size: 13px; color: #ccc; 
    overflow-y: auto;
    /* max-height inherited from parent flex logic roughly, but we can set flex: 1 */
    flex: 1;
    display: none; 
}

.counter-group { margin-bottom: 6px; border: 1px solid #444; border-radius: 4px; overflow: hidden; background: #2a2a2a; }

.counter-color-label { 
    padding: 10px; background: #333; font-weight: 600; font-size: 14px; 
    cursor: pointer; display: flex; align-items: center; 
    justify-content: space-between; transition: background 0.2s; color: #eee;
}
.counter-color-label:hover { background: #444; }

.counter-details { display: none; padding: 8px 10px; background: #222; border-top: 1px solid #444; }
.counter-details.visible { display: block; }
.detail-row { display: flex; justify-content: space-between; font-size: 12px; color: #aaa; margin-bottom: 4px; border-bottom: 1px dashed #333; padding-bottom: 2px;}

/* Tooltip & Context Menu Fixed */
#tooltip { 
    position: absolute; display: none; background: rgba(10, 10, 10, 0.95); 
    color: white; padding: 8px 12px; border-radius: 6px; font-size: 12px; 
    pointer-events: none; z-index: 3000; white-space: nowrap; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.5); line-height: 1.4; border: 1px solid #444;
}

#context-menu { 
    position: fixed; display: none; background: #252525; padding: 12px; 
    border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.6); z-index: 4000; 
    width: 150px; flex-direction: column; gap: 10px; border: 1px solid #444;
}

.ctx-label { font-size: 12px; font-weight: bold; color: #ccc; margin-bottom: 4px; }
.ctx-slider { width: 100%; cursor: pointer; accent-color: #1976D2; }
.ctx-colors { display: flex; flex-wrap: wrap; gap: 6px; }
.ctx-swatch { 
    width: 22px; height: 22px; border-radius: 50%; cursor: pointer; 
    box-shadow: inset 0 0 2px rgba(0,0,0,0.5); border: 2px solid transparent; 
}
.ctx-swatch:hover { transform: scale(1.2); border-color: #fff; }
.ctx-swatch.active { border-color: #fff; }
.ctx-val { font-size: 11px; float: right; color: #aaa; }

/* New Context Menu Buttons */
.ctx-mode-row { display: flex; gap: 5px; margin-bottom: 8px; width: 100%; }
.ctx-mode-btn { 
    flex: 1; padding: 6px; font-size: 11px; text-align: center; 
    background: #333; border: 1px solid #555; border-radius: 4px; 
    cursor: pointer; color: #ccc; font-weight: 700; transition: all 0.2s;
}
.ctx-mode-btn:hover { background: #444; color: #fff; }
.ctx-mode-btn.active { background: #1976D2; color: #fff; border-color: #1976D2; }


#ui-help { 
    position: absolute; display: none; background: rgba(20, 20, 20, 0.98); 
    color: #fff; padding: 10px 14px; border-radius: 6px; font-size: 13px; 
    z-index: 200; pointer-events: none; max-width: 260px; line-height: 1.4; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.5); border: 1px solid #555; 
}

#inventory-alert {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: #252525; border-radius: 8px; box-shadow: 0 5px 30px rgba(0,0,0,0.7);
    width: 320px; padding: 25px; z-index: 2000; display: none; text-align: center; border: 1px solid #444;
}
#inventory-alert h3 { margin-top: 0; font-size: 18px; color: #ef5350; }
#inventory-alert p { font-size: 14px; color: #ccc; line-height: 1.5; margin-bottom: 20px; }
#alert-btn { background: #444; color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 13px; }
#alert-btn:hover { background: #666; }

/* --- ASYMMETRIC GRID (1.5fr / 1fr) --- */
.instructions {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 8px 12px;
    margin-top: 15px;
    padding: 12px;
    border-top: none; 
    background-color: #383838; 
    border-radius: 6px;
    border: 1px solid #555;
}

.instr-item {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    font-size: 14px; 
    color: #e0e0e0;
}

.instr-item .key {
    font-weight: 700;
    color: #ffffff; 
    margin-bottom: 2px;
    font-size: 15px; 
    white-space: nowrap;
}

.instr-item .desc {
    color: #cccccc; 
    font-size: 13px; 
    line-height: 1.2;
}

/* --- TUTORIAL --- */

/* New fixed background dimmer that sits BEHIND the panels (z-index 9) */
#tutorial-dimmer {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 8999; /* Block clicks behind tutorial */
    transition: opacity 0.5s ease; /* SMOOTH FADE */
    opacity: 1;
}

/* Overlay holds the Text/Spotlight. High Z-index but transparent bg */
#tutorial-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    /* removed background color */
    z-index: 9000;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none; /* Allow clicks to pass through to Panels */
}

#tutorial-welcome {
    background: #252525;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 25px rgba(0,0,0,0.8);
    border: 1px solid #555;
    max-width: 400px;
    pointer-events: auto; /* Re-enable clicks for welcome box */
}

#tutorial-welcome h2 { margin-top: 0; color: #fff; }

#tutorial-spotlight {
    position: absolute;
    border: 3px solid #1976D2;
    box-shadow: 0 0 20px 5px rgba(25, 118, 210, 0.5), inset 0 0 10px rgba(0,0,0,0.5);
    background: transparent;
    z-index: 9001;
    pointer-events: none;
    border-radius: 4px;
    transition: all 0.3s ease;
    /* CHANGED: box-sizing ensures border is part of the width/height calculations */
    box-sizing: border-box;
}

#tutorial-tooltip-box {
    position: absolute;
    background: #1976D2;
    color: white;
    padding: 15px;
    border-radius: 8px;
    width: 250px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 9002;
    font-size: 14px;
    line-height: 1.5;
    transition: all 0.3s ease;
    pointer-events: auto; /* Re-enable clicks for "Next" button */
}

/* Animation for Simulated Click */
@keyframes simClickPulse {
    0% { transform: scale(1); box-shadow: 0 2px 5px rgba(0,0,0,0.4); }
    50% { transform: scale(0.9); box-shadow: 0 0 0 3px #ffffff, 0 0 10px #1976D2; border-color: #fff; }
    100% { transform: scale(1); box-shadow: 0 2px 5px rgba(0,0,0,0.4); }
}

.sim-click-anim {
    animation: simClickPulse 1.5s ease-in-out 3; /* CHANGED to 3 times only */
    z-index: 9005 !important; /* Ensure it stays on top while pulsing */
}

/* Toast Message */
#toast-msg {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #4caf50;
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 15px;
    z-index: 10000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
#toast-msg.show {
    opacity: 1;
}

/* --- COPYRIGHT NOTICE --- */
#copyright-notice {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    z-index: 100;
    pointer-events: none; /* Let clicks pass right through */
    user-select: none;
}