/*
MIT License
Copyright (c) 2025 Livio Dalloro
See LICENSE file for details.
*/

:root {
    --bg-color: #000000;
    --text-color: #ffffff;
    --hive-color: #333333;
    --center-color: #00BFAE;
    --hive-text-color: #e6e6e6;
    --center-text-color: #ffffff;
    --btn-bg: rgba(255, 255, 255, 0.05);
    --btn-border: rgba(255, 255, 255, 0.2);
    --btn-text: #ffffff;
    --message-bg: #00BFAE;
    --message-text: #000;
    --level-bar-bg: #333;
    --highlight-color: #00BFAE;
    --glass-bg: rgba(18, 18, 18, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

html {
    touch-action: pan-x pan-y;
}

body {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    width: 100vw;
    min-height: 100svh;
    /* Handle mobile address bars better */
    overflow-x: hidden;
    overflow-y: auto;
    /* Allow scrolling if content overflows */
    display: flex;
    justify-content: center;
    touch-action: pan-x pan-y;
    -webkit-text-size-adjust: none;
}

.mobile-container {
    width: 100%;
    max-width: 500px;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top) 20px env(safe-area-inset-bottom) 20px;
    position: relative;
}

header {
    display: flex;
    flex-direction: column;
    padding: 15px 0 10px 0;
    gap: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 10px;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

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

.level-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 5px;
    border-radius: 8px;
    transition: background 0.2s;
    cursor: pointer;
}

.level-container:active {
    background: rgba(255, 255, 255, 0.05);
}

.level-text {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.dots-container {
    display: flex;
    align-items: center;
    position: relative;
    height: 2px;
    background-color: var(--level-bar-bg);
    width: 100%;
    margin-top: 10px;
    border-radius: 2px;
}

.progress-line-fill {
    position: absolute;
    height: 100%;
    background-color: var(--highlight-color);
    left: 0;
    top: 0;
    z-index: 0;
    transition: width 0.4s cubic-bezier(0.19, 1, 0.22, 1);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #444;
    position: absolute;
    transform: translate(-50%, -50%);
    top: 50%;
    z-index: 1;
    transition: all 0.3s;
}

.dot.active {
    background: var(--highlight-color);
}

.dot.current {
    width: 14px;
    height: 14px;
    background: var(--highlight-color);
    border: 3px solid var(--bg-color);
    box-shadow: 0 0 10px rgba(247, 218, 33, 0.4);
}

.score-display {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--highlight-color);
    margin-left: 20px;
    white-space: nowrap;
}

#score {
    color: #fff;
    font-weight: 700;
    font-size: 1.2rem;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.header-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 10px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.header-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.15);
}

/* Language Dropdown Menu */
.dropdown-menu {
    position: fixed;
    top: 55px;
    right: 20px;
    background-color: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 4px 0;
    z-index: 200;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
}

.dropdown-menu button {
    display: block;
    width: 100%;
    padding: 12px 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-menu button:active {
    background-color: rgba(255, 255, 255, 0.1);
}

#lang-flag {
    font-size: 1.2rem;
}

.input-area {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80px;
    margin: 10px 0;
}

#input-text {
    font-size: 2.2rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #fff;
    letter-spacing: 4px;
}

#input-text:empty::before {
    content: '';
    display: inline-block;
}

.cursor {
    width: 3px;
    height: 35px;
    background-color: #00BFAE;
    margin-left: 2px;
    animation: blink 1.2s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Total Words Row Style */
.total-words-row {
    font-weight: bold;
    border-bottom: 2px solid #ddd;
    margin-bottom: 5px;
    padding-bottom: 5px;
}

/* Hive Styling - Polished Math */
.hive-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px 0;
}

.hive {
    position: relative;
    width: 300px;
    height: 280px;
}

.cell {
    position: absolute;
    width: 100px;
    height: 86.6px;
    /* Correct height for a regular flat-top hexagon */
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    background-color: var(--hive-color);
    color: var(--hive-text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s, filter 0.1s;
    touch-action: manipulation;
}

.cell:active {
    transform: scale(0.92) !important;
    filter: brightness(1.3);
}

.cell.center {
    background-color: var(--center-color);
    color: var(--center-text-color);
    z-index: 5;
    left: 100px;
    top: 95px;
}

/* Mathematically perfect offsets for 6px spacing (Decimal precision) */
#cell-1 {
    left: 100px;
    top: 2.4px;
}

/* Top: Center - 92.6 */
#cell-2 {
    left: 180.2px;
    top: 48.7px;
}

/* Top Right: Center + (80.2, -46.3) */
#cell-3 {
    left: 180.2px;
    top: 141.3px;
}

/* Bottom Right: Center + (80.2, 46.3) */
#cell-4 {
    left: 100px;
    top: 187.6px;
}

/* Bottom: Center + 92.6 */
#cell-5 {
    left: 19.8px;
    top: 141.3px;
}

/* Bottom Left: Center + (-80.2, 46.3) */
#cell-6 {
    left: 19.8px;
    top: 48.7px;
}

/* Top Left: Center + (-80.2, -46.3) */

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    padding: 30px 0;
}

.control-btn {
    background-color: transparent;
    border: 1px solid var(--btn-border);
    color: var(--btn-text);
    padding: 16px 32px;
    border-radius: 40px;
    font-size: 1.1rem;
    font-weight: 600;
    min-width: 110px;
    transition: all 0.2s;
    touch-action: manipulation;
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.95);
}

#shuffle-btn {
    padding: 16px;
    min-width: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.words-list-container {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 1px solid #222;
    background-color: #0c0c0c;
    display: flex;
    flex-direction: column;
    border-radius: 20px;
    overflow: hidden;
    flex-shrink: 0;
    /* Prevent it from shrinking on small screens */
}

.words-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    font-size: 1rem;
    color: #888;
}

.words-actions {
    display: flex;
    gap: 10px;
}

#toggle-words-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #333;
    color: #fff;
    padding: 6px 16px;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: 600;
}

.mode-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    padding: 0 5px;
}

.words-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 20px 20px 20px;
    overflow-y: auto;
    max-height: 200px;
}

.found-word {
    font-size: 1rem;
    text-transform: capitalize;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 2px;
    margin-right: 8px;
    /* Added spacing between words */
}

/* Modals & Glassmorphism */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    margin: 15vh auto;
    padding: 0;
    border-radius: 24px;
    width: 90%;
    max-width: 400px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2,
.modal-header h3 {
    margin: 0;
    font-size: 1.3rem;
}

.close-btn,
#close-modal-btn,
#close-multi-btn {
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Rankings List */
#rankings-list,
.ranking-list {
    padding: 10px 20px 25px 20px;
}

.ranking-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: #888;
}

.ranking-row.reached {
    color: #fff;
    font-weight: 600;
}

.ranking-row.reached span:first-child::before {
    content: '✓ ';
    color: var(--highlight-color);
}

.ranking-header {
    border-bottom: 2px solid #444;
    padding-bottom: 10px;
    margin-bottom: 5px;
}

.ranking-header .rank-name,
.ranking-header .rank-score {
    font-weight: 700;
    color: #fff;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Multiplayer UI Polish */
.multi-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 500;
    padding: 20px;
    flex-direction: column;
}

.multi-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.multi-step {
    display: flex;
    flex-direction: column;
    gap: 25px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.multi-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.primary-btn {
    background: var(--highlight-color);
    color: #000;
    padding: 18px;
    border: none;
    border-radius: 16px;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: 0 4px 15px rgba(247, 218, 33, 0.2);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    font-weight: 600;
    font-size: 1.1rem;
}

.danger-btn {
    background: rgba(204, 51, 51, 0.15);
    color: #ff6666;
    border: 1px solid rgba(204, 51, 51, 0.3);
    padding: 16px;
    border-radius: 16px;
    font-weight: 600;
    margin-top: 20px;
}

input {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 18px;
    border-radius: 16px;
    font-size: 1.1rem;
    transition: all 0.2s;
}

input:focus {
    border-color: var(--highlight-color);
    background: rgba(255, 255, 255, 0.06);
}

.room-info {
    background: rgba(247, 218, 33, 0.1);
    border: 1px solid rgba(247, 218, 33, 0.2);
    padding: 20px;
    border-radius: 16px;
    text-align: center;
}

.room-info span {
    display: block;
    font-size: 0.8rem;
    color: var(--highlight-color);
    margin-bottom: 5px;
    letter-spacing: 1px;
}

#active-room-code {
    font-size: 1.4rem;
    color: #fff;
}

.player-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 15px;
}

.player-item {
    background: rgba(255, 255, 255, 0.03);
    padding: 15px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-item.self {
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.edit-link {
    color: var(--highlight-color);
    text-decoration: none;
    font-size: 0.9rem;
    margin-left: 5px;
}

/* Message Area Toast */
.message-area {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--message-bg);
    color: var(--message-text);
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 800;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    pointer-events: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.message-area.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.multiplayer-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(247, 218, 33, 0.1);
    color: var(--highlight-color);
    padding: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    margin: 10px 0;
}

.hidden {
    display: none !important;
}

/* Sharing UI */
.banner-share-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--highlight-color);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    cursor: pointer;
    transition: all 0.2s;
}

.banner-share-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.9);
}

.share-btn-inline {
    background: rgba(247, 218, 33, 0.15);
    border: none;
    color: var(--highlight-color);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    vertical-align: middle;
    cursor: pointer;
    transition: all 0.2s;
}

.share-btn-inline:active {
    transform: scale(0.9);
    background: rgba(247, 218, 33, 0.3);
}

.share-btn-alt {
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}