:root {
    --cell-size: 50px; /* JS에서 동적으로 계산됨 */
    --base-color: black;
    --text-color: white;
    --accent-color: rgb(150, 0, 0);
    --line-color: #ccc;
    --cell-color: #aaa;
}

html, body {
    height: 100%;
}

body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

@media screen and (min-width: 600px) {
    body {
        display: block;
        height: auto;
        overflow: auto;
    }
}

.game-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    transition: opacity 2s ease;
}

@media screen and (min-width: 600px) {
    .game-content {
        display: block;
        height: 100%;
    }
}

.columns {
    padding: 0;
    font-weight: 900;
    flex: 1;
    min-height: 0;
}

@media screen and (min-width: 600px) {
    .columns {
        height: 100%;
    }
}

.column {
    min-height: 100dvh;
    overflow-y: auto;
}

@media screen and (max-width: 599px) {
    .column {
        display: flex;
        flex-direction: column;
        min-height: 0;
        flex: 1;
    }
}

.is-hidden-mobile {
    display: none;
}

@media screen and (min-width: 600px) {
    .is-hidden-mobile {
        display: block;
    }
}

.crossword-container {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    background-color: var(--base-color);
}

@media screen and (min-width: 600px) {
    .crossword-container {
        height: 100%;
    }
}

.mobile-clue-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    background-color: var(--accent-color);
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 700;
    padding: 0.5rem 1rem;
    text-align: center;
}

@media screen and (min-width: 600px) {
    .crossword-container {
        height: 100%;
        flex: none;
    }
    
    .mobile-clue-container {
        display: none;
    }
}

.crossword {
    display: grid;
    gap: 1px;
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(13, var(--cell-size));
    width: fit-content;
}

/* 플립 애니메이션 컨테이너 */
.flip-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.flip-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
}

.flip-layer-1 {
    animation: flip-opacity 2s infinite step-end;
}

.flip-layer-2 {
    animation: flip-opacity 2s infinite step-end reverse;
}

@keyframes flip-opacity {
    0%, 50% {
        opacity: 1;
    }
    50.01%, 100% {
        opacity: 0;
    }
}

/* 레이어 1: 검정 배경 + 빨강 글자칸 */
.cleared-container, .cleared-container-2 {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
}

.cleared-container {
    background-color: var(--base-color);
}

.cleared-container-2 {
    display: none;
    background-color: var(--accent-color);
}

@media screen and (min-width: 600px) {
    .cleared-container-2 {
        display: flex;
    }
}

.cleared .crossword-cell {
    background-color: var(--base-color);
}

.cleared .answer-cell {
    background-color: var(--accent-color);
}

.cleared-2 .crossword-cell {
    background-color: var(--accent-color);
}

.cleared-2 .answer-cell {
    background-color: var(--base-color);
}

/* 레이어 2: 반전 색상 */
.cleared-container-alt, .cleared-container-2-alt {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
}

.cleared-container-alt {
    background-color: var(--accent-color);
}

.cleared-container-2-alt {
    display: none;
    background-color: var(--base-color);
}

@media screen and (min-width: 600px) {
    .cleared-container-2-alt {
        display: flex;
    }
}

.cleared-container-alt .crossword-cell {
    background-color: var(--accent-color);
}

.cleared-container-alt .answer-cell {
    background-color: var(--base-color);
}

.cleared-container-2-alt .crossword-cell {
    background-color: var(--base-color);
}

.cleared-container-2-alt .answer-cell {
    background-color: var(--accent-color);
}

.cleared, .cleared-2 {
    display: grid;
    grid-template-columns: repeat(8, var(--cell-size));
    grid-template-rows: repeat(13, var(--cell-size));
    width: fit-content;
}

.crossword-cell {
    background-color: var(--base-color);
    position: relative;
}

.answer-cell {
    position: relative;
    background-color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.answer-number {
    width: fit-content;
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: clamp(0.62rem, 1.5vw, 1.125rem);
}

.answer-input {
    background-color: transparent;
    color: var(--base-color);
    outline: none;
    border: none;
    width: 100%;
    height: 100%;
    font-size: clamp(1.125rem, 3vw, 2rem);
    text-align: center;
    caret-color: transparent;
    cursor: pointer;
    padding-top: 4px;
    line-height: 1;
    font-weight: 900;
}


/* 같은 라인에 속한 cell 하이라이트 */
.answer-cell.highlight-line {
    background-color: var(--line-color);
    opacity: 1;
}

/* 현재 선택된 cell 하이라이트 */
.answer-cell.highlight-current {
    background-color: var(--cell-color);
    opacity: 0.6;
}

.clues-container {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    background-color: var(--accent-color);
    height: 100%;
    gap: 3rem;
    font-weight: 900;
    line-height: 1.7;
    font-size: 1rem;
}

.horizontal-clues-title, .vertical-clues-title {
    margin-bottom: 0.25rem;
}

@media screen and (min-width: 600px) {
    .clues-container {
        font-size: 1.25rem;
    }
}

.clue-item {
    cursor: pointer;
}

.clue-item.highlight-clue {
    color: var(--text-color);
}

/* 채점 버튼 */
.grade-button {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background-color: transparent;
    color: var(--text-color);
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    z-index: 1000;
    display: none;
}

@media screen and (min-width: 600px) {
    .grade-button {
        display: block;
        color: var(--base-color);
    }
}

.grade-button:hover {
    opacity: 0.5;
}

.answer-input.correct {
    background-color: var(--text-color);
    color: black;
    cursor: default;
}

.answer-input.incorrect {
    background-color: var(--text-color);
    color: red;
}

/* 클리어 화면 */
.clear-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--accent-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 2s ease, visibility 2s ease;
}

.clear-screen.show {
    opacity: 1;
    visibility: visible;
}

.game-content.fade-out {
    opacity: 0;
}

/* 가상 키보드 */
.virtual-keyboard {
    display: flex;
    flex-direction: column;
    background-color: #1a1a1a;
    padding: 8px 4px;
    gap: 6px;
}

@media screen and (min-width: 600px) {
    .virtual-keyboard {
        display: none;
    }
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.key {
    min-width: 32px;
    height: 42px;
    border: none;
    border-radius: 6px;
    background-color: #3a3a3a;
    color: var(--text-color);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    max-width: 50px;
    transition: background-color 0.1s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.key:active {
    background-color: #555;
}

.key-shift {
    background-color: #555;
    flex: 1.2;
    max-width: 60px;
}

.key-shift.active {
    background-color: var(--accent-color);
}

.key-backspace {
    background-color: #555;
    flex: 1.2;
    max-width: 60px;
}

.key-grade {
    background-color: var(--accent-color);
    flex: 1;
    max-width: none;
    font-size: 1.1rem;
}

.key-grade:active {
    background-color: rgb(180, 0, 0);
}