:root {
    /* Brand Colors */
    --brand-primary: #2563eb;
    --brand-primary-hover: #1d4ed8;
    --brand-accent: #db2777;
    
    /* Backgrounds & Surfaces */
    --bg-body: #f8fafc;
    --bg-surface: #ffffff;
    --bg-hover: #f1f5f9;
    
    /* Typography */
    --text-main: #0f172a;
    --text-sub: #64748b;
    --text-light: #f8fafc;
    
    /* Player Typography & Grammar Colors */
    --text-romaji: #3f6212;
    --text-trans: #0369a1;
    --highlight-bg: #e0f2fe;     
    --highlight-border: #0284c7; 
    --color-noun: #2563eb;       
    --color-verb: #16a34a;       
    --color-adjective: #d97706;  
    --color-particle: #94a3b8;   
    --color-aux: #9333ea;        
    --color-default: #db2777; 

    /* Structural */
    --border-light: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    
    /* Z-index layers */
    --z-nav: 50;
    --z-dropdown: 100;
}

/* --- Shared Media --- */
.yt-responsive-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    height: 0;
    overflow: hidden;
    background-color: #000;
    width: 100%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.yt-responsive-wrapper iframe,
.yt-responsive-wrapper #yt-player,
.yt-responsive-wrapper #youtube-player {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    border: none;
}

/* --- Forms & Buttons --- */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-main); font-size: 0.9rem;}
.form-group input, .form-group textarea, .form-group select { 
    width: 100%; padding: 0.75rem; box-sizing: border-box; 
    border: 1px solid var(--border-light); border-radius: var(--radius-md);
    font-family: inherit; font-size: 1rem; transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none; border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn { 
    background-color: var(--brand-primary); color: white; border: none; 
    padding: 0.75rem 1.5rem; cursor: pointer; border-radius: var(--radius-md); 
    font-weight: 600; font-size: 1rem; transition: background-color 0.2s; 
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; 
    text-decoration: none; text-align: center;
}
.btn:hover { background-color: var(--brand-primary-hover); }
.btn-full { width: 100%; margin-top: 1rem; }
.btn-outline { background: transparent; color: var(--text-main); border: 1px solid var(--border-light); }
.btn-outline:hover { background: var(--bg-hover); color: var(--brand-primary); border-color: var(--brand-primary); }

.btn-primary { background-color: #3498db; }
.btn-primary:hover { background-color: #2980b9; }
.btn-success { background-color: #27ae60; }
.btn-success:hover { background-color: #219653; }
.btn-warning { background-color: #f39c12; }
.btn-warning:hover { background-color: #d68910; }
.btn-purple { background-color: #8e44ad; }
.btn-purple:hover { background-color: #732d91; }
.btn-secondary { background-color: #7f8c8d; color: white; }
.btn-secondary:hover { background-color: #636e72; }
.btn-clear { background: #e74c3c; color: white; border: none; border-radius: var(--radius-md); padding: 8px 12px; cursor: pointer; }
.btn-clear:hover { background: #c0392b; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Toggles / Switches */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #d4d4d8; transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: var(--shadow-sm); }
input:checked + .slider { background-color: var(--brand-primary); }
input:checked + .slider:before { transform: translateX(20px); }

/* --- Auth & Utility Cards --- */
@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

.auth-card {
    max-width: 420px; margin: 4rem auto; background: var(--bg-surface);
    padding: 2.5rem 2rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light); animation: fade-in-up 0.4s ease-out; width: 100%;
}
.auth-card.center-text { text-align: center; max-width: 480px; }
.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-icon {
    width: 48px; height: 48px; color: var(--brand-primary); margin-bottom: 1rem;
    background: var(--bg-hover); padding: 10px; border-radius: 50%; display: inline-block;
}
.auth-icon-success { width: 64px; height: 64px; color: #10b981; margin-bottom: 1.5rem; }
.auth-title { font-size: 1.5rem; font-weight: 700; color: var(--text-main); margin-bottom: 0.5rem; }
.auth-subtitle { font-size: 0.9rem; color: var(--text-sub); margin-bottom: 2.5rem; }
#login-response { margin-top: 1rem; text-align: center; }
.action-buttons { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

/* --- Admin Dashboard & Editor --- */
/* MOBILE FIRST: Stack on small screens, Grid on md+ */
.dashboard-grid { display: flex; flex-direction: column; gap: 20px; margin-top: 1rem; }
@media (min-width: 768px) {
    .dashboard-grid { display: grid; grid-template-columns: 35% 65%; }
}

/* REMOVED: .hidden { display: none !important; } - It broke Tailwind */

.panel { background: var(--bg-surface); padding: 20px; border: 1px solid var(--border-light); border-radius: var(--radius-md); display: flex; flex-direction: column; box-shadow: var(--shadow-sm); }
.search-wrapper { display: flex; gap: 8px; align-items: center; }
.inline-create-box { background: #e8f8f5; border: 1px solid #27ae60; padding: 15px; border-radius: var(--radius-md); margin-top: 5px; }
.input-success { border: 2px solid #27ae60 !important; background-color: #f0fdf4 !important; }
#jsoneditor { flex-grow: 1; min-height: 550px; margin-bottom: 15px; }
#preview-container { background: white; padding: 15px; border: 1px solid var(--border-light); border-radius: var(--radius-md); height: 250px; overflow-y: auto; margin-bottom: 20px; }
.match-highlight { color: var(--brand-primary); background-color: #eff6ff; font-weight: 900; padding: 0 2px; border-radius: 3px; }

/* --- Song Library --- */
.song-list { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; }
.song-card {
    background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-md);
    padding: 1.5rem; display: flex; justify-content: space-between; align-items: center;
    box-shadow: var(--shadow-sm); transition: transform 0.2s ease, box-shadow 0.2s ease;
    flex-wrap: wrap; gap: 1rem;
}
.song-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: #cbd5e1; }
.song-card-content h3 { margin: 0 0 0.25rem 0; color: var(--text-main); font-size: 1.1rem; }
.song-card-meta { color: var(--text-sub); font-size: 0.875rem; }
.song-card-actions { display: flex; gap: 0.75rem; width: 100%; justify-content: flex-end; }
@media (min-width: 640px) {
    .song-card-actions { width: auto; }
}
.empty-state { padding: 2rem; background-color: #fef3c7; border: 1px solid #fde68a; border-radius: var(--radius-md); text-align: center; color: #92400e; }

/* --- Success & Confirmation Cards --- */
.success-card {
    max-width: 600px; margin: 4rem auto; background: var(--bg-surface); padding: 2.5rem;
    border-radius: var(--radius-lg); border: 1px solid var(--border-light); text-align: center;
    box-shadow: var(--shadow-lg); animation: fade-in-up 0.4s ease-out; width: 100%;
}
.success-card h2 { color: #27ae60; margin-top: 0; font-size: 1.75rem; }
.success-card-text { font-size: 1.1rem; color: var(--text-main); margin-bottom: 2rem; }
.success-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.success-actions .btn { flex-grow: 1; }

/* --- Tap-to-Sync Studio --- */
/* MOBILE FIRST: Stack on small screens, Grid on md+ */
.sync-layout { display: flex; flex-direction: column; gap: 20px; }
@media (min-width: 768px) {
    .sync-layout { display: grid; grid-template-columns: 45% 55%; height: 80vh; }
}
.video-panel { display: flex; flex-direction: column; gap: 15px; }
.sticky-wrapper { position: sticky; top: 80px; } /* Updated top to accommodate thicker sticky header */

.controls-box { background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-md); padding: 20px; box-shadow: var(--shadow-sm); }
.key-indicator { display: inline-block; background: var(--bg-hover); border: 1px solid var(--border-light); border-radius: 4px; padding: 4px 8px; font-family: monospace; font-weight: bold; }
.lyrics-panel { background: var(--bg-surface); border: 1px solid var(--border-light); border-radius: var(--radius-md); overflow-y: auto; padding: 20px; box-shadow: inset 0 2px 4px rgba(0,0,0,0.05); }

/* Unified Lyric Row */
.lyric-row, .lyric-line {
    padding: 15px; border-bottom: 1px solid var(--border-light); border-radius: 6px;
    transition: all 0.2s ease; cursor: pointer; display: flex; gap: 15px;
    border-left: 6px solid transparent; flex-wrap: wrap;
}
.lyric-row { align-items: center; } 
.lyric-line { flex-direction: column; gap: 0.4rem; }

.lyric-row:hover, .lyric-line:hover { background-color: var(--bg-hover); }
.lyric-row.active, .lyric-line.active {
    background-color: var(--highlight-bg); border-left-color: var(--highlight-border);
    transform: translateX(6px); box-shadow: var(--shadow-sm);
}

.time-stamp { font-family: monospace; background: #333; color: #00ff00; padding: 4px 8px; border-radius: 4px; font-size: 0.9em; min-width: 60px; text-align: center; }

/* --- Interactive Player Specifics --- */
.player-container { max-width: 800px; margin: 0 auto; padding: 1rem; }
@media (min-width: 768px) { .player-container { padding: 2rem 1rem; } }
.song-header {
    background: var(--bg-surface); padding: 1.5rem; border-radius: 12px;
    box-shadow: var(--shadow-sm); margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.25rem;
}
.song-header h1 { margin: 0; font-size: 1.5rem; color: var(--text-main); line-height: 1.2; }
@media (min-width: 768px) { .song-header h1 { font-size: 1.8rem; } }
.header-romaji { font-size: 1.1rem; color: var(--text-sub); font-style: italic; margin-bottom: 0.5rem; }
.song-header a.artist-link { color: var(--color-noun); text-decoration: none; font-weight: 600; display: inline-block; }
.song-header a.artist-link:hover { text-decoration: underline; }

.lyrics-toolbar { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; padding: 0.5rem 0; margin-bottom: 1rem; flex-wrap: wrap; }
.toggle-group { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: var(--text-sub); font-weight: 500; }
.lyrics-board { background: var(--bg-surface); padding: 1.5rem; border-radius: 12px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 0.5rem; }

/* Vocabulary Chunk Rendering */
.chunks-container { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.3rem; row-gap: 1.5rem; margin-bottom: 0.2rem; }
.chunk { position: relative; cursor: help; border-bottom: 3px solid var(--color-default); padding-bottom: 2px; transition: background-color 0.2s; }
.chunk:hover { background-color: #ffeaa7; border-radius: 3px; }

.chunk.pos-noun { border-bottom-color: var(--color-noun); }
.chunk.pos-verb { border-bottom-color: var(--color-verb); }
.chunk.pos-adjective { border-bottom-color: var(--color-adjective); }
.chunk.pos-particle { border-bottom-color: var(--color-particle); }
.chunk.pos-auxiliary { border-bottom-color: var(--color-aux); }

ruby { font-size: 1.2rem; font-weight: 500; text-align: center; }
@media (min-width: 768px) { ruby { font-size: 1.4rem; } }
rt { font-size: 0.7rem; color: var(--text-sub); font-weight: 400; user-select: none; }

/* Tooltips */
.tooltip {
    visibility: hidden; opacity: 0; position: absolute; bottom: 100%; left: 50%;
    transform: translateX(-50%) translateY(-10px); background: #27272a; color: #fafafa;
    text-align: left; padding: 0.75rem; border-radius: 8px; width: max-content;
    min-width: 150px; max-width: 250px; z-index: 10; box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    transition: opacity 0.2s, transform 0.2s; pointer-events: none; font-size: 0.85rem; line-height: 1.4;
}
.tooltip::after {
    content: ''; position: absolute; top: 100%; left: 50%; margin-left: -6px;
    border-width: 6px; border-style: solid; border-color: #27272a transparent transparent transparent;
}
.chunk:hover .tooltip { visibility: visible; opacity: 1; transform: translateX(-50%) translateY(-5px); }

.tt-row { display: flex; flex-direction: column; margin-bottom: 0.4rem; }
.tt-row:last-child { margin-bottom: 0; }
.tt-label { font-size: 0.65rem; text-transform: uppercase; color: #a1a1aa; letter-spacing: 0.05em; }
.tt-value { font-weight: 500; }

.line-romaji { font-size: 1rem; color: var(--text-romaji); font-style: italic; }
.line-trans { font-size: 1rem; color: var(--text-trans); font-weight: 500; }