/* ==========================================================================
   Kyorinrin - Modern UI
   Mobile-first design with dark/light theme support
   ========================================================================== */

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

/* --------------------------------------------------------------------------
   Design Tokens (Dark theme default)
   -------------------------------------------------------------------------- */
:root,
[data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-nav: #0a0a1a;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0b0;
    --accent: #6c5ce7;
    --accent-hover: #7d6ff0;
    --accent-secondary: #00cec9;
    --danger: #ff6b6b;
    --danger-hover: #ff5252;
    --border: #2a2a3e;
    --shadow: rgba(0,0,0,0.4);
    --toast-bg: #222;
    --input-bg: #16213e;
    --overlay-bg: rgba(0,0,0,0.7);
    --card-hover: #1e1e3a;
    --badge-read-bg: #2a2a3e;
    --badge-read-text: #a0a0b0;
    --badge-unread-bg: #6c5ce7;
    --badge-unread-text: #fff;
}

[data-theme="light"] {
    --bg-primary: #f5f5f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f0f5;
    --bg-nav: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #555570;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd6;
    --accent-secondary: #00b894;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --border: #e0e0e8;
    --shadow: rgba(0,0,0,0.1);
    --toast-bg: #333;
    --input-bg: #f0f0f5;
    --overlay-bg: rgba(0,0,0,0.5);
    --card-hover: #eeeef4;
    --badge-read-bg: #e0e0e8;
    --badge-read-text: #555570;
    --badge-unread-bg: #6c5ce7;
    --badge-unread-text: #fff;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

img {
    max-width: 100%;
    height: auto;
}

/* --------------------------------------------------------------------------
   Accessibility
   -------------------------------------------------------------------------- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
    font-size: 14px;
    border-radius: 0 0 4px 0;
}

.skip-link:focus {
    top: 0;
}

*:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

#aria-announcements {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */
.nav {
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
}

.nav__brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    white-space: nowrap;
}

.nav__brand:hover {
    color: var(--accent);
}

.nav__links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
    z-index: 999;
}

.nav__links.open {
    display: flex;
}

.nav__link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 12px 20px;
    min-height: 44px;
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s;
    font-size: 0.95rem;
}

.nav__link:hover,
.nav__link--active {
    color: var(--accent);
    background: var(--bg-tertiary);
}

.nav__hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 8px;
}

.nav__hamburger:hover {
    background: var(--bg-tertiary);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background 0.2s;
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
}

@media (min-width: 600px) {
    .nav__links {
        display: flex;
        flex-direction: row;
        position: static;
        background: none;
        border: none;
        padding: 0;
        gap: 4px;
    }

    .nav__link {
        padding: 8px 14px;
        border-radius: 6px;
    }

    .nav__hamburger {
        display: none;
    }
}

/* --------------------------------------------------------------------------
   Main Content
   -------------------------------------------------------------------------- */
.main {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
    gap: 8px;
    line-height: 1.2;
}

.btn:active {
    transform: scale(0.97);
}

.btn--primary {
    background: var(--accent);
    color: #fff;
}

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

.btn--secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn--secondary:hover {
    background: var(--card-hover);
    color: var(--text-primary);
}

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

.btn--danger:hover {
    background: var(--danger-hover);
    color: #fff;
}

.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn--ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn--sm {
    min-height: 36px;
    min-width: 36px;
    padding: 6px 14px;
    font-size: 0.85rem;
}

.btn--full {
    width: 100%;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px; /* Prevents iOS zoom */
    transition: border-color 0.2s;
    line-height: 1.4;
}

.form-input:focus {
    border-color: var(--accent);
    outline: none;
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.2);
}

.form-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.form-error {
    color: var(--danger);
    font-size: 0.82rem;
    margin-top: 4px;
    display: none;
}

.form-error.visible {
    display: block;
}

.form-input.invalid {
    border-color: var(--danger);
}

select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Page Header
   -------------------------------------------------------------------------- */
.page-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.page-header__title {
    font-size: 1.5rem;
    font-weight: 700;
}

.page-header__actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

@media (min-width: 600px) {
    .page-header {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

/* --------------------------------------------------------------------------
   Search Bar
   -------------------------------------------------------------------------- */
.search-bar {
    display: flex;
    gap: 8px;
    width: 100%;
}

.search-bar .form-input {
    flex: 1;
    margin-bottom: 0;
}

@media (min-width: 600px) {
    .search-bar {
        max-width: 400px;
    }
}

/* --------------------------------------------------------------------------
   Comic Grid (Library)
   -------------------------------------------------------------------------- */
.comic-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 600px) {
    .comic-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }
}

@media (min-width: 900px) {
    .comic-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 20px;
    }
}

.comic-card {
    display: block;
    text-decoration: none;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.comic-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow);
}

.comic-card__img {
    width: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    display: block;
}

.comic-card__title {
    padding: 10px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   Feed Cards (Home)
   -------------------------------------------------------------------------- */
.feed-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feed-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.feed-card:hover {
    box-shadow: 0 4px 16px var(--shadow);
}

.feed-card__thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
}

.feed-card__body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.feed-card__title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.feed-card__title:hover {
    color: var(--accent);
}

.feed-card__chapters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

@media (min-width: 600px) {
    .feed-card {
        flex-direction: row;
    }

    .feed-card__thumb {
        width: 160px;
        aspect-ratio: 2 / 3;
        flex-shrink: 0;
    }

    .feed-card__body {
        flex: 1;
        justify-content: center;
    }
}

@media (min-width: 900px) {
    .feed-card__thumb {
        width: 200px;
    }
}

/* --------------------------------------------------------------------------
   Chips (chapter pills)
   -------------------------------------------------------------------------- */
.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    min-height: 36px;
    transition: background 0.2s, transform 0.1s;
    cursor: pointer;
    border: none;
    background: var(--accent);
    color: #fff;
}

.chip:hover {
    background: var(--accent-hover);
    color: #fff;
    transform: scale(1.05);
}

/* --------------------------------------------------------------------------
   Badges (read/unread)
   -------------------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge--read {
    background: var(--badge-read-bg);
    color: var(--badge-read-text);
}

.badge--unread {
    background: var(--badge-unread-bg);
    color: var(--badge-unread-text);
}

.badge--new {
    background: var(--danger);
    color: #fff;
}

.badge--caught-up {
    background: var(--accent-secondary);
    color: #fff;
}

/* --------------------------------------------------------------------------
   Chapter List (Comic Detail)
   -------------------------------------------------------------------------- */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chapter-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-primary);
    min-height: 48px;
    transition: background 0.2s;
    cursor: pointer;
    gap: 12px;
}

.chapter-item:hover {
    background: var(--card-hover);
    color: var(--text-primary);
}

.chapter-item--read {
    opacity: 0.6;
}

.chapter-item__name {
    font-weight: 500;
    font-size: 0.92rem;
}

/* --------------------------------------------------------------------------
   Comic Detail (Hero)
   -------------------------------------------------------------------------- */
.comic-hero {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 24px;
}

.comic-hero__cover {
    width: 100%;
    max-width: 280px;
    border-radius: 10px;
    object-fit: cover;
    aspect-ratio: 2 / 3;
    margin: 0 auto;
    display: block;
}

.comic-hero__info {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.comic-hero__title {
    font-size: 1.5rem;
    font-weight: 700;
}

.comic-hero__desc {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

@media (min-width: 600px) {
    .comic-hero {
        flex-direction: row;
        align-items: flex-start;
    }

    .comic-hero__cover {
        width: 220px;
        margin: 0;
        flex-shrink: 0;
    }

    .comic-hero__info {
        flex: 1;
    }
}

/* --------------------------------------------------------------------------
   Chapter Reader (Zero-Gap)
   -------------------------------------------------------------------------- */
.reader {
    max-width: 100%;
    margin: 0 auto;
}

.reader__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    gap: 12px;
    margin-bottom: 8px;
}

.reader__title {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader__back {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    white-space: nowrap;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.reader__back:hover {
    color: var(--accent);
}

.reader__pages {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 0;
    font-size: 0;
}

.reader__page {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
}

.reader__spread {
    display: flex;
    flex-direction: row;
    width: 100%;
    line-height: 0;
    font-size: 0;
}

.reader__spread .reader__page {
    width: 50%;
}

.reader__nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    gap: 12px;
    margin-top: 8px;
}

@media (min-width: 900px) {
    .reader {
        max-width: 800px;
    }
}

/* --------------------------------------------------------------------------
   Login Page
   -------------------------------------------------------------------------- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 56px);
    padding: 16px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px 24px;
}

.login-card__title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
}

.login-card__subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    z-index: 5000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay[style*="display: block"],
.modal-overlay[style*="display:block"] {
    display: flex !important;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal__title {
    font-size: 1.15rem;
    font-weight: 700;
}

.modal__close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.modal__close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal__body {
    padding: 20px;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px 0;
    flex-wrap: wrap;
}

.pagination__info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0 8px;
}

/* --------------------------------------------------------------------------
   Empty State
   -------------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-secondary);
}

.empty-state__icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.empty-state__text {
    font-size: 1.1rem;
}

/* --------------------------------------------------------------------------
   Error Pages
   -------------------------------------------------------------------------- */
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 56px);
    text-align: center;
    padding: 16px;
}

.error-page__code {
    font-size: 5rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 8px;
}

.error-page__msg {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 24px;
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    pointer-events: none;
    max-width: 400px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--toast-bg);
    color: #fff;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 10px;
    box-shadow: 0 8px 24px var(--shadow);
    pointer-events: auto;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-size: 0.9rem;
    min-height: 44px;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast--success { background: #27ae60; }
.toast--error { background: var(--danger); }
.toast--warning { background: #f39c12; color: #1a1a2e; }
.toast--info { background: var(--accent); }

.toast__close {
    background: none;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    margin-left: auto;
    opacity: 0.7;
    min-height: auto;
    min-width: auto;
}

.toast__close:hover { opacity: 1; }

@media (max-width: 599px) {
    .toast-container {
        left: 12px;
        right: 12px;
        max-width: none;
    }
}

/* --------------------------------------------------------------------------
   Loading
   -------------------------------------------------------------------------- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

.loading-spinner--dark {
    border-color: rgba(0,0,0,0.15);
    border-top-color: var(--accent);
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    flex-direction: column;
    color: #fff;
    font-size: 1.1rem;
}

.loading-overlay .loading-spinner {
    width: 48px;
    height: 48px;
    border-width: 4px;
    margin-bottom: 16px;
    margin-right: 0;
}

button.loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Reading Progress Bar
   -------------------------------------------------------------------------- */
.reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--accent);
    z-index: 9999;
    transition: width 0.1s linear;
}

/* --------------------------------------------------------------------------
   Prevent iOS zoom on input focus
   -------------------------------------------------------------------------- */
input, select, textarea {
    font-size: 16px;
}

/* --------------------------------------------------------------------------
   Utility
   -------------------------------------------------------------------------- */
.text-center { text-align: center; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 16px; }
.mt-lg { margin-top: 24px; }
.mb-md { margin-bottom: 16px; }
.gap-sm { gap: 8px; }

/* --------------------------------------------------------------------------
   Translation Drawer
   -------------------------------------------------------------------------- */
.tl-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    z-index: 6000;
}

.tl-overlay.open {
    display: block;
}

.tl-drawer {
    position: fixed;
    z-index: 6001;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;

    /* Mobile: bottom sheet */
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 60vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
}

.tl-drawer.open {
    transform: translateY(0);
}

@media (min-width: 900px) {
    .tl-drawer {
        /* Desktop: right panel */
        top: 0;
        bottom: 0;
        right: 0;
        left: auto;
        width: 360px;
        max-height: none;
        border-radius: 0;
        transform: translateX(100%);
    }

    .tl-drawer.open {
        transform: translateX(0);
    }
}

.tl-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tl-drawer__title {
    font-size: 1rem;
    font-weight: 700;
}

.tl-drawer__close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.tl-drawer__close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tl-drawer__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tl-drawer__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.tl-drawer__empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.tl-drawer__empty-sub {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.tl-words {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tl-word-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
}

.tl-word-card.open {
    padding: 10px 14px;
}

.tl-word-card__head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.tl-word-card__chevron {
    margin-left: auto;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    position: relative;
    top: 2px;
}

.tl-word-card__chevron::after {
    content: '';
    display: block;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--text-secondary);
    border-bottom: 2px solid var(--text-secondary);
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
    position: absolute;
    top: 3px;
    left: 4px;
}

.tl-word-card.open .tl-word-card__chevron::after {
    transform: rotate(45deg);
    top: 1px;
}

.tl-word-card__kanji {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tl-word-card__reading {
    font-size: 0.9rem;
    color: var(--accent);
}

.tl-word-card__badges {
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
    margin-bottom: 4px;
}

.tl-word-card.open .tl-word-card__badges {
    display: flex;
}

.tl-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
}

.tl-badge--jlpt {
    background: var(--accent);
    color: #fff;
}

.tl-badge--common {
    background: var(--accent-secondary);
    color: #fff;
}

.tl-badge--pos {
    background: var(--badge-read-bg);
    color: var(--badge-read-text);
}

.tl-word-card__meanings {
    display: none;
    flex-direction: column;
    gap: 2px;
    margin-top: 6px;
}

.tl-word-card.open .tl-word-card__meanings {
    display: flex;
}

.tl-word-card__meaning {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
