/* --- Root Variables - ELTcation Color Palette --- */
:root {
    /* Primary colors from logo */
    --primary-coral: #FF6B47; /* Main coral from logo */
    --primary-navy: #2C3E50; /* Deep navy from logo frame */
    --primary-dark: #1A252F; /* Darker navy for depth */
    --accent-white: #FFFFFF;
    --accent-light: #F8F9FA;
    --text-link: var(--primary-dark);
    
    /* Canvas and backgrounds */
    --canvas-bg: #FFFFFF;
    --node-text-stroke: none;
    --app-bg: linear-gradient(135deg, #2C3E50 0%, #34495E 100%);
    --dock-bg: rgba(255, 255, 255, 0.95);
    --dock-shadow: rgba(44, 62, 80, 0.3);
    
    /* Interactive elements */
    --btn-bg: rgba(255, 107, 71, 0.1);
    --btn-hover: rgba(255, 107, 71, 0.2);
    --btn-active: #FF6B47;
    --btn-border: rgba(255, 107, 71, 0.3);
    
    /* Node colors - harmonized with logo */
    --meaning-color: #E8A87C; /* Warm beige */
    --context-color: #1ABC9C; /* A nice turquoise/teal */
    --derivative-color: #F39C12; /* Golden orange */
    --idiom-color: #3498DB; /* Bright blue */
    --collocation-color: #2ECC71; /* Fresh green */
    --synonym-color: #9B51E0; /* Purple */
    --opposite-color: #E74C3C; /* Red */
    --translation-color: #8E44AD;
    
    /* Text colors */
    --text-light: #FFFFFF;
    --dock-text-color: #2C3E50; 
    --canvas-text-color: #2C3E50;
    --text-muted: #7F8C8D;
    --text-secondary: #BDC3C7; /* Added for links */
}


/* --- Canvas Theme Control --- */
:root {
    --canvas-bg: #FFFFFF;
    --text-dark: #2C3E50; 
}

[data-theme='dark'] {
    --canvas-bg: var(--primary-dark);
    --canvas-text-color: var(--accent-light);
    --text-link: var(--accent-white);
}

/* --- Input Field Theming & Overlay --- */
.input-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    pointer-events: none; opacity: 0; visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.input-overlay.visible {
    opacity: 1; visibility: visible; pointer-events: auto;
}

/* --- Input Field Error Styling --- */
.overlay-input-field.error {
  border-color: #e74c3c; /* A clear, friendly red */
  animation: shake 0.5s ease-in-out;
}

.overlay-input-field.error::placeholder {
  color: #e74c3c;
  opacity: 0.7;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
  40%, 60% { transform: translate3d(3px, 0, 0); }
}

/* FIX: Add styles for the new wrapper */
.input-wrapper {
    position: relative;
    width: 80%;
    max-width: 500px;
    display: flex;
    align-items: center;
}

.overlay-input-field {
    width: 100%; /* FIX: Take full width of the wrapper */
    box-sizing: border-box;
    /* FIX: Add more padding on the right for the mic button */
    padding: 15px 60px 15px 25px; 
    border: 2px solid var(--primary-coral); border-radius: 12px;
    background-color: var(--canvas-bg); color: var(--canvas-text-color);
    font-family: inherit; font-size: 1.3rem; text-align: center;
    outline: none; box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    transform: scale(0.95); transition: all 0.3s ease;
}
.input-overlay.visible .overlay-input-field { transform: scale(1); }
[data-theme='dark'] .overlay-input-field {
    background-color: #2C3E50; color: var(--text-light); border-color: var(--primary-coral);
}

/* --- Icon Visibility Control --- */
.sun-icon { display: block; }
.moon-icon { display: none; }
[data-theme='dark'] .sun-icon { display: none; }
[data-theme='dark'] .moon-icon { display: block; }

/* --- Global & App Layout Styles --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
    background: var(--app-bg); color: var(--text-light); overflow: hidden;
    height: 100vh; position: relative;
}
body::before {
    content: ''; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(255, 107, 71, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 107, 71, 0.05) 0%, transparent 50%);
    pointer-events: none; z-index: -1;
}
#app-wrapper {
    width: 100%; height: 100%; display: flex; flex-direction: column; padding: 20px; gap: 20px;
}
main#graph-panel { flex-grow: 1; min-height: 0; position: relative; }

/* --- Header --- */
header { flex-shrink: 0; text-align: center; position: relative; }
.title-container {
    display: inline-flex; align-items: center; background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px); border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 15px 30px; border-radius: 20px; color: white;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); transition: all 0.3s ease;
}
.title-container:hover { transform: translateY(-2px); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4); }
.header-logo { height: 45px; margin-right: 20px; filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3)); }
header h1 {
    font-size: 2.2rem; font-weight: 700;
    background: linear-gradient(135deg, #FFFFFF 0%, #FF6B47 100%);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

/* --- Graph Canvas --- */
#graph-container {
    width: 100%; height: 100%; background: var(--canvas-bg); border-radius: 25px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    overflow: hidden; position: relative; border: 1px solid rgba(255, 107, 71, 0.2);
    transition: background-color 0.4s ease; /* Smooth theme transition */
}
#wordsplainer-graph-svg { width: 100%; height: 100%; cursor: grab; }
#wordsplainer-graph-svg:active { cursor: grabbing; }

/* --- Controls Dock --- */
#controls-dock {
    flex-shrink: 0; background: var(--dock-bg); backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 107, 71, 0.2); border-radius: 25px; padding: 20px 25px;
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 10px 40px var(--dock-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    position: relative; overflow: hidden;
}
.category-buttons, .utility-buttons { display: flex; gap: 12px; }
.category-btn {
    background: var(--btn-bg); border: 1px solid var(--btn-border); color: var(--dock-text-color);
    border-radius: 16px; padding: 12px 8px; cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    min-width: 100px; position: relative; overflow: hidden;
}
.category-btn:hover {
    background: var(--btn-hover); transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(255, 107, 71, 0.3); border-color: var(--primary-coral);
}
.category-btn.active {
    background: var(--btn-active); color: var(--text-light); font-weight: 600;
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(255, 107, 71, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.color-dot-container {
    width: 45px; height: 45px; background: rgba(255, 255, 255, 0.15);
    border-radius: 12px; display: flex; justify-content: center; align-items: center;
    transition: all 0.3s ease;
}
.category-btn:hover .color-dot-container { transform: scale(1.1); }
.color-dot {
    width: 28px; height: 28px; border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); transition: all 0.3s ease;
}
.category-btn:hover .color-dot { transform: scale(1.1); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); }
.category-btn span { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

/* ===== START OF ENHANCED D3 STYLES SECTION ===== */

.status-text { 
    fill: var(--primary-coral); 
    text-anchor: middle; 
    font-size: 1.3rem; 
    font-weight: 500;
}
.error-text { 
    fill: var(--opposite-color); 
    font-weight: 500;
}

.link { 
    /* Base style, JS will override for specific types */
    stroke: var(--text-secondary, #BDC3C7); 
    stroke-opacity: 0.6; 
    stroke-width: 1px; 
    transition: stroke 0.3s ease, stroke-width 0.3s ease, opacity 0.3s ease;
}

.node { 
    cursor: pointer; 
    /* This transition is KEY for smooth JS-driven animations */
    transition: transform 0.3s ease, filter 0.3s ease;
}

.node text { 
    font-size: 13px; 
    font-weight: 600; 
    text-anchor: middle; 
    dominant-baseline: central; 
    pointer-events: none; 
    fill: var(--canvas-text-color); 
    transition: fill 0.3s ease;
}

/* --- Central Node --- */
.node.central-node circle { 
    fill: var(--primary-coral);
    stroke: rgba(255, 255, 255, 0.5);
    stroke-width: 2px;
    transition: all 0.3s ease;
}
.node.central-node.active-central > circle {
    stroke: white;
    stroke-width: 4px;
}

/* --- Peripheral Nodes --- */
.node:not(.central-node):not(.node-example) circle {
    stroke: rgba(0, 0, 0, 0.1);
    stroke-width: 1px;
    transition: stroke 0.3s ease, stroke-width 0.3s ease;
}
[data-theme='dark'] .node:not(.central-node):not(.node-example) circle {
    stroke: rgba(255, 255, 255, 0.2);
}

/* Node Colors */
.node.node-meaning circle { fill: var(--meaning-color); }
.node.node-context circle { fill: var(--context-color); }
.node.node-derivatives circle { fill: var(--derivative-color); }
.node.node-idioms circle { fill: var(--idiom-color); }
.node.node-collocations circle { fill: var(--collocation-color); }
.node.node-synonyms circle { fill: var(--synonym-color); }
.node.node-opposites circle { fill: var(--opposite-color); }
.node.node-translation circle { fill: var(--translation-color); }

/* --- 'Add More' Node --- */
.node.node-history circle { 
    fill: var(--text-muted); 
}
.node.node-history text { 
    fill: var(--accent-light); /* Ensures text is light and readable on the grey background */
}
.node.node-add circle {
    /* Make it visible: transparent fill with a thicker, bright stroke */
    fill: transparent;
    stroke: var(--primary-coral);
    stroke-width: 2.5px;
    stroke-dasharray: 5 3;
    transform-origin: center;
    transition: all 0.3s ease, transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.node.node-add text {
    /* Match the text color to the stroke for a cohesive look */
    fill: var(--primary-coral);
    font-size: 24px;
    font-weight: 300;
    transition: fill 0.3s ease;
}

.node.node-add:hover circle {
    /* We keep the fill/stroke changes here for simplicity */
    fill: var(--primary-coral);
    stroke-dasharray: none; 
}

.node.node-add:hover text {
    fill: var(--accent-white);
}

/* NEW: Add a loading state for the '+' button */
.node.node-add.is-loading circle {
    stroke-dasharray: none;
    animation: spin 1.5s linear infinite;
    transform-origin: center; /* Important for rotation */
}

/* NEW: Hide the '+' text when the button is loading */
.node.node-add.is-loading text {
    display: none;
}

/* NEW: Style for when there are no more items to load */
.node.node-add.is-disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.node.node-add.is-disabled circle,
.node.node-add.is-disabled:hover circle {
    fill: transparent;
    stroke: var(--text-muted);
    stroke-dasharray: none;
    animation: none;
}

.node.node-add.is-disabled text,
.node.node-add.is-disabled:hover text {
    fill: var(--text-muted);
}

.node.is-loading-example {
  opacity: 0.5;
  cursor: wait;
  pointer-events: none;
}

/* --- ENHANCED: Text Node Container Styles --- */
.node .node-html-wrapper {
      width: 220px;
      overflow: visible;
}

/* Base style for the <div> inside the wrapper. TRANSPARENT by default. */
.node .node-html-content {
    color: var(--canvas-text-color);
    font-size: 14px;
    font-weight: 500;
    height: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    transition: color 0.3s ease;
}

/* Dark mode text color for the transparent container */
[data-theme='dark'] .node .node-html-content {
    color: var(--accent-light);
}

.node-example .node-html-content {
    background-color: var(--accent-light);
    border: 1px solid #E0E0E0;
    border-radius: 8px;
    padding: 12px;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Dark mode for the solid example boxes */
[data-theme='dark'] .node-example .node-html-content {
    background-color: #34495E;
    border-color: #4A6572;
}

/* Style for interactive words inside any of these containers */
.node .node-html-content .interactive-word {
    color: var(--text-link);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none; /* <--- CHANGE: No underline by default */
    transition: color 0.2s ease, text-decoration 0.2s ease; /* Added transition for smoothness */
}

.node .node-html-content .interactive-word:hover {
    color: var(--primary-coral);
    text-decoration: underline; /* <--- CHANGE: Add underline ONLY on hover */
    text-decoration-style: solid;
}

/* --- Loading Spinner on Canvas --- */
.loading-spinner {
    animation: spin 2s linear infinite;
    transform-origin: center;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Voice Input Button --- */
.input-overlay {
    /* This no longer needs to be a positioning context */
}

.voice-input-btn {
    position: absolute;
    /* FIX: Positioned inside the wrapper's right edge */
    right: 15px; 
    top: 50%;
    transform: translateY(-50%);
    
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s ease;
    display: none; /* Hidden by default, JS will show it if supported */
}

.voice-input-btn:hover {
    color: var(--primary-coral);
    background-color: var(--btn-bg);
}

.voice-input-btn svg {
    width: 24px;
    height: 24px;
}

[data-theme='dark'] .voice-input-btn {
    color: var(--text-secondary);
}

[data-theme='dark'] .voice-input-btn:hover {
    color: var(--primary-coral);
    background-color: rgba(255, 255, 255, 0.1);
}

/* Style for when the microphone is actively listening */
.voice-input-btn.listening {
    color: white;
    background-color: var(--primary-coral);
    animation: pulse-mic 1.5s infinite ease-in-out;
}

@keyframes pulse-mic {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 107, 71, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 107, 71, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 107, 71, 0);
    }
}


/* --- Tooltip Styles --- */
.graph-tooltip {
    position: absolute;
    background: var(--primary-dark);
    color: var(--accent-white);
    padding: 10px 16px;
    border-radius: 10px;
    border: 1px solid var(--primary-coral);
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: none;
    opacity: 0;
    /* The new JS handles the transform, so we add a transition for it */
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    white-space: pre; /* Allows tooltips with line breaks */
}

.graph-tooltip.visible {
    opacity: 1;
    /* The JS will set the transform to translateY(-10px) on hover */
}

/* --- Utility Buttons & Others --- */
.utility-btn {
    background: var(--btn-bg); border: 1px solid var(--btn-border);
    border-radius: 16px; cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; width: 80px; height: 80px; color: var(--dock-text-color);
    position: relative; overflow: hidden;
}
.utility-btn:hover {
    background: var(--btn-hover); transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(255, 107, 71, 0.3); border-color: var(--primary-coral);
}
.utility-btn svg { width: 28px; height: 28px; fill: currentColor; transition: all 0.3s ease; }
.utility-btn span { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.5px; }

/* --- Language Modal --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(44, 62, 80, 0.7); backdrop-filter: blur(10px);
    display: flex; justify-content: center; align-items: center; z-index: 100;
    opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.visible { opacity: 1; visibility: visible; }
.modal-content {
    background: var(--dock-bg); color: var(--dock-text-color); padding: 30px 40px;
    border-radius: 20px; box-shadow: 0 15px 50px rgba(0, 0, 0, 0.4);
    width: 90%; max-width: 400px; text-align: center; position: relative;
    transform: scale(0.95); transition: transform 0.3s ease;
}
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-content h2 { margin-bottom: 25px; font-size: 1.5rem; }
.modal-close-btn {
    position: absolute; top: 10px; right: 15px; background: none; border: none;
    font-size: 2.5rem; line-height: 1; cursor: pointer; color: var(--text-muted);
    transition: all 0.2s ease;
}
.modal-close-btn:hover { color: var(--primary-coral); transform: rotate(90deg); }
.language-list { list-style-type: none; padding: 0; margin: 0; max-height: 50vh; overflow-y: auto; }
.language-list li {
    padding: 15px 20px; margin-bottom: 10px; background: var(--btn-bg);
    border-radius: 12px; border: 1px solid var(--btn-border);
    cursor: pointer; font-weight: 600; transition: all 0.2s ease;
}
.language-list li:hover {
    background: var(--primary-coral); color: white; transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255, 107, 71, 0.3);
}

/* --- Canvas Controls (Zoom, Register) --- */
#canvas-controls {
    position: absolute; top: 15px; right: 15px; z-index: 10;
    display: flex; flex-direction: column; align-items: flex-end; gap: 10px;  
}
#zoom-controls { display: flex; flex-direction: column; gap: 8px; }
#canvas-controls .control-btn {
    pointer-events: auto; background-color: var(--dock-bg); color: var(--dock-text-color);
    border: 1px solid var(--btn-border); border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); height: 38px; cursor: pointer;
    transition: all 0.2s ease; display: flex; justify-content: center;
    align-items: center; position: relative; overflow: hidden;
}
#canvas-controls .control-btn:hover { background-color: var(--btn-hover); border-color: var(--primary-coral); }
#canvas-controls .control-btn.active {
    background-color: var(--btn-hover);
    border-color: var(--primary-coral);
    color: var(--primary-coral);
}

#onboarding-help-btn {
    width: 38px;      
    margin-top: 20px; 
}

#register-toggle-btn {
    position: relative; overflow: hidden; width: 38px;
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme='dark'] #canvas-controls .control-btn:hover {
    color: var(--text-light); /* Or simply 'white' */
}
.register-state {
    position: absolute; width: 100%; height: 100%; left: 0; top: 0;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.register-state .register-text { opacity: 0; position: absolute; font-weight: 600; font-size: 0.8rem; }
.conversational-state { opacity: 1; transform: translateY(0); }
.academic-state { opacity: 0; transform: translateY(20px); }
.business-state { opacity: 0; transform: translateY(20px); }

#register-toggle-btn.is-academic .conversational-state { opacity: 0; transform: translateY(-20px); }
#register-toggle-btn.is-academic .academic-state { opacity: 1; transform: translateY(0); }
#register-toggle-btn.is-academic .business-state { opacity: 0; transform: translateY(20px); } /* Explicitly hide */

#register-toggle-btn.is-business .conversational-state { opacity: 0; transform: translateY(-20px); }
#register-toggle-btn.is-business .academic-state { opacity: 0; transform: translateY(-20px); } /* Move up and hide */
#register-toggle-btn.is-business .business-state { opacity: 1; transform: translateY(0); }
#register-toggle-btn:hover {
    width: 145px; 
}

#register-toggle-btn:hover .register-icon {
    opacity: 0;
}

#register-toggle-btn:hover .register-text {
    opacity: 1;
}
#zoom-controls .control-btn { width: 38px; }
#zoom-controls .control-btn svg { fill: currentColor; width: 20px; height: 20px; }
#register-toggle-btn.needs-attention { animation: pulse-glow 2.5s infinite ease-in-out; }
@keyframes pulse-glow {
    0% { box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
    50% { box-shadow: 0 2px 5px rgba(0,0,0,0.1), 0 0 15px rgba(255, 107, 71, 0.7); }
    100% { box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
}

#proficiency-toggle-btn {
    position: relative; /* Needed for absolute positioning of children */
    overflow: hidden;
    width: 38px;
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.proficiency-state {
    position: absolute; width: 100%; height: 100%; left: 0; top: 0;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.proficiency-state .proficiency-icon {
    transition: opacity 0.3s ease;
}

.proficiency-state .proficiency-text {
    opacity: 0;
    position: absolute;
    font-weight: 600;
    font-size: 0.8rem;
}

.high-state { opacity: 1; transform: translateY(0); }
.low-state { opacity: 0; transform: translateY(20px); }

#proficiency-toggle-btn:not(.is-high) .high-state { opacity: 0; transform: translateY(-20px); }
#proficiency-toggle-btn:not(.is-high) .low-state { opacity: 1; transform: translateY(0); }

#proficiency-toggle-btn:hover {
    width: 80px;
}
#proficiency-toggle-btn:hover .proficiency-icon {
    opacity: 0;
}
#proficiency-toggle-btn:hover .proficiency-text {
    opacity: 1;
}

#age-toggle-btn {
    position: relative;
    overflow: hidden;
    width: 38px;
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.age-state {
    position: absolute; width: 100%; height: 100%; left: 0; top: 0;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.age-state .age-icon {
    transition: opacity 0.3s ease;
}

.age-state .age-text {
    opacity: 0;
    position: absolute;
    font-weight: 600;
    font-size: 0.8rem;
}

/* Default state: Adults is visible */
.adult-state { opacity: 1; transform: translateY(0); }
.teen-state { opacity: 0; transform: translateY(20px); }

/* When .is-adult class is NOT present, show Teens */
#age-toggle-btn:not(.is-adult) .adult-state { opacity: 0; transform: translateY(-20px); }
#age-toggle-btn:not(.is-adult) .teen-state { opacity: 1; transform: translateY(0); }

/* Expand on hover */
#age-toggle-btn:hover {
    width: 80px;
}

#age-toggle-btn:hover .age-icon {
    opacity: 0;
}

#age-toggle-btn:hover .age-text {
    opacity: 1;
}

/* FIX: New rules for layout toggle button */
#layout-toggle-btn {
    width: 38px; /* a) Ensure consistent width */
    margin-top: 20px; /* b) Add space above to create a visual group */
}


/* Default state: High is visible */
.high-state { opacity: 1; transform: translateY(0); }
.low-state { opacity: 0; transform: translateY(20px); }

/* When .is-high class is NOT present, show Low */
#proficiency-toggle-btn:not(.is-high) .high-state { opacity: 0; transform: translateY(-20px); }
#proficiency-toggle-btn:not(.is-high) .low-state { opacity: 1; transform: translateY(0); }

/* Expand on hover */
#proficiency-toggle-btn:hover {
    width: 80px;
}

[data-theme='dark'] #canvas-controls .control-btn {
    background-color: #34495E; /* A dark, but not black, background */
    color: var(--text-light);
    border: 1px solid rgba(255, 255, 255, 0.2); /* A subtle light border */
}

[data-theme='dark'] #canvas-controls .control-btn:hover {
    background-color: #4A6572; /* Lighter on hover */
    border-color: var(--primary-coral);
}


/* 2. Define a new, more vibrant glow animation for dark mode */
@keyframes pulse-glow-dark {
    0% {
        box-shadow: 0 0 0 rgba(255, 107, 71, 0); /* Start with no glow */
    }
    50% {
        box-shadow: 0 0 20px 2px rgba(255, 107, 71, 0.8); /* A stronger, wider coral glow */
    }
    100% {
        box-shadow: 0 0 0 rgba(255, 107, 71, 0); /* End with no glow */
    }
}

/* 3. Apply this new animation when in dark mode */
[data-theme='dark'] #register-toggle-btn.needs-attention {
    animation-name: pulse-glow-dark; /* Override the animation name */
}

.tts-icon-group {
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
}

.tts-icon path {
    /* Use CSS variables to match your theme */
    fill: var(--canvas-text-color);
    transition: fill 0.3s ease;
}

.tts-icon-group:hover .tts-icon path {
    fill: var(--primary-coral);
}

.copy-icon-group {
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
}

.copy-icon path {
    /* Use CSS variables to match your theme */
    fill: var(--canvas-text-color);
    transition: fill 0.3s ease;
    opacity: 0.6; /* Make it slightly more subtle than text */
}

.copy-icon-group:hover .copy-icon path {
    fill: var(--primary-coral);
    opacity: 1;
}

.game-status-ui {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--dock-bg);
    color: var(--dock-text-color);
    border-radius: 12px;
    padding: 10px 20px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    border: 1px solid var(--btn-border);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-20px);
    transition: all 0.3s ease;
}

.game-status-ui.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.game-info, .game-steps {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.game-status-ui span {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.game-status-ui strong {
    font-size: 1.1rem;
    color: var(--dock-text-color);
}

#end-game-btn {
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    color: var(--text-muted);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#end-game-btn:hover {
    background: var(--opposite-color);
    color: white;
    transform: rotate(90deg);
}

[data-theme='dark'] .game-status-ui {
    background-color: #34495E;
    color: var(--text-light);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme='dark'] .game-status-ui strong {
    color: white;
}

/* --- Game Over Modal --- */
.game-over-content {
    text-align: center;
    position: relative; /* Needed for the canvas */
    overflow: hidden; /* Keeps confetti inside the modal bounds */
}

.game-over-content h2 {
    font-size: 2.5rem;
    color: var(--primary-coral);
    margin-bottom: 15px;
}

.game-over-content p {
    font-size: 1.2rem;
    margin-bottom: 30px;
    color: var(--dock-text-color);
}

[data-theme='dark'] .game-over-content p {
    color: var(--dock-text-color);
}

.modal-play-again-btn {
    background: var(--primary-coral);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 15px 30px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 5px 15px rgba(255, 107, 71, 0.3);
}

.modal-play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 107, 71, 0.4);
}

#confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Allows clicks to go through to the button */
    z-index: -1;
}

.shepherd-modal-overlay {
    background: rgba(26, 37, 47, 0.7); /* var(--primary-dark) with transparency */
    backdrop-filter: blur(5px);
    transition: opacity 0.3s ease;
    z-index: 11000; /* Extremely high z-index */
}

/* FIX: The tour element needs an EVEN HIGHER z-index than the overlay. 
   This makes its buttons clickable and ensures it's visible in full-screen. */
.shepherd-element.wordsplainer-tour {
    z-index: 11001; /* Must be higher than the overlay */
    
    /* STYLE: Improved glassmorphism */
    background: rgba(30, 42, 54, 0.8); /* Darker, less blue, more transparent */
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px); /* For Safari */
    border-radius: 18px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.4), 
                inset 0 0 0 1.5px rgba(255, 255, 255, 0.1); /* Glassy edge highlight */
    max-width: 380px;
    filter: drop-shadow(0 0 15px rgba(0,0,0,0.5));
}

.shepherd-element.wordsplainer-tour .shepherd-arrow::before {
    background: rgba(30, 42, 54, 0.8);
}

.shepherd-element.wordsplainer-tour .shepherd-header {
    padding: 1.2em 1.2em 0.8em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.shepherd-element.wordsplainer-tour .shepherd-title {
    color: var(--primary-coral);
    font-weight: 700;
    font-size: 1.3rem;
}

.shepherd-element.wordsplainer-tour .shepherd-cancel-icon {
    color: var(--text-secondary);
    transition: all 0.2s ease;
}
.shepherd-element.wordsplainer-tour .shepherd-cancel-icon:hover {
    color: var(--accent-white);
    transform: scale(1.1);
}

.shepherd-element.wordsplainer-tour .shepherd-text {
    color: var(--accent-light);
    font-size: 1rem;
    line-height: 1.6;
    padding: 1.2em;
}

.shepherd-element.wordsplainer-tour .shepherd-text b {
    color: var(--primary-coral);
    font-weight: 600;
}

.shepherd-element.wordsplainer-tour .shepherd-footer {
    padding: 0 1.2em 1.2em;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.shepherd-element.wordsplainer-tour .shepherd-button {
    border: none;
    border-radius: 12px;
    padding: 12px 24px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    box-shadow: none;
}

/* Primary Action Button (Next, Let's Go) */
.shepherd-element.wordsplainer-tour .shepherd-button:not(.shepherd-button-secondary) {
    background: var(--primary-coral);
    color: white;
    box-shadow: 0 5px 20px rgba(255, 107, 71, 0.25), 
                inset 0 -2px 0 rgba(0,0,0,0.15); /* Subtle 3D effect */
}
.shepherd-element.wordsplainer-tour .shepherd-button:not(.shepherd-button-secondary):hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 107, 71, 0.35),
                inset 0 -2px 0 rgba(0,0,0,0.15);
}

/* Secondary Action Button (Back) */
.shepherd-element.wordsplainer-tour .shepherd-button.shepherd-button-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
}
.shepherd-element.wordsplainer-tour .shepherd-button.shepherd-button-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--accent-white);
}

/* --- ENHANCED RESPONSIVE DESIGN --- */

/* For Tablets and Small Desktops (e.g., up to 1200px) */
@media (max-width: 1200px) {
    /* Allow the controls dock to wrap its contents into multiple lines */
    #controls-dock {
        flex-wrap: wrap;
        justify-content: center; /* Center the buttons when they wrap */
        row-gap: 20px; /* Add space between the wrapped rows */
    }
}


/* For Mobile Devices (e.g., up to 768px) */
@media (max-width: 768px) {
    #app-wrapper { 
        padding: 10px; 
        gap: 10px; /* Reduced gap for smaller screens */
    }
    .title-container { 
        padding: 10px 15px; 
        border-radius: 16px;
    }
    header h1 { font-size: 1.5rem; }
    .header-logo { height: 30px; margin-right: 12px; }

    /* --- THE MOBILE DOCK FIX: HORIZONTAL SCROLLING --- */
    #controls-dock {
        /* 1. Revert to a single row and enable horizontal scrolling */
        flex-direction: row;
        flex-wrap: nowrap; /* CRITICAL: Prevent wrapping */
        overflow-x: auto;  /* CRITICAL: Enable horizontal scroll */
        
        /* 2. Improve the visual alignment and padding */
        justify-content: flex-start; /* Align buttons to the start */
        padding: 15px;

        /* 3. Improve the scrolling experience (optional but recommended) */
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        scroll-snap-type: x mandatory; /* Makes scrolling "snap" to buttons */
    }

    /* 4. Ensure button groups don't shrink */
    .category-buttons, .utility-buttons {
        flex-shrink: 0;
    }

    /* 5. Add snap alignment to individual buttons for a better feel */
    .category-btn, .utility-btn {
        scroll-snap-align: start;
    }

    /* 6. Hide the ugly scrollbar for a cleaner look */
    #controls-dock::-webkit-scrollbar {
        display: none;
    }
    #controls-dock {
        -ms-overflow-style: none;  /* IE and Edge */
        scrollbar-width: none;  /* Firefox */
    }
}