/* ============================================
   FONTS
   ============================================ */
@font-face {
    font-family: "TuluLipi";
    src: url("./fonts/TuluLipi.woff2") format("woff2"),
         url("./fonts/TuluLipi.woff") format("woff");
    font-display: swap;
}

/* ============================================
   GLOBAL RESET
   ============================================ */
* {
    box-sizing: border-box;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent zoom on input focus - helps keep keyboard visible */
input, textarea, select {
    font-size: 16px !important;
}

/* ============================================
   BASE LAYOUT
   ============================================ */
body {
    margin: 0;
    font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #222;
    color: #fff;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh; /* Use svh for better mobile support */
    justify-content: flex-end;
    overflow: hidden;
    position: fixed; /* Prevent body scroll */
    width: 100%;
    /* Prevent pull-to-refresh */
    overscroll-behavior: none;
}

.app-container { 
    gap: 12px;
    padding: 8px;
}

/* ============================================
   TEXT DISPLAY
   ============================================ */
#typed-text {
    font-size: 1.4rem;
    padding: 16px;
    text-align: left;
    width: 100%;
    border-bottom: 1px solid #444;
}

#display-container {
    padding: 15px 32px;
    background: #2a2a2a;
    border-radius: 8px;
    margin-bottom: 10px;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tulu-text {
    font-family: 'TuluLipi', serif;
    font-size: 32px;
    color: #f0f0f0;
    min-height: 32px;
}

.latin-subtext {
    font-family: 'Satoshi';
    font-size: 14px;
    color: #888;
    margin-top: 4px;
}

/* Copy Button Styles */
.tulu-output-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
}

.copy-button {
    padding: 8px 16px;
    background: #222;
    color: #616161;
    border: 1px solid #333;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 200;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
    margin: 4px 0px;
}

.copy-button:hover {
    background: #272727;
    box-shadow: 0 4px 12px rgba(51, 51, 51, 0.4);
}

.copy-button:active {
    transform: translateY(0);
}

.copy-button.copied {
    background: #828282;
    animation: copyPulse 0.3s ease;
}

@keyframes copyPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Make sure tulu-text takes remaining space */
.tulu-text {
    flex: 1;
}

/* ============================================
   SUGGESTION BAR
   ============================================ */
#suggestion-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: #333;
    height: 60px;
    border-bottom: 1px solid #444;
    padding: 0 8px;
    gap: 4px;
}

.suggestion {
    flex: 1;
    text-align: center;
    color: #ccc;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.suggestion:hover {
    background: rgba(255, 255, 255, 0.1);
}

.suggestion:first-child {
    color: #6c9cd6;
    font-weight: 600;
}

/* ============================================
   KEYBOARD LAYOUT
   ============================================ */
#keyboard {
    background-color: transparent;
    padding: 12px 8px 16px;
    touch-action: none;
    user-select: none;
    width: 100%;
    max-width: 100%;
    /* Ensure keyboard stays visible on mobile */
    position: relative;
    z-index: 100;
}

.key-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 8px;
    width: 100%;
}

.key {
    background: #2e2e30;
    border-radius: 8px;
    padding: 16px 8px;
    min-width: 0; /* Allow keys to shrink */
    flex: 1 1 auto; /* Flexible growth and shrink */
    max-width: 60px;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: all 0.1s ease;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    /* Better touch targets */
    min-height: 48px;
}

.key:active,
.key.active {
    background: #4c9eff;
    color: white;
    transform: scale(0.95);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.key-space {
    flex: 3 1 auto;
    max-width: 40%;
    font-size: 1rem;
}

.key-special {
    flex: 1.5 1 auto;
    max-width: 70px;
    font-weight: 600;
    font-size: 1rem;
    background: #3a3a3c;
}
.key-shift{
    min-width: 40px;
}

/* ============================================
   WELCOME MODAL
   ============================================ */
.welcome-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.welcome-box {
    background: #1a1a1a;
    padding: 28px;
    width: 85%;
    max-width: 400px;
    border-radius: 16px;
    text-align: center;
    color: #fff;
    border: 1px solid #333;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.welcome-box h2 {
    margin: 0 0 16px;
    font-size: 1.8rem;
    color: #f0f0f0;
}

.welcome-box ul {
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.6;
    margin: 16px 0 24px;
    padding-left: 20px;
    color: #ccc;
}

#welcome-start {
    background: #4c9eff;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

#welcome-start:hover {
    background: #3a8eef;
    transform: translateY(-1px);
}

/* ============================================
   TYPING TEST
   ============================================ */
#typing-test-container {
    width: 100%;
    text-align: center;
    padding: 12px 12px;
}

#target-text {
    font-size: 20px;
    font-weight: 600;
    max-width: 90%;
    margin: 0 auto 12px;
    padding: 12px;
    border-radius: 12px;
    background: #1a1a1a;
    border: 2px solid #333;
    color: #666;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Character highlighting */
#target-text .correct {
    color: #4CAF50;
}

#target-text .incorrect {
    color: #f44336;
    background: rgba(244, 67, 54, 0.2);
    border-radius: 2px;
}

#target-text .current {
    color: #4c9eff;
    background: rgba(76, 158, 255, 0.2);
    border-radius: 2px;
    animation: pulse 1s infinite;
}

#target-text .pending {
    color: #666;
}

#target-text .extra {
    color: #ff9800;
    background: rgba(255, 152, 0, 0.2);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Live stats */
#live-stats {
    font-size: 18px;
    margin-top: 0px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    color: #aaa;
    padding: 8px;
    flex-wrap: wrap;
}

#live-wpm,
#live-time,
#live-accuracy {
    padding: 8px 16px;
    background: none;
    border-radius: 8px;
    font-weight: 500;
    min-width: 80px;
}

#roman-output {
    height: fit-content;
    min-height: 16px;
}

#progress-bar {
    display: none;
    width: 0;
    height: 4px;
    background: linear-gradient(90deg, #4c9eff, #667eea);
    transition: width 0.3s ease;
    border-radius: 2px;
    margin-top: 12px;
}

#progress-bar[data-milestone="true"] {
    animation: glow 0.5s ease;
}

@keyframes glow {
    0%, 100% { box-shadow: none; }
    50% { box-shadow: 0 0 20px #4c9eff; }
}

#progress-text {
    font-size: 14px;
    color: #888;
    display: none;
    margin-top: 0px;
}

/* ============================================
   COMPLETION MODAL
   ============================================ */
.completion-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.completion-modal.show {
    opacity: 1;
}

.completion-content {
    background: #1a1a1a;
    border-radius: 16px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
}

.completion-modal.show .completion-content {
    transform: scale(1);
}

.completion-content h2 {
    font-size: 32px;
    margin: 0 0 30px;
    color: #f0f0f0;
}

.completion-stats {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 30px 0;
    gap: 24px;
    flex-wrap: wrap;
}

.stat-item {
    flex: 1;
    min-width: 100px;
    text-align: center;
}

.stat-label {
    font-size: 12px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 8px;
    font-weight: 600;
}

.stat-value {
    font-size: 32px;
    font-weight: bold;
    color: #4c9eff;
}

.completion-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 30px;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    max-width: 180px;
    padding: 14px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #4c9eff;
    color: white;
}

.btn-primary:hover {
    background: #3a8eef;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 158, 255, 0.3);
}

.btn-secondary {
    background: #333;
    color: #f0f0f0;
}

.btn-secondary:hover {
    background: #444;
    transform: translateY(-2px);
}

/* Milestone toast */
.milestone-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-30px);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: 600;
    font-size: 16px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1001;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.milestone-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   DIACRITICAL POPUP SYSTEM
   ============================================ */
.diacritic-indicator {
    position: absolute;
    top: 3px;
    right: 5px;
    font-size: 10px;
    color: #4c9eff;
    opacity: 0.7;
    font-weight: bold;
}

.diacritic-variant.active-variant {
  background: #333;
  color: white;
  transform: scale(1.2);
}


.key {
    position: relative;
}

.diacritic-popup {
    position: fixed;
    display: flex;
    gap: 4px;
    padding: 8px;
    background: #1a1a1a;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    z-index: 10000;
    transform: translateX(-50%) translateY(10px);
    opacity: 0;
    transition: all 0.2s ease;
    border: 2px solid #4c9eff;
}

.diacritic-popup.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.diacritic-variant {
    min-width: 44px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2e2e30;
    border-radius: 8px;
    font-size: 1.5rem;
    font-weight: 500;
    color: #fff;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0 8px;
}

.diacritic-variant:hover,
.diacritic-variant:active {
    background: #4c9eff;
    transform: scale(1.1);
}

.diacritic-variant.base-variant {
    border: 2px solid #4c9eff;
}

.keyboard-selector{
    display: flex;
    box-shadow: none;
    justify-content: center;
    border-color: #1a1a1a00;
    gap: 32px;
}

.keyboard-button {
    padding: 8px 16px;
    color: #aaa;
    background: #2e2e30;
    border-radius: 8px;
    font-weight: 500;
    min-width: 80px;
}

button {
    border: #2e2e30;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden {
    display: none !important;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    body {
        /* Use small viewport height to avoid browser chrome */
        height: 100svh;
    }
    
    #keyboard {
        padding: 10px 6px 14px;
    }
    
    .key-row {
        gap: 5px;
    }
    
    #target-text {
        font-size: 22px;
        padding: 12px 12px;
        max-width: 95%;
    }
    
    #live-stats {
        font-size: 16px;
        gap: 12px;
    }
    
    #live-wpm,
    #live-time,
    #live-accuracy {
        padding: 6px 12px;
        font-size: 14px;
        min-width: 70px;
    }
    
    /* Optimized keys for tablets and large phones */
    .key {
        padding: 16px 6px;
        font-size: 1.4rem;
        min-height: 50px;
        max-width: 100%;
    }
    
    .key-space {
        font-size: 0.95rem;
    }
    
    .key-special {
        font-size: 0.95rem;
    }

    .key-shift{
        padding: 0px 15px !important;
    }
}

@media (max-width: 600px) {
    #keyboard {
        padding: 8px 4px 12px;
    }
    
    .key-row {
        gap: 4px;
        margin-bottom: 6px;
    }
    
    /* Compact but still tappable for small phones */
    .key {
        padding: 20px 4px;
        font-size: 20px;
        min-height: 48px;
        border-radius: 6px;
        min-width: 36px;
    }
    
    .key-space {
        font-size: 0.9rem;
    }
    
    .key-special {
        font-size: 0.9rem;
    }
    
    .completion-content {
        padding: 30px 20px;
        width: 95%;
    }
    
    .completion-content h2 {
        font-size: 24px;
        margin-bottom: 20px;
    }
    
    .completion-stats {
        flex-direction: column;
        gap: 16px;
        margin: 20px 0;
    }
    
    .stat-value {
        font-size: 28px;
    }
    
    .completion-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn-primary,
    .btn-secondary {
        max-width: 100%;
        width: 100%;
    }
    
    #target-text {
        font-size: 20px;
        padding: 10px 12px;
    }
    
    .suggestion {
        font-size: 1rem;
        padding: 6px;
    }
    
    .diacritic-variant {
        min-width: 48px;
        height: 52px;
        font-size: 1.5rem;
    }
}

@media (max-width: 400px) {
    #keyboard {
        padding: 6px 3px 10px;
    }
    
    .key-row {
        gap: 3px;
        margin-bottom: 5px;
    }
    
    .key {
        padding: 20px 3px;
        font-size: 1.2rem;
        min-height: 44px;
        border-radius: 5px;
    }
    
    .key-space {
        font-size: 0.85rem;
    }
    
    .key-special {
        font-size: 0.85rem;
    }
    
    #target-text {
        font-size: 18px;
    }
    
    .diacritic-variant {
        min-width: 42px;
        height: 48px;
        font-size: 1.4rem;
    }
}

@media (max-width: 360px) {
    #keyboard {
        padding: 5px 2px 8px;
    }
    
    .key-row {
        gap: 2px;
        margin-bottom: 4px;
    }
    
    .key {
        padding: 16px 2px;
        font-size: 1.1rem;
        min-height: 42px;
        border-radius: 4px;
    }
    
    .key-space {
        font-size: 0.8rem;
    }
    
    .key-special {
        font-size: 0.8rem;
    }
}

/* ============================================
   LANDSCAPE MODE
   ============================================ */
@media (max-height: 600px) and (orientation: landscape) {
    body {
        height: auto;
        min-height: 100vh;
        min-height: 100svh;
    }
    
    #typing-test-container {
        padding: 4px;
    }
    
    #target-text {
        font-size: 18px;
        padding: 8px 12px;
        margin-bottom: 10px;
    }
    
    .key {
        padding: 10px 4px;
        min-height: 40px;
        font-size: 1.2rem;
    }
    
    #keyboard {
        padding: 5px 4px 8px;
    }
    
    .key-row {
        margin-bottom: 4px;
        gap: 3px;
    }
}

/* ============================================
   iOS SPECIFIC FIXES
   ============================================ */
@supports (-webkit-touch-callout: none) {
    body {
        /* iOS Safari specific height */
        min-height: -webkit-fill-available;
    }
    
    /* Prevent iOS bounce/rubber-banding */
    html {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}