@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600;700&family=Nunito:wght@600;700;800&display=swap');

:root {
    /* Kid-friendly palette */
    --primary: #5B8DEF;          /* friendly sky blue */
    --primary-hover: #4574db;
    --primary-shadow: #3a62b9;
    --accent-yellow: #FFC845;    /* sunny yellow */
    --accent-yellow-shadow: #E09D1C;
    --accent-coral: #FF6B9D;     /* coral pink */
    --accent-coral-shadow: #D64B7B;
    --accent-mint: #34D399;      /* mint green */
    --accent-mint-shadow: #16A876;
    --accent-purple: #A78BFA;

    --danger: #FB7185;
    --danger-shadow: #D94A5C;

    --bg-gradient: linear-gradient(135deg, #FFF7E6 0%, #E6F2FF 50%, #FFE9F2 100%);
    --panel-bg: rgba(255, 255, 255, 0.92);
    --text-main: #2D3A5F;
    --text-muted: #7A8AB0;
    --border-color: #E3EAFF;

    --cell-size: 56px;
    --cell-bg: #ffffff;
    --cell-header-bg: #FFF3C4;
    --cell-header-color: #B4710F;
    --cell-correct: #C6F7E1;
    --cell-error: #FFD7DF;

    --display-font: 'Fredoka', 'Nunito', 'Malgun Gothic', sans-serif;
    --body-font: 'Nunito', 'Fredoka', 'Malgun Gothic', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: var(--body-font);
}

body {
    background: var(--bg-gradient);
    background-attachment: fixed;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-main);
    user-select: none;
    overflow-x: hidden;
    position: relative;
}

/* ---------- Floating background decorations ---------- */
.bg-decorations {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.deco {
    position: absolute;
    font-size: 2.4rem;
    opacity: 0.55;
    font-family: var(--display-font);
    font-weight: 700;
    color: var(--primary);
    animation: float 12s ease-in-out infinite;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.08));
}

.deco-1  { top: 6%;  left: 4%;   animation-delay: 0s;   color: var(--accent-coral); }
.deco-2  { top: 18%; left: 88%;  animation-delay: 1.2s; color: var(--accent-yellow); font-size: 2.8rem; }
.deco-3  { top: 42%; left: 2%;   animation-delay: 2.4s; color: var(--accent-mint); }
.deco-4  { top: 70%; left: 6%;   animation-delay: 3.1s; font-size: 2.6rem; }
.deco-5  { top: 82%; left: 90%;  animation-delay: 0.6s; color: var(--accent-purple); }
.deco-6  { top: 12%; left: 50%;  animation-delay: 4s;   font-size: 2.6rem; }
.deco-7  { top: 55%; left: 94%;  animation-delay: 1.8s; color: var(--accent-yellow); }
.deco-8  { top: 32%; left: 10%;  animation-delay: 2.7s; color: var(--accent-coral); font-size: 3rem; }
.deco-9  { top: 88%; left: 30%;  animation-delay: 3.6s; color: var(--accent-mint); font-size: 3rem; }
.deco-10 { top: 28%; left: 78%;  animation-delay: 4.5s; color: var(--primary); font-size: 3.2rem; }
.deco-11 { top: 65%; left: 45%;  animation-delay: 5s;   color: var(--accent-purple); font-size: 2.8rem; }
.deco-12 { top: 92%; left: 72%;  animation-delay: 2.2s; }

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(-4deg); }
    50%      { transform: translateY(-22px) rotate(4deg); }
}

/* ---------- App container ---------- */
#app {
    width: 100%;
    max-width: 1400px; /* Increased for multiplayer */
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* ---------- Screens ---------- */
.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border-radius: 32px;
    padding: 44px 40px;
    box-shadow:
        0 20px 40px -10px rgba(91, 141, 239, 0.25),
        0 8px 16px -4px rgba(255, 107, 157, 0.12),
        inset 0 0 0 3px rgba(255,255,255,0.6);
    border: 3px solid rgba(255,255,255,0.8);
}

.screen.active {
    display: flex;
    animation: bounceIn 0.5s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes bounceIn {
    0%   { opacity: 0; transform: scale(0.85) translateY(20px); }
    60%  { opacity: 1; transform: scale(1.03) translateY(-4px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- Title ---------- */
.title-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 4px;
}

.title-emoji {
    font-size: 2.6rem;
    animation: wiggle 2.2s ease-in-out infinite;
    display: inline-block;
}
.title-emoji:last-child { animation-delay: 1.1s; }

@keyframes wiggle {
    0%, 100% { transform: rotate(-10deg) scale(1); }
    50%      { transform: rotate(10deg)  scale(1.1); }
}

h1 {
    font-family: var(--display-font);
    font-weight: 700;
    font-size: 3.2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent-coral) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 10px rgba(91, 141, 239, 0.15);
    letter-spacing: -1px;
}

.subtitle {
    font-size: 1.15rem;
    color: var(--text-muted);
    margin-bottom: 36px;
    font-weight: 700;
}

/* ---------- Settings ---------- */
.settings {
    width: 100%;
    max-width: 560px;
    margin-bottom: 30px;
}

.setting-group {
    margin-bottom: 26px;
}

.setting-group > label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: var(--display-font);
    font-weight: 700;
    margin-bottom: 14px;
    font-size: 1.25rem;
    color: var(--text-main);
}

.label-icon {
    font-size: 1.4rem;
}

.radio-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.radio-group input[type="radio"] {
    display: none;
}

.radio-group label {
    padding: 13px 22px;
    background: #fff;
    border: 3px solid var(--border-color);
    border-radius: 18px;
    cursor: pointer;
    font-weight: 800;
    font-size: 1rem;
    transition: transform 0.15s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
    text-align: center;
    box-shadow: 0 4px 0 #D6DEF5;
}

.radio-group label:hover {
    border-color: #B8C8F2;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #D6DEF5;
}

.radio-group input[type="radio"]:checked + label {
    background: linear-gradient(135deg, var(--primary) 0%, #7FA7F5 100%);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 0 var(--primary-shadow);
    transform: translateY(0);
}

.radio-group input[type="radio"]:checked + label:hover {
    box-shadow: 0 6px 0 var(--primary-shadow);
    transform: translateY(-2px);
}

/* ---------- Actions & Buttons ---------- */
.actions {
    display: flex;
    gap: 16px;
    margin-top: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

button {
    padding: 15px 32px;
    border: none;
    border-radius: 18px;
    font-family: var(--display-font);
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.2s;
}

/* 3D chunky button style */
.primary-btn {
    background: linear-gradient(180deg, #FFD66B 0%, var(--accent-yellow) 100%);
    color: #6B3F00;
    box-shadow: 0 6px 0 var(--accent-yellow-shadow), 0 10px 16px rgba(224, 157, 28, 0.25);
}
.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--accent-yellow-shadow), 0 14px 20px rgba(224, 157, 28, 0.3);
}
.primary-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--accent-yellow-shadow), 0 4px 8px rgba(224, 157, 28, 0.2);
}

.secondary-btn {
    background: white;
    color: var(--primary);
    box-shadow: 0 6px 0 var(--border-color), 0 10px 16px rgba(91, 141, 239, 0.1);
    border: 3px solid var(--border-color);
}
.secondary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 0 var(--border-color), 0 14px 20px rgba(91, 141, 239, 0.15);
    border-color: #B8C8F2;
}
.secondary-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 var(--border-color), 0 4px 8px rgba(91, 141, 239, 0.1);
}

.danger-btn {
    background: linear-gradient(180deg, #FF9BAE 0%, var(--danger) 100%);
    color: white;
    padding: 10px 20px;
    font-size: 1rem;
    box-shadow: 0 4px 0 var(--danger-shadow);
}
.danger-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 0 var(--danger-shadow);
}
.danger-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 var(--danger-shadow);
}

/* ---------- Game Screen ---------- */
.game-header {
    width: 100%;
    max-width: 720px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding: 16px 26px;
    background: white;
    border-radius: 22px;
    box-shadow: 0 8px 20px rgba(91, 141, 239, 0.15);
    border: 3px solid var(--border-color);
}

.timer {
    font-family: var(--display-font);
    font-size: 2.3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    letter-spacing: 2px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent-coral) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#game-mode-label {
    font-family: var(--display-font);
    font-weight: 700;
    color: #0B6F4B;
    background: linear-gradient(135deg, #B9F4DC 0%, #7FE3B7 100%);
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 1.1rem;
    border: 2px solid #7FE3B7;
}

/* ---------- Players Container ---------- */
.players-container {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    width: 100%;
    justify-content: center;
    margin-top: 10px;
}

.player-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.6);
    border: 3px dashed var(--border-color);
    border-radius: 24px;
    padding: 20px;
    flex: 1;
    min-width: 300px;
    max-width: 480px;
    transition: all 0.3s;
}

.player-area.finished {
    border-color: var(--accent-yellow);
    background: #FFFBEB;
    box-shadow: 0 10px 20px rgba(255, 200, 69, 0.2);
}

.player-header {
    display: flex;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 12px;
    align-items: center;
}

.player-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-timer {
    font-family: var(--display-font);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
    background: #F0F4FF;
    padding: 4px 10px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.player-name {
    font-family: var(--display-font);
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--primary);
    background: white;
    padding: 4px 14px;
    border-radius: 12px;
    box-shadow: 0 4px 0 var(--border-color);
}

.player-status {
    font-weight: 700;
    color: var(--accent-coral);
    font-size: 1.2rem;
}

/* ---------- Board ---------- */
.board-container {
    width: 100%;
    overflow-x: auto;
    padding: 10px 0;
    display: flex;
    justify-content: center;
}

.board {
    display: grid;
    gap: 4px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent-purple) 100%);
    padding: 6px;
    border-radius: 18px;
    width: fit-content;
    box-shadow: 0 15px 30px -6px rgba(91, 141, 239, 0.25);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--cell-bg);
    font-family: var(--display-font);
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-main);
    border-radius: 8px;
}

.cell.header {
    background: var(--cell-header-bg);
    color: var(--cell-header-color);
}

.cell.corner {
    background: linear-gradient(135deg, var(--accent-coral) 0%, #FF9AB8 100%);
    color: white;
    font-size: 1.9rem;
    border-radius: 14px 8px 8px 8px;
    box-shadow: inset 0 -3px 0 rgba(0,0,0,0.1);
}

.cell input {
    width: 100%;
    height: 100%;
    border: none;
    text-align: center;
    font-family: var(--display-font);
    font-size: 1.4rem;
    font-weight: 700;
    outline: none;
    background: transparent;
    transition: background 0.2s, box-shadow 0.2s, color 0.2s;
    -moz-appearance: textfield;
    border-radius: 8px;
    color: var(--text-main);
}

.cell input::-webkit-outer-spin-button,
.cell input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cell input:focus, .cell input.active-cell {
    background: #FFFBEB;
    box-shadow: inset 0 0 0 3px var(--accent-yellow);
}

.cell input:disabled {
    color: #0B6F4B;
}

.cell input.correct {
    background: var(--cell-correct);
    box-shadow: none;
    animation: pop 0.35s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.25) rotate(-4deg); }
    70%  { transform: scale(0.95) rotate(3deg); }
    100% { transform: scale(1) rotate(0); }
}

.cell input.error {
    background: var(--cell-error);
    color: #991B1B;
    animation: shake 0.35s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-5px) rotate(-2deg); }
    40%      { transform: translateX(5px)  rotate(2deg); }
    60%      { transform: translateX(-4px) rotate(-1deg); }
    80%      { transform: translateX(4px)  rotate(1deg); }
}

/* ---------- Keyboard Section ---------- */
.keyboard-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    margin-top: 16px;
}

.side-controls {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    max-width: 280px;
}

.side-controls .danger-btn {
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 1rem;
}

.virtual-keyboard {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 280px;
}

.v-key {
    background: white;
    border: 3px solid var(--border-color);
    border-radius: 16px;
    font-family: var(--display-font);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
    padding: 14px 0;
    cursor: pointer;
    box-shadow: 0 6px 0 var(--border-color);
    transition: transform 0.1s, box-shadow 0.1s;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.v-key:active {
    transform: translateY(6px);
    box-shadow: 0 0 0 var(--border-color);
}

.v-key.action-key {
    background: #F0F4FF;
    color: var(--primary);
    font-size: 1.5rem;
}

/* ---------- Modals ---------- */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(45, 58, 95, 0.45);
    backdrop-filter: blur(6px);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.25s ease-out;
}

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

.modal-content {
    background: white;
    padding: 44px 40px;
    border-radius: 30px;
    width: 90%;
    max-width: 620px;
    position: relative;
    box-shadow:
        0 25px 50px -12px rgba(91, 141, 239, 0.35),
        inset 0 0 0 3px rgba(255,255,255,0.9);
    border: 4px solid var(--border-color);
    animation: popUp 0.4s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes popUp {
    from { transform: translateY(40px) scale(0.9); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

.close-btn {
    position: absolute;
    top: 16px; right: 20px;
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    border-radius: 50%;
    background: var(--border-color);
    transition: background 0.2s, color 0.2s, transform 0.15s;
}

.close-btn:hover {
    background: var(--accent-coral);
    color: white;
    transform: rotate(90deg);
}

h2 {
    font-family: var(--display-font);
    font-weight: 700;
    text-align: center;
    color: var(--primary);
    margin-bottom: 20px;
    font-size: 1.8rem;
}

.record-filter {
    margin: 20px 0;
    text-align: center;
}

.record-filter select {
    padding: 12px 22px;
    border-radius: 14px;
    border: 3px solid var(--border-color);
    font-family: var(--body-font);
    font-size: 1.05rem;
    font-weight: 700;
    outline: none;
    cursor: pointer;
    background: #F9FAFF;
    color: var(--text-main);
    transition: border-color 0.2s;
}

.record-filter select:hover {
    border-color: var(--primary);
}

.best-score {
    text-align: center;
    font-family: var(--display-font);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 30px;
    color: #6B3F00;
    background: linear-gradient(135deg, #FFF1BE 0%, #FFDE82 100%);
    padding: 18px;
    border-radius: 18px;
    border: 3px solid var(--accent-yellow);
}

.best-score .trophy {
    font-size: 1.5rem;
    margin-right: 6px;
}

#best-time {
    font-weight: 700;
    color: #C25C00;
    font-size: 1.5rem;
    margin-left: 10px;
}

.chart-container {
    position: relative;
    height: 260px;
    width: 100%;
    padding: 10px;
    background: #F9FAFF;
    border-radius: 16px;
    border: 2px dashed var(--border-color);
}

/* ---------- Result Modal ---------- */
.result-content {
    text-align: center;
}

.celebrate {
    font-size: 4rem;
    display: inline-block;
    animation: celebrate 1.2s ease-in-out infinite;
}

@keyframes celebrate {
    0%, 100% { transform: translateY(0) rotate(-10deg); }
    50%      { transform: translateY(-12px) rotate(10deg); }
}

.result-time {
    font-family: var(--display-font);
    font-size: 3.6rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent-coral) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 16px 0;
    font-variant-numeric: tabular-nums;
    letter-spacing: 2px;
}

#result-message {
    color: var(--text-main);
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    background: #FFF3C4;
    padding: 14px 20px;
    border-radius: 16px;
    display: inline-block;
}

/* ---------- Responsiveness ---------- */
@media (max-width: 640px) {
    :root {
        --cell-size: 46px;
    }

    .cell { font-size: 1.1rem; }
    .cell input { font-size: 1.2rem; }
    .cell.corner { font-size: 1.5rem; }

    .screen { padding: 28px 20px; border-radius: 26px; }
    h1 { font-size: 2.3rem; }
    .title-emoji { font-size: 2rem; }
    .timer { font-size: 1.8rem; }

    .deco { font-size: 1.8rem; opacity: 0.35; }

    button { padding: 12px 22px; font-size: 1rem; }
}

@media (max-width: 450px) {
    :root {
        --cell-size: 38px;
    }
    .game-header {
        flex-direction: column;
        gap: 10px;
    }
    .cell { font-size: 0.95rem; }
    .cell input { font-size: 1rem; }
    h1 { font-size: 2rem; }
    .radio-group label { padding: 10px 14px; font-size: 0.9rem; }
    .keyboard-section { gap: 10px; }
    .side-controls .danger-btn { padding: 12px 14px; font-size: 1rem; }
    .virtual-keyboard { gap: 8px; max-width: 260px; }
    .v-key { font-size: 1.5rem; padding: 10px 0; border-radius: 12px; box-shadow: 0 4px 0 var(--border-color); }
    .v-key:active { transform: translateY(4px); box-shadow: 0 0 0 var(--border-color); }
}
