html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%; /* Prevents iOS zoom on text fields */
}

/* Modern Glass Morphism Design */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    direction: rtl; /* Ji bo nivîsa Kurdî */
    overflow-x: hidden;
    padding: 10px;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased; /* Better font rendering on mobile */
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none; /* Prevent overscroll bounce on mobile */
}

/* Logo Image Styles */
.brand-logo {
    width: 50px;
    height: 50px;
    /*border-radius: 50%; */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0; /* Prevent logo from shrinking */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    animation: logoPulse 2s ease-in-out infinite;
}

.logo-image {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Ensure image covers the container */
    /*border-radius: 50%; /* Make image circular */
    display: block;
}

/* Fallback if image doesn't load */
.brand-logo::before {
    content: "HK";
    position: absolute;
    font-weight: bold;
    font-size: 1.2rem;
    color: white;
    display: none; /* Hidden by default, shows if image fails */
}

.brand-logo.image-failed::before {
    display: flex; /* Show fallback text if image fails */
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    /* background: linear-gradient(45deg, #8e2de2, #4a00e0); */
}

@keyframes logoPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Responsive design for logo */
@media (max-width: 768px) {
    .brand-logo {
        width: 40px;
        height: 40px;
    }
    
    .brand-logo.image-failed::before {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .brand-logo {
        width: 35px;
        height: 35px;
    }
    
    .brand-logo.image-failed::before {
        font-size: 0.9rem;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .brand-logo {
        width: 30px;
        height: 30px;
    }
    
    .brand-logo.image-failed::before {
        font-size: 0.8rem;
    }
}

/* Glass container effect */
.container {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    padding: 40px;
    width: 90%;
    max-width: 700px;
    text-align: center;
    animation: fadeIn 0.8s ease-out;
    margin: 20px;
    position: relative;
    z-index: 10;
    overflow: hidden;
}

/* Subtle border glow effect */
.container::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, #8e2de2, #4a00e0, #3b82f6, #06b6d4);
    border-radius: 22px;
    z-index: -1;
    animation: borderGlow 3s ease-in-out infinite alternate;
    opacity: 0.3;
}

@keyframes borderGlow {
    0% { opacity: 0.2; }
    100% { opacity: 0.4; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

h1 {
    color: #fff;
    font-size: 2.2rem;
    margin-bottom: 15px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.1rem;
    line-height: 1.6;
}

/* Glass sentence box */
.sentence-box {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 25px;
    margin: 30px 0;
    font-size: 1.6em;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    line-height: 1.4;
    touch-action: manipulation;
    user-select: text; /* Allow text selection */
    position: relative;
    overflow: hidden;
}

.sentence-box::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: 0.5s;
}

.sentence-box:hover::before {
    left: 100%;
}

.sentence-box:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-3px);
}

/* Controls section - UPDATED FOR SINGLE ROW ON MOBILE */
.controls {
    margin-bottom: 30px;
    display: flex;
    flex-wrap: nowrap; /* Prevent wrapping */
    justify-content: center;
    gap: 8px; /* Reduced gap for mobile */
    width: 100%;
    overflow-x: auto; /* Allow horizontal scrolling if needed */
    padding: 5px 0; /* Add some padding for scroll area */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.controls::-webkit-scrollbar {
    display: none; /* Hide scrollbar */
}

/* Modern glass buttons - UPDATED FOR MOBILE */
button {
    padding: 12px 20px; /* Reduced padding for mobile */
    font-size: 1em;
    font-weight: 600;
    border: none;
    border-radius: 12px; /* Slightly smaller radius */
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    outline: none;
    min-width: 120px; /* Reduced min-width */
    min-height: 44px; /* Minimum touch target size for accessibility */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    touch-action: manipulation; /* Better touch response on mobile */
    user-select: none; /* Prevent text selection on double tap */
    transform: translateZ(0); /* Enable hardware acceleration */
    will-change: transform;
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

button::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -60%;
    width: 20px;
    height: 200%;
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(25deg);
    transition: all 0.6s;
}

button:hover::after {
    left: 120%;
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

button:hover::before {
    transform: translateX(0);
}

button:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.02); /* Reduced hover effect */
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

button:active:not(:disabled) {
    transform: translateY(1px) scale(0.98);
    transition: all 0.1s ease;
}

button:disabled {
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.5) !important;
    box-shadow: none;
    transform: none;
}

#newSentenceBtn {
    background: linear-gradient(45deg, #2193b0, #6dd5ed);
    color: white;
    box-shadow: 0 4px 15px rgba(33, 147, 176, 0.3);
}

#recordBtn {
    background: linear-gradient(45deg, #00b09b, #96c93d);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 176, 155, 0.3);
}

#recordBtn.recording {
    background: linear-gradient(45deg, #ff416c, #ff4b2b);
    animation: pulse 1.5s infinite;
    box-shadow: 0 0 20px rgba(255, 65, 108, 0.5);
    transform: scale(1.03); /* Reduced scale */
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 75, 43, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 75, 43, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 75, 43, 0); }
}

/* Animation for loading states */
@keyframes fadeInOut {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

#stopBtn {
    background: linear-gradient(45deg, #ffd700, #ffb700);
    color: #333;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
}

#submitBtn {
    background: linear-gradient(45deg, #8e2de2, #4a00e0);
    color: white;
    width: 100%;
    padding: 18px;
    font-size: 1.3em;
    border-radius: 15px;
    margin-top: 15px;
    position: relative;
    overflow: hidden;
    border: none;
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#submitBtn::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -60%;
    width: 20px;
    height: 200%;
    background: rgba(255, 255, 255, 0.4);
    transform: rotate(25deg);
    transition: all 0.6s;
}

#submitBtn:hover::after {
    left: 120%;
}

#submitBtn:hover:not(:disabled) {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 30px rgba(139, 92, 246, 0.6);
}

#submitBtn:active:not(:disabled) {
    transform: translateY(2px) scale(0.98);
    transition: all 0.1s ease;
}

/* Status indicator */
.status {
    margin: 20px 0;
    font-size: 1.2em;
    color: rgba(255, 255, 255, 0.9);
    height: 25px;
    font-weight: 500;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 25px;
}

.status.loading::after {
    content: "...";
    animation: fadeInOut 1.5s infinite;
    display: inline-block;
    width: 20px;
    margin-left: 5px;
}

audio {
    width: 100%;
    margin-top: 20px;
    display: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

/* Wave visualization */
.wave-visual {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    height: 60px;
    margin: 20px 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.wave-visual.active {
    opacity: 1;
}

.wave-visual span {
    display: inline-block;
    width: 5px;
    height: 20px;
    background: linear-gradient(to top, #3b82f6, #8b5cf6);
    margin: 0 3px;
    border-radius: 2px;
    animation: waveBar 1.2s infinite ease-in-out;
    transform-origin: bottom;
}

.wave-visual span:nth-child(1) { animation-delay: 0s; height: 15px; }
.wave-visual span:nth-child(2) { animation-delay: 0.1s; height: 30px; }
.wave-visual span:nth-child(3) { animation-delay: 0.2s; height: 45px; }
.wave-visual span:nth-child(4) { animation-delay: 0.3s; height: 30px; }
.wave-visual span:nth-child(5) { animation-delay: 0.4s; height: 15px; }

@keyframes waveBar {
    0%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(2.5); }
}

/* Focus states for accessibility */
button:focus, audio:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-left: 10px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Header styles - UPDATED FOR SINGLE ROW ON MOBILE */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 700px;
    padding: 15px 20px;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    position: relative;
    overflow: hidden;
    flex-wrap: nowrap; /* Prevent wrapping */
    gap: 15px; /* Add gap between items */
}

.top-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: 0.5s;
}

.top-bar:hover::before {
    left: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 1; /* Allow shrinking but not too much */
    min-width: 0; /* Important for text truncation */
}

.brand-logo {
    width: 45px;
    height: 45px;
    /* background: linear-gradient(45deg, #8e2de2, #4a00e0);
    /*border-radius: 50%; */
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
    color: white;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    animation: logoPulse 2s ease-in-out infinite;
    flex-shrink: 0; /* Prevent logo from shrinking */
}

@keyframes logoPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0; /* Important for text truncation */
    flex-shrink: 1;
}

.brand-title {
    font-weight: 600;
    font-size: 1.1rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-subtitle {
    font-size: 0.85rem;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.inst-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    flex-shrink: 0; /* Prevent badge from shrinking */
    white-space: nowrap;
}

.inst-badge strong {
    display: block;
    font-size: 0.9rem;
}

/* AI Voice Indicator */
.ai-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    animation: float 3s ease-in-out infinite;
}

.ai-icon {
    width: 30px;
    height: 30px;
    background: linear-gradient(45deg, #8e2de2, #4a00e0);
    border-radius: 50%;
    margin-left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: rotate 4s linear infinite;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.5);
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-8px); }
    100% { transform: translateY(0px); }
}

.ai-icon::after {
    content: "AI";
    font-size: 12px;
    font-weight: bold;
    color: white;
}

.ai-text {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.3rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* Footer styles */
.footer-note {
    margin-top: 25px;
    padding: 15px 0;
    font-size: 0.9rem;
    opacity: 0.8;
    line-height: 1.5;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

/* Status wrapper */
.status-wrapper {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 25px;
        width: 95%;
        margin: 10px;
    }
    
    h1 {
        font-size: 1.8rem;
        margin-bottom: 10px;
    }
    
    p {
        font-size: 1rem;
        line-height: 1.5;
    }
    
    .sentence-box {
        font-size: 1.3em;
        padding: 20px;
        margin: 20px 0;
    }
    
    /* Controls - SINGLE ROW ON MOBILE */
    .controls {
        flex-direction: row; /* Keep buttons in row */
        flex-wrap: nowrap; /* Prevent wrapping */
        gap: 6px; /* Even smaller gap on mobile */
        margin-bottom: 20px;
        /*justify-content: flex-start; /* Start from left */
        padding: 8px 0; /* More padding for scroll area */
    }
    
    button {
        padding: 10px 16px; /* Smaller padding */
        font-size: 0.9em;
        min-width: 100px; /* Smaller min-width */
        min-height: 42px; /* Slightly smaller but still accessible */
        border-radius: 10px;
        flex-shrink: 0; /* Important: prevent shrinking */
    }
    
    #newSentenceBtn, #recordBtn, #stopBtn {
        flex: 0 0 auto; /* Don't grow, don't shrink, auto basis */
    }
    
    #submitBtn {
        padding: 15px;
        font-size: 1.1em;
        margin-top: 10px;
    }
    
    .status {
        font-size: 1em;
        margin: 15px 0;
    }
    
    .ai-indicator {
        margin-bottom: 15px;
    }
    
    .ai-icon {
        width: 25px;
        height: 25px;
    }
    
    .ai-text {
        font-size: 1.1rem;
    }
    
    /* Header adjustments for mobile - SINGLE ROW */
    .top-bar {
        flex-direction: row; /* Keep as row on mobile */
        gap: 10px;
        padding: 12px 15px;
        margin-bottom: 15px;
    }
    
    .brand {
        gap: 8px;
        flex: 1; /* Take available space */
    }
    
    .brand-logo {
        width: 35px;
        height: 35px;
        font-size: 0.9rem;
    }
    
    .brand-title {
        font-size: 0.95rem;
    }
    
    .brand-subtitle {
        font-size: 0.75rem;
    }
    
    .inst-badge {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
    
    .inst-badge strong {
        font-size: 0.8rem;
    }
    
    /* Footer adjustments */
    .footer-note {
        font-size: 0.85rem;
        padding: 10px 0;
    }
    
    /* Wave visualization adjustments */
    .wave-visual {
        height: 50px;
        margin: 10px 0;
    }
    
    .wave-visual span {
        width: 3px;
        margin: 0 2px;
    }
}

/* Extra small devices (phones, 480px and down) */
@media (max-width: 480px) {
    .container {
        padding: 20px;
        width: 98%;
        margin: 5px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .sentence-box {
        font-size: 1.1em;
        padding: 15px;
    }
    
    /* Controls - EXTRA SMALL */
    .controls {
        gap: 4px; /* Minimal gap */
        padding: 10px 0; /* More scroll area */
    }
    
    button {
        padding: 8px 12px;
        font-size: 0.85em;
        min-width: 90px; /* Even smaller */
        min-height: 40px;
        border-radius: 8px;
    }
    
    /* Specific button adjustments for very small screens */
    #newSentenceBtn {
        min-width: 85px; /* Adjust for longer text */
    }
    
    #recordBtn {
        min-width: 80px;
    }
    
    #stopBtn {
        min-width: 75px;
    }
    
    #submitBtn {
        padding: 12px;
        font-size: 1em;
        min-height: 44px;
    }
    
    .top-bar {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .brand-logo {
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }
    
    .brand-title {
        font-size: 0.9rem;
    }
    
    .brand-subtitle {
        font-size: 0.7rem;
    }
    
    .ai-text {
        font-size: 1rem;
    }
    
    .footer-note {
        font-size: 0.8rem;
    }
    
    /* Ensure adequate touch targets */
    .controls button {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Very small screens - ensure single row */
@media (max-width: 360px) {
    .top-bar {
        padding: 8px 10px;
        gap: 6px;
    }
    
    .brand-subtitle {
        font-size: 0.65rem;
    }
    
    .inst-badge {
        font-size: 0.6rem;
        padding: 2px 5px;
    }
    
    .inst-badge strong {
        font-size: 0.7rem;
    }
    
    /* Controls - VERY SMALL */
    .controls {
        gap: 3px;
    }
    
    button {
        padding: 6px 10px;
        font-size: 0.8em;
        min-width: 80px;
        min-height: 38px;
    }
    
    #newSentenceBtn {
        min-width: 75px;
        font-size: 0.75em;
    }
    
    #recordBtn {
        min-width: 70px;
        font-size: 0.75em;
    }
    
    #stopBtn {
        min-width: 65px;
        font-size: 0.75em;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .container {
        padding: 20px;
        max-height: 80vh;
        overflow-y: auto;
    }
    
    .sentence-box {
        font-size: 1.2em;
        padding: 20px;
    }
    
    .controls {
        gap: 8px; /* More space in landscape */
        justify-content: center; /* Center in landscape */
    }
    
    button {
        padding: 10px 18px;
        min-width: 110px;
    }
    
    .top-bar {
        padding: 10px;
        margin-bottom: 10px;
    }
    
    .footer-note {
        font-size: 0.8rem;
        margin-top: 15px;
    }
}

/* Ensure buttons are visible and accessible */
@media (max-width: 320px) {
    .controls {
        gap: 2px;
    }
    
    button {
        padding: 5px 8px;
        font-size: 0.75em;
        min-width: 70px;
        min-height: 36px;
    }
    
    /* Very specific adjustments for smallest screens */
    #newSentenceBtn {
        min-width: 68px;
        font-size: 0.7em;
    }
    
    #recordBtn {
        min-width: 65px;
        font-size: 0.7em;
    }
    
    #stopBtn {
        min-width: 60px;
        font-size: 0.7em;
    }
}