:root {
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.3);
    --text-color: #2d3436;
    --error-color: #ff7675;
    --success-color: #55efc4;
    --secondary-color: #636e72;
    --danger-color: #e17055;
    --shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

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

body {
    font-family: 'Inter', 'Noto Sans TC', sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-color);
}

.container {
    width: 95%;
    max-width: 600px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 25px;
    box-shadow: var(--shadow);
    height: 85vh;
    max-height: 750px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 10px auto;
}

header {
    text-align: center;
    margin-bottom: 12px;
}

h1 {
    font-weight: 700;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.subtitle {
    font-size: 0.9rem;
    color: var(--secondary-color);
    letter-spacing: 1px;
}

/* Sound theme selector bar */
.sound-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 18px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.sound-bar label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--secondary-color);
    white-space: nowrap;
}

.sound-bar select {
    flex: 1;
    max-width: 220px;
    padding: 5px 10px;
    border: 1.5px solid rgba(74, 144, 226, 0.35);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    font-family: 'Inter', 'Noto Sans TC', sans-serif;
    font-size: 0.85rem;
    color: var(--text-color);
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.sound-bar select:focus {
    border-color: var(--primary-color);
}

.btn-preview {
    padding: 5px 10px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
}

.btn-preview:hover {
    background: var(--primary-hover);
    transform: scale(1.08);
}

.input-section {
    margin-bottom: 25px;
}

.input-group {
    display: flex;
    gap: 10px;
}

input[type="text"] {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid transparent;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    font-size: 1rem;
    outline: none;
}

input[type="text"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 4px 15px rgba(74, 144, 226, 0.2);
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    font-size: 0.95rem;
}

#addButton {
    background: var(--primary-color);
    color: white;
}

#addButton:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.feedback {
    height: 24px;
    margin-top: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.feedback.show {
    opacity: 1;
}

.feedback.error {
    color: var(--error-color);
}

.feedback.success {
    color: var(--success-color);
}

main {
    flex: 1;
    /* Fill remaining space in .container */
    min-height: 0;
    /* Critical: allow shrinking in flex context */
    display: flex;
    flex-direction: column;
}

.list-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.list-header h2 {
    font-size: 1.1rem;
}

.actions {
    display: flex;
    gap: 8px;
}

.list-container {
    flex: 1;
    min-height: 0;
    /* Critical: allows flex child to shrink and overflow-y to work */
    overflow-y: scroll;
    /* 'scroll' forces scrollbar always visible, unlike 'auto' which hides on macOS */
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

ul {
    list-style: none;
    padding-bottom: 20px;
    /* Space for last item */
}

li {
    background: white;
    margin-bottom: 8px;
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02);
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: fadeIn 0.3s ease;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

li span {
    font-family: 'Inter', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    letter-spacing: 0.5px;
}

li::before {
    content: '📚';
    margin-right: 12px;
    font-size: 1.1rem;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom Scrollbar - High Visibility */
.list-container::-webkit-scrollbar {
    width: 12px;
}

.list-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.list-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
    border: 3px solid #f1f1f1;
}

.list-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}