@font-face {
    font-family: 'Noto Sans JP';
    src: url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP&display=swap');
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --kanji-size: 3rem;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: #000;
    color: #0f0;
    font-family: 'Noto Sans JP', sans-serif;
}

body {
    overflow: hidden;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 20px;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

h1 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 2rem;
}

.controls-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px;
    z-index: 100;
    display: flex;
    justify-content: center;
}

.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.top-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.navigation-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.range-inputs {
    order: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.range-inputs input {
    width: 60px;
    padding: 8px;
    font-size: 0.9rem;
    background-color: #111;
    color: #0f0;
    border: 1px solid #0f0;
    border-radius: 4px;
    margin: 0 5px;
}

.range-note {
    font-size: 0.7rem;
    color: #0f0;
    margin-left: 10px;
}

#start-button {
    padding: 8px 15px;
    font-size: 0.9rem;
    background-color: #0f0;
    color: #000;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 10px;
}

.buttons-row {
    display: flex;
    gap: 10px;
    align-items: center;
    white-space: nowrap;
}

.buttons-row button {
    padding: 8px 12px;
    font-size: 0.9rem;
    background-color: rgba(0, 255, 0, 0.2);
    color: #0f0;
    border: 1px solid #0f0;
    border-radius: 4px;
    cursor: pointer;
}

#previous-button, #next-button {
    padding: 8px 15px;
    font-size: 0.9rem;
    background-color: rgba(0, 255, 0, 0.2);
    color: #0f0;
    border: 1px solid #0f0;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 10px;
}

#kanji-display {
    position: relative;
    flex-grow: 1;
    overflow: hidden;
    transition: width 0.3s ease, float 0.3s ease;
}

.kanji {
    position: absolute;
    color: #0f0;
    font-size: var(--kanji-size);
    animation: drop 4s linear;
    user-select: none;
}

.kanji-trail {
    position: absolute;
    font-size: 2.5rem;
    color: #0f0;
    opacity: 0.3;
    z-index: 4;
    animation: fade 1s linear forwards;
}

@keyframes drop {
    0% {
        top: -50px;
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        top: 100vh;
        opacity: 0;
    }
}

@keyframes fade {
    0% {
        opacity: 0.3;
    }
    100% {
        opacity: 0;
    }
}

@keyframes blinkRedGreen {
    0% { color: #0f0; }
    20% { color: #f00; }
    40% { color: #0f0; }
    60% { color: #f00; }
    80% { color: #0f0; }
    100% { color: #f00; }
}

.kanji-blink {
    animation: blinkRedGreen 1s linear;
    animation-fill-mode: forwards;
    animation-iteration-count: 1;
    animation-play-state: running !important;
}

#meaning-display {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}

.meaning-container {
    position: fixed;
    top: 120px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 20px;
    border-radius: 10px;
    animation: fadeInOut 2s ease-in-out;
    z-index: 20;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 1; }
}

.kanji-large {
    font-size: 5rem;
    color: #f00;
    margin-bottom: 10px;
}

.meaning-text {
    font-size: 2rem;
    color: #f00;
}

#history-section, #vocab-section, #mylist-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40%;
    background-color: rgba(0, 0, 0, 0.9);
    border-top: 1px solid #0f0;
    z-index: 30;
    overflow-y: auto;
    display: none;
}

#history-list, #vocab-list, #mylist-list {
    padding: 10px;
    max-height: 100%;
    overflow-y: auto;
}

.history-item, .vocab-item, .mylist-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 20px;
    border-bottom: 1px solid rgba(0, 255, 0, 0.3);
    width: 100%;
}

.left-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.vocab-index, .mylist-index {
    color: #0f0;
    width: 40px;
    text-align: right;
    margin-right: 1em;
}

.history-kanji, .vocab-kanji {
    font-size: 1.5rem;
    color: #0f0;
    min-width: 40px;
    text-align: left;
    margin-right: 1em;
}

.history-meaning, .vocab-meaning {
    color: #0f0;
    text-align: right;
    padding-right: 20px;
    min-width: 150px;
}

.wrong-count {
    color: #f00;
    margin: 0 15px;
    min-width: 30px;
    text-align: right;
    user-select: none;
}

.right-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.remove-button {
    background-color: #f00;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    margin-left: 10px;
    min-width: 70px;
    text-align: center;
    pointer-events: auto;
    user-select: none;
}

.copy-text {
    display: inline-block;
    white-space: pre;
    user-select: text;
    font-size: 1.5rem;
}

#size-increase, #size-decrease {
    background-color: #000;
    color: #0f0;
    border: 1px solid #0f0;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 1.2rem;
    font-weight: bold;
    min-width: 40px;
    margin: 0 5px;
    cursor: pointer;
}

.size-display {
    color: #0f0;
    font-size: 1.2rem;
    padding: 0 10px;
    min-width: 40px;
    text-align: center;
    display: inline-block;
}

.size-note {
    color: #0f0;
    font-size: 1.2rem;
    margin-left: 15px;
    margin-right: 5px;
}

/* Hide mobile text by default (desktop view) */
.mobile-only {
    display: none;
}

/* Mobile styles */
@media (max-width: 768px) {
    /* Hide title on mobile */
    .title {
        display: none;
    }
    
    /* Fix container positioning to avoid URL bar */
    .controls-container {
        position: fixed;
        top: 20px; /* Move down to avoid URL bar */
        left: 0;
        right: 0;
        padding: 10px;
        z-index: 100;
        background: rgba(0, 0, 0, 0.9);
    }
    
    /* Reposition top controls for mobile */
    .top-controls {
        display: flex;
        align-items: center;
        width: 100%;
        justify-content: flex-start;
    }
    
    /* Fix hamburger menu placement */
    #menu-toggle {
        order: 1;
        font-size: 24px;
        padding: 5px 10px;
        margin-right: 10px;
    }
    
    /* Range inputs with menu button */
    .range-inputs {
        order: 2;
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 5px;
        white-space: nowrap;
        width: calc(100% - 50px); /* Allow space for hamburger */
        justify-content: flex-start;
    }
    
    /* Center the navigation buttons */
    .navigation-buttons {
        justify-content: center;
        flex-wrap: wrap;
        gap: 5px;
        width: 100%;
        margin-top: 10px;
    }
    
    /* Make sure buttons are properly sized and visible */
    #previous-button, #start-button, #next-button {
        flex: 1;
        min-width: 80px;
        max-width: 33%;
        margin: 0 2px;
        padding: 8px 5px;
        font-size: 14px;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Fix dropdown positioning to be visible on screen */
    .dropdown-content {
        position: fixed;
        top: 120px; /* Position below the controls */
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.95);
        border-top: 1px solid #0f0;
        padding: 15px;
        width: 100%;
        z-index: 1000;
        display: none;
    }
    
    .dropdown-content.active {
        display: block;
    }
    
    /* Adjust the kanji display to account for controls */
    #kanji-display {
        position: fixed;
        top: 150px; /* Adjust based on your controls height */
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: calc(100% - 150px);
    }
    
    /* Adjust meaning container */
    .meaning-container {
        top: 180px; /* Position below controls */
    }
    
    /* Fix list sections */
    #history-section, #vocab-section, #mylist-section {
        height: 50%; /* Taller on mobile */
    }
    
    /* Remove any transformations */
    html, body {
        transform: none !important;
        position: relative !important;
        width: 100% !important;
        height: 100% !important;
    }
    
    /* Make touch targets bigger */
    button, input {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Make the hamburger menu always visible */
    #menu-toggle {
        display: block;
    }
    
    /* Fix button sizing */
    .dropdown-content button {
        width: 100%;
        margin: 5px 0;
        padding: 10px;
    }
    
    /* Make sure dropdown is hidden by default on mobile */
    .dropdown-content {
        display: none;
    }
    
    .dropdown-content.active {
        display: block;
    }
    
    /* Make range inputs wrap properly on mobile */
    .range-inputs {
        flex-wrap: wrap;
        justify-content: flex-start;
    }
    
    /* Reorganize the top controls for mobile */
    .menu-content {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .main-controls {
        width: 100%;
    }
    
    /* Make hamburger and range inputs on same row */
    .main-controls {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .top-controls {
        display: flex;
        width: 100%;
        align-items: center;
    }

    .desktop-only {
        display: none;
    }
    
    .mobile-only {
        display: inline;
    }
}

/* Desktop styles for larger screens */
@media (min-width: 769px) {
    .controls-container {
        flex-direction: row;
        justify-content: space-between;
        padding: 10px 20px;
        background: rgba(0, 0, 0, 0.8);
        top: 0;
        height: auto;
    }
    
    .menu-content {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        gap: 15px;
        position: relative; /* For absolute positioning of title */
    }
    
    /* Center the title on desktop */
    .title {
        display: block;
        color: #0f0;
        font-size: 2.2rem;
        font-weight: bold;
        text-align: center;
        position: absolute;
        left: 0;
        right: 0;
        margin: 0 auto;
        pointer-events: none;
        z-index: 5;
        text-shadow: 0 0 5px rgba(0, 255, 0, 0.7);
    }
    
    /* Create main control group */
    .main-controls {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 15px;
        width: 50%; /* Take up half the space on the left */
        z-index: 10;
    }
    
    /* Move navigation buttons into the same group as range inputs */
    .main-controls-group {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .range-inputs {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 5px;
        white-space: nowrap;
    }
    
    .navigation-buttons {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
    }
    
    /* Size and list controls on the right */
    .right-controls {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 15px;
        width: 50%; /* Take up half the space on the right */
        z-index: 10;
    }
    
    /* Style for list buttons */
    .list-buttons {
        display: flex;
        align-items: center;
        gap: 10px;
        z-index: 10;
    }
    
    .list-buttons button {
        background-color: rgba(0, 255, 0, 0.2);
        color: #0f0;
        border: 1px solid #0f0;
        border-radius: 4px;
        padding: 8px 12px;
        cursor: pointer;
        white-space: nowrap;
    }
    
    /* Size controls */
    .size-controls {
        display: flex;
        align-items: center;
        white-space: nowrap;
        gap: 5px;
        z-index: 10;
    }
    
    /* Hide hamburger menu on desktop */
    #menu-toggle {
        display: none;
    }
    
    /* Show dropdown content directly in header on desktop */
    .dropdown-content {
        display: flex !important;
        position: static;
        background: transparent;
        border: none;
        padding: 0;
        width: auto;
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }
    
    /* Adjust buttons for desktop */
    #previous-button, #start-button, #next-button {
        flex: none;
        min-width: auto;
        max-width: none;
        margin: 0;
        padding: 8px 15px;
        font-size: 0.9rem;
    }
    
    #start-button {
        background-color: #0f0;
        color: #000;
    }
    
    /* Reset kanji display position for desktop */
    #kanji-display {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
        width: 100%;
        height: calc(100vh - 70px);
        margin-top: 70px; /* Space for the header */
    }
    
    /* Adjust meaning container for desktop */
    .meaning-container {
        top: 120px;
    }
}