/* ============================================
   JOURNEY TO JOYFUL ISLAND - RALLY GAME
   Island Adventure Themed Design System
   ============================================ */

/* Google Fonts akan di-load via <link> tag di HTML untuk lebih reliable */

:root {
    /* Island Theme - Light Mode (Tropical Sunset) */
    --bg-gradient-start: #FFE5B4;
    --bg-gradient-end: #87CEEB;
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(255, 255, 255, 0.3);
    --text-main: #2C3E50;
    --text-sec: #5A6C7D;

    /* Primary Colors - Coral/Orange Sunset */
    --primary: #FF6B6B;
    --primary-hover: #FF8E53;
    --primary-gradient: linear-gradient(135deg, #FF6B6B 0%, #FF8E53 100%);

    /* Secondary Colors - Ocean Blue */
    --secondary: #4E65FF;
    --secondary-light: #92EFFD;
    --secondary-gradient: linear-gradient(135deg, #4E65FF 0%, #92EFFD 100%);

    /* Accent Colors - Tropical Green */
    --accent: #10B981;
    --accent-light: #34D399;
    --accent-gradient: linear-gradient(135deg, #10B981 0%, #34D399 100%);

    /* Utility Colors */
    --danger: #EF4444;
    --warning: #F59E0B;
    --success: #10B981;

    /* Effects */
    --glass-bg: rgba(255, 255, 255, 0.15);
    --glass-border: rgba(255, 255, 255, 0.3);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.2);
    --radius: 16px;
    --radius-sm: 8px;
    --radius-lg: 24px;
}

[data-theme="dark"] {
    /* Island Theme - Dark Mode (Deep Ocean Night) */
    --bg-gradient-start: #0F172A;
    --bg-gradient-end: #1E293B;
    --card-bg: rgba(30, 41, 59, 0.85);
    --card-border: rgba(148, 163, 184, 0.2);
    --text-main: #F1F5F9;
    --text-sec: #94A3B8;

    /* Brighter colors for dark mode */
    --primary: #FF8E53;
    --primary-hover: #FFB088;
    --primary-gradient: linear-gradient(135deg, #FF8E53 0%, #FFB088 100%);

    --secondary: #6366F1;
    --secondary-light: #A5B4FC;
    --secondary-gradient: linear-gradient(135deg, #6366F1 0%, #A5B4FC 100%);

    --accent: #34D399;
    --accent-light: #6EE7B7;

    --danger: #F87171;
    --success: #34D399;

    --glass-bg: rgba(15, 23, 42, 0.5);
    --glass-border: rgba(148, 163, 184, 0.2);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
}

/* ============================================
   GLOBAL STYLES
   ============================================ */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    /* Font stack with comprehensive fallbacks */
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
    transition: background 0.5s ease;
}

/* Animated Wave Background */
body::before {
    content: '';
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 200px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%234E65FF' fill-opacity='0.1' d='M0,96L48,112C96,128,192,160,288,160C384,160,480,128,576,112C672,96,768,96,864,112C960,128,1056,160,1152,165.3C1248,171,1344,149,1392,138.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E") no-repeat bottom;
    background-size: cover;
    pointer-events: none;
    z-index: 0;
    animation: waveFloat 15s ease-in-out infinite;
}

@keyframes waveFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-20px);
    }
}

/* Floating Particles Animation */
.particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

/* ============================================
   LAYOUT COMPONENTS
   ============================================ */

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    position: relative;
    z-index: 10;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
    border: 1px solid var(--card-border);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: fadeInUp 0.5s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header Navigation */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 2px solid var(--card-border);
    animation: slideDown 0.4s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }

    to {
        transform: translateY(0);
    }
}

.header>div {
    font-weight: 700;
    font-size: 1.1rem;
}

h1,
h2,
h3 {
    margin: 0 0 16px 0;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    color: white;
    text-decoration: none;
    font-family: 'Poppins', sans-serif;
    position: relative;
    overflow: hidden;
    min-height: 44px;
    /* Touch-friendly */
    box-shadow: var(--shadow-sm);
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:active {
    transform: scale(0.98);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-primary {
    background: var(--primary-gradient);
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger) 0%, #DC2626 100%);
}

.btn-success {
    background: var(--accent-gradient);
}

.btn-ghost {
    background: transparent;
    color: var(--text-sec);
    border: 2px solid var(--text-sec);
    box-shadow: none;
}

.btn-ghost:hover {
    background: var(--glass-bg);
    border-color: var(--primary);
    color: var(--primary);
}

/* ============================================
   FORMS
   ============================================ */

input,
select,
textarea {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--card-border);
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    color: var(--text-main);
    font-size: 16px;
    /* Prevents zoom on iOS */
    font-family: 'Poppins', sans-serif;
    margin-bottom: 12px;
    outline: none;
    transition: all 0.3s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    background: var(--card-bg);
    box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.1);
    transform: translateY(-1px);
}

input::placeholder {
    color: var(--text-sec);
    opacity: 0.7;
}

/* ============================================
   TIMER DISPLAY
   ============================================ */

.timer-display {
    font-size: 3rem;
    font-weight: 800;
    text-align: center;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 4px 8px rgba(255, 107, 107, 0.3);
    margin: 20px 0;
    letter-spacing: 2px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }
}

.timer-display.warning {
    background: linear-gradient(135deg, var(--warning) 0%, var(--danger) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    animation: urgentPulse 1s ease-in-out infinite;
}

@keyframes urgentPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* ============================================
   PUZZLE GRID
   ============================================ */

.puzzle-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    aspect-ratio: 3/2;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    padding: 6px;
    border-radius: var(--radius);
    overflow: hidden;
    max-width: 600px;
    margin: 20px auto;
    box-shadow: var(--shadow-lg), inset 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
}

.puzzle-grid::before {
    content: '🏝️ JOYFUL ISLAND';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.15);
    pointer-events: none;
    z-index: 1;
    letter-spacing: 3px;
}

.piece {
    background-color: #1a1a1a;
    background-image: url('puzzle.jpg');
    background-size: 300% 200%;
    opacity: 0.1;
    transition: all 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    filter: grayscale(100%) blur(2px);
    position: relative;
    border-radius: 4px;
    overflow: hidden;
}

.piece::before {
    content: '🔒';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.piece.unlocked {
    opacity: 1;
    filter: grayscale(0%) blur(0);
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.3),
        0 0 20px rgba(255, 107, 107, 0.5);
    animation: pieceUnlock 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 2;
}

.piece.unlocked::before {
    content: '✨';
    opacity: 1;
    animation: sparkle 0.6s ease;
}

@keyframes pieceUnlock {
    0% {
        transform: scale(0.5) rotate(-180deg);
        opacity: 0;
    }

    50% {
        transform: scale(1.1) rotate(10deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes sparkle {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(1.5);
    }
}

/* Puzzle Positions */
.p1 {
    background-position: 0% 0%;
}

.p2 {
    background-position: 50% 0%;
}

.p3 {
    background-position: 100% 0%;
}

.p4 {
    background-position: 0% 100%;
}

.p5 {
    background-position: 50% 100%;
}

.p6 {
    background-position: 100% 100%;
}

/* ============================================
   TABLE
   ============================================ */

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

thead {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
}

th {
    padding: 14px 16px;
    text-align: left;
    font-weight: 700;
    color: var(--text-main);
    border-bottom: 2px solid var(--card-border);
}

td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--card-border);
    transition: background 0.2s ease;
}

tr:hover td {
    background: var(--glass-bg);
}

tr:last-child td {
    border-bottom: none;
}

.badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.bg-green {
    background: rgba(16, 185, 129, 0.2);
    color: var(--accent);
    border: 1px solid var(--accent);
}

.bg-red {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
    border: 1px solid var(--danger);
}

/* ============================================
   THEME TOGGLE
   ============================================ */

.theme-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-gradient);
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 1.5rem;
    z-index: 999;
    border: 3px solid var(--card-bg);
    transition: all 0.3s ease;
    animation: float 3s ease-in-out infinite;
}

.theme-toggle:hover {
    transform: scale(1.1) translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.theme-toggle:active {
    transform: scale(0.95) translateY(0);
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

/* ============================================
   MOBILE SPECIFIC
   ============================================ */

.mobile-card {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-group input {
    margin-bottom: 0;
    flex: 1;
}

.input-group button {
    flex-shrink: 0;
}

/* Sticky Controls */
.sticky-controls {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    padding: 12px 0;
    z-index: 99;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin: -20px -20px 20px -20px;
    padding: 20px;
}

details {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    border: 1px solid var(--card-border);
}

summary {
    font-weight: 700;
    cursor: pointer;
    padding: 8px;
    transition: color 0.2s ease;
}

summary:hover {
    color: var(--primary);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    .card {
        padding: 20px;
        border-radius: var(--radius-sm);
    }

    .timer-display {
        font-size: 2.5rem;
    }

    h1 {
        font-size: 1.8rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.2rem;
    }

    .btn {
        padding: 14px 20px;
        font-size: 0.9rem;
    }

    .puzzle-grid {
        gap: 4px;
        padding: 4px;
    }

    table {
        font-size: 0.9rem;
    }

    th,
    td {
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .timer-display {
        font-size: 2rem;
    }

    .header {
        padding: 12px 16px;
    }

    .theme-toggle {
        width: 48px;
        height: 48px;
        bottom: 16px;
        right: 16px;
    }
}

/* ============================================
   CELEBRATION EFFECTS
   ============================================ */

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background: var(--primary);
    opacity: 0;
    animation: confettiFall 3s ease-out forwards;
    z-index: 9999;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg);
    }
}

/* Success Toast */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    padding: 16px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--accent);
    z-index: 9999;
    animation: toastSlide 0.4s ease;
    font-weight: 600;
}

@keyframes toastSlide {
    from {
        transform: translateX(-50%) translateY(-100px);
        opacity: 0;
    }

    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

/* Loading Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--glass-bg);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}