* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    flex-direction: column;
}

header h1 {
    font-size: 1.2rem;
    color: #333;
    font-weight: 600;
}

#currentDate {
    font-size: 0.9rem;
    color: #666;
    margin-top: 2px;
}

.settings-link {
    color: #667eea;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.settings-link:hover,
.settings-link:active {
    background: rgba(102, 126, 234, 0.1);
}

/* Main button grid */
main {
    padding: 12px;
    overflow-y: auto;
    padding-bottom: 70px; /* Space for status bar */
}

#buttonGrid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 75px;
    gap: 10px;
    width: 100%;
}

/* Loading state */
.loading {
    grid-column: 1 / -1;
    text-align: center;
    color: white;
    font-size: 1.1rem;
    padding: 40px;
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    color: white;
    padding: 40px 20px;
}

.empty-state p {
    font-size: 1.1rem;
    margin-bottom: 20px;
    opacity: 0.9;
}

.empty-state a {
    display: inline-block;
    background: white;
    color: #667eea;
    padding: 12px 24px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s;
}

.empty-state a:hover,
.empty-state a:active {
    transform: scale(1.05);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
}

/* Quick buttons */
.quick-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    border: none;
    border-radius: 14px;
    padding: 8px;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
    position: relative;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

.quick-btn:active {
    transform: scale(0.95);
}

/* Width classes - IMPORTANT: grid-column span for different button widths */
.quick-btn.width-1 {
    grid-column: span 1;
}

.quick-btn.width-2 {
    grid-column: span 2;
}

.quick-btn.width-3 {
    grid-column: span 3;
}

/* Fallback for browsers that might not apply span correctly */
.quick-btn[class*="width-1"] {
    grid-column-end: span 1;
}

.quick-btn[class*="width-2"] {
    grid-column-end: span 2;
}

.quick-btn[class*="width-3"] {
    grid-column-end: span 3;
}

/* Button content */
.btn-name {
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
    word-break: break-word;
}

.btn-note {
    font-size: 0.8rem;
    opacity: 0.85;
    margin-top: 4px;
    text-align: center;
}

/* Flash animation */
.quick-btn.flash {
    animation: flash 0.35s ease-out;
}

@keyframes flash {
    0% {
        transform: scale(1);
        filter: brightness(1);
    }
    30% {
        transform: scale(0.92);
        filter: brightness(1.4);
    }
    100% {
        transform: scale(1);
        filter: brightness(1);
    }
}

/* Already recorded state */
.quick-btn.recorded {
    opacity: 0.5;
    position: relative;
}

.quick-btn.recorded::after {
    content: '✓';
    position: absolute;
    top: 5px;
    right: 8px;
    font-size: 1rem;
    opacity: 0.8;
}

/* Status bar */
#statusBar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 55px;
    background: rgba(51, 51, 51, 0.95);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 200;
    backdrop-filter: blur(10px);
}

#statusBar.visible {
    transform: translateY(0);
}

#statusBar.success {
    background: rgba(40, 167, 69, 0.95);
}

#statusBar.warning {
    background: rgba(255, 193, 7, 0.95);
    color: #333;
}

#statusBar.error {
    background: rgba(220, 53, 69, 0.95);
}

#statusMessage {
    font-size: 1rem;
    font-weight: 500;
    text-align: center;
    padding: 0 20px;
}

/* Responsive adjustments */
@media (min-width: 400px) {
    #buttonGrid {
        grid-auto-rows: 80px;
    }

    .btn-name {
        font-size: 1.05rem;
    }
}

@media (min-width: 500px) {
    #buttonGrid {
        grid-auto-rows: 85px;
        gap: 15px;
    }

    .quick-btn {
        border-radius: 16px;
    }

    .btn-name {
        font-size: 1.1rem;
    }
}

/* Landscape mode */
@media (orientation: landscape) and (max-height: 500px) {
    header {
        padding: 10px 15px;
    }

    header h1 {
        font-size: 1rem;
    }

    main {
        padding: 10px;
        padding-bottom: 60px;
    }

    #buttonGrid {
        grid-auto-rows: 60px;
        gap: 8px;
    }

    .quick-btn {
        padding: 6px;
    }

    .btn-name {
        font-size: 0.9rem;
    }

    .btn-note {
        font-size: 0.7rem;
    }

    #statusBar {
        height: 45px;
    }

    #statusMessage {
        font-size: 0.9rem;
    }
}

/* Safe area insets for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #statusBar {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(55px + env(safe-area-inset-bottom));
    }

    main {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
        padding-left: calc(12px + env(safe-area-inset-left));
        padding-right: calc(12px + env(safe-area-inset-right));
    }
}
