/* Custom Animations and Micro-interactions */
body {
    -webkit-tap-highlight-color: transparent;
    font-size: 1rem;
    overflow-x: hidden;
}

body.study-active,
body:has(#app.study-mode) {
    height: var(--app-vh, 100dvh);
    min-height: var(--app-vh, 100dvh);
    overflow: hidden;
}

#toast-container {
    max-width: min(24rem, calc(100vw - 2rem));
    pointer-events: none;
}

.app-toast {
    pointer-events: auto;
}

.app-dialog-overlay {
    animation-duration: 0.18s;
}

.app-dialog-overlay.app-dialog-closing {
    opacity: 0;
    transition: opacity 0.14s ease;
}

.app-dialog-card {
    transform-origin: center;
}

.app-dialog-closing .app-dialog-card {
    transform: translateY(0.4rem) scale(0.98);
    transition: transform 0.14s ease;
}

.app-dialog-action:focus-visible {
    outline: 3px solid rgba(99, 102, 241, 0.35);
    outline-offset: 2px;
}

:root {
    font-size: 16.5px;
}

@media (min-width: 768px) {
    :root {
        font-size: 17px;
    }
}

@media (max-width: 380px) {
    :root {
        font-size: 16px;
    }
}

#app {
    min-height: 100svh;
}

#app.study-mode {
    width: 100%;
    max-width: none;
    height: var(--app-vh, 100dvh);
    min-height: 0;
    padding-bottom: 0 !important;
    overflow: hidden;
}

/* Glassmorphism utilities */
.glass {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.dark .glass {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Loader */
.loader {
    border-top-color: #6366f1;
    -webkit-animation: spinner 1.5s linear infinite;
    animation: spinner 1.5s linear infinite;
}

@keyframes spinner {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Animations */
.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

.slide-up {
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.slide-in-right {
    animation: slideInRight 0.3s ease-out forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInRight {
    from { transform: translateX(50px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.dark ::-webkit-scrollbar-thumb {
    background: #475569;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Card Hover Effects */
.hover-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hover-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

/* Flashcard Flip Animation */
.perspective-1000 {
    perspective: 1000px;
}

.transform-style-3d {
    transform-style: preserve-3d;
}

.backface-hidden {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.rotate-y-180 {
    transform: rotateY(180deg);
}

.flip-card-inner {
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner {
    transform: rotateY(180deg);
}

/* Gradient text */
.text-gradient {
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-image: linear-gradient(to right, #6366f1, #ec4899);
}

/* Responsive study/check surfaces */
.app-screen {
    min-height: 100svh;
}

.study-shell {
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.study-header,
.study-footer {
    flex: 0 0 auto;
}

.study-main {
    flex: 1 1 auto;
    min-height: 0;
    padding: clamp(0.5rem, 2svh, 1rem);
}

.study-footer {
    padding: clamp(0.5rem, 1.8svh, 1rem);
    padding-bottom: max(clamp(0.5rem, 1.8svh, 1rem), env(safe-area-inset-bottom));
}

.study-card {
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

.study-content {
    min-height: clamp(11rem, 38svh, 18rem);
    max-height: 100%;
    padding: clamp(1rem, 3.2svh, 2rem);
    overflow: hidden;
}

.study-footer-row {
    align-items: stretch;
}

.study-back-action {
    min-width: 0;
    min-height: 3.05rem;
    padding: 0.75rem 0.35rem;
    line-height: 1;
}

.study-icon-action {
    width: 2.1rem;
    height: 2.1rem;
    font-size: 0.95rem;
}

.fit-text {
    font-size: clamp(var(--fit-min, 1.25rem), var(--fit-fluid, 8vw), var(--fit-max, 3.6rem));
    line-height: 1.12;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
}

.meaning-text {
    line-height: 1.42;
}

.compact-status-row span:first-child {
    min-width: 0;
}

.home-card button {
    min-width: 0;
    white-space: normal;
    line-height: 1.2;
}

.record-dot {
    display: inline-block;
    width: 0.48rem;
    height: 0.48rem;
    border-radius: 9999px;
    border-width: 1px;
    border-style: solid;
}

.mobile-group-card {
    min-width: 0;
}

.mobile-group-title {
    touch-action: manipulation;
}

.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.mobile-search-row {
    min-height: 3.1rem;
}

.detail-table {
    table-layout: fixed;
    border-collapse: collapse;
    --detail-row-height: 3.45rem;
    --detail-word-col-mobile: 28%;
}

.detail-col-index {
    width: 1.75rem;
}

.detail-col-record {
    width: 1.8rem;
}

.detail-col-word {
    width: 32%;
}

.detail-col-meaning {
    width: auto;
}

.detail-table th,
.detail-table td {
    vertical-align: middle;
}

.detail-word-heading {
    position: relative;
}

.detail-column-resizer {
    display: none;
}

.detail-word-cell {
    height: var(--detail-row-height);
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    overflow: hidden;
}

.detail-index-cell,
.detail-record-cell {
    height: var(--detail-row-height);
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    vertical-align: middle;
}

.detail-index-cell span,
.detail-record-cell .record-compact {
    vertical-align: middle;
}

.detail-cell-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    width: calc(100% / var(--detail-scale-x, 1));
    max-height: calc(var(--detail-font-size, 0.9rem) * var(--detail-line-height, 1.14) * 2);
    overflow: hidden;
    font-size: var(--detail-font-size, 0.9rem);
    line-height: var(--detail-line-height, 1.14);
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
    transform: scaleX(var(--detail-scale-x, 1));
    transform-origin: left center;
}

.detail-word-text {
    -webkit-line-clamp: 3;
    max-height: calc(var(--detail-font-size, 0.9rem) * var(--detail-line-height, 1.14) * 3);
    color: #111827;
    font-weight: 600;
}

.detail-meaning-text {
    color: #4b5563;
}

.detail-row td {
    border-top: 1px solid #eef2f7;
    height: var(--detail-row-height);
}

.detail-row:first-child td {
    border-top: 0;
}

.detail-row-section td {
    border-top: 2px solid #cbd5e1;
}

.detail-row-major td {
    border-top: 4px double #64748b;
}

.record-compact {
    width: 1.45rem;
    min-width: 1.45rem;
    height: 1.45rem;
    font-size: 0.72rem;
    line-height: 1;
}

@media (max-width: 640px) {
    #toast-container {
        top: auto !important;
        right: 0.75rem !important;
        bottom: max(0.75rem, env(safe-area-inset-bottom)) !important;
        left: 0.75rem !important;
        align-items: stretch;
        gap: 0.4rem;
    }

    .app-toast {
        width: 100%;
        margin-bottom: 0 !important;
        padding: 0.62rem 0.72rem !important;
        border-radius: 0.75rem;
        box-shadow: 0 12px 30px -12px rgba(15, 23, 42, 0.45);
    }

    .app-toast i {
        font-size: 0.98rem !important;
        margin-right: 0.5rem !important;
    }

    .toast-message {
        font-size: 0.9rem !important;
        line-height: 1.15;
    }

    .toast-close {
        width: 1.75rem !important;
        height: 1.75rem !important;
        padding: 0.25rem !important;
    }

    .study-header {
        padding: 0.55rem 0.65rem;
    }

    .study-main {
        padding: 0.55rem;
    }

    .study-content {
        min-height: clamp(9.5rem, 32svh, 14rem);
        padding: 0.85rem;
    }

    .study-footer {
        padding-left: 0.65rem;
        padding-right: 0.65rem;
    }

    .study-action {
        padding-top: 0.75rem !important;
        padding-bottom: 0.75rem !important;
        font-size: 1rem !important;
    }

    .study-back-action {
        min-height: 2.75rem;
        padding: 0.65rem 0.2rem;
        font-size: 0.92rem;
        gap: 0.3rem;
    }

    .study-back-action span {
        display: none;
    }

    .study-icon-action {
        width: 2rem;
        height: 2rem;
    }

    .home-group-grid {
        gap: 0.6rem;
    }

    .app-nav {
        min-height: 3rem;
    }

    .detail-table {
        --detail-row-height: 3.1rem;
    }

    .detail-col-index {
        width: 1.45rem;
    }

    .detail-col-record {
        width: 1.35rem;
    }

    .detail-col-word {
        width: var(--detail-word-col-mobile, 28%);
    }

    .detail-column-resizer {
        display: block;
        position: absolute;
        top: 0;
        right: -0.75rem;
        width: 1.5rem;
        height: 100%;
        cursor: col-resize;
        touch-action: none;
        opacity: 0;
        z-index: 2;
    }

    .detail-column-resizing {
        cursor: col-resize;
        user-select: none;
    }

    .detail-word-cell {
        padding-left: 0.25rem !important;
        padding-right: 0.25rem !important;
    }

    .detail-index-cell {
        padding-left: 0.2rem !important;
        padding-right: 0.2rem !important;
        font-size: 0.75rem !important;
    }

    .detail-record-cell {
        padding-left: 0.1rem !important;
        padding-right: 0.1rem !important;
    }

    .record-compact {
        width: 1.12rem;
        min-width: 1.12rem;
        height: 1.12rem;
        font-size: 0.62rem;
        border-radius: 0.38rem;
    }
}
