/* 틱택토 */

.tictactoe-container {
    max-width: 580px;
    margin: 0 auto;
    padding: 40px 16px 80px;
    padding-bottom: calc(50px + 20px);
    font-family: 'Pretendard', sans-serif;
    min-height: 100vh;
}

.ttt-header {
    text-align: center;
    margin-bottom: 24px;
}

.ttt-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #333;
    margin: 0 0 8px 0;
}

.ttt-subtitle {
    font-size: 0.9rem;
    color: #666;
    margin: 0;
}

/* 게임 방법 */
.ttt-howto {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 20px;
    border: 1px solid #e9ecef;
}

.ttt-howto-title {
    font-size: 1rem;
    font-weight: 700;
    color: #333;
    margin: 0 0 10px 0;
}

.ttt-howto-list {
    margin: 0;
    padding-left: 1.2rem;
    font-size: 0.9rem;
    line-height: 1.65;
    color: #444;
}

.ttt-howto-list li {
    margin-bottom: 6px;
}

.ttt-howto-list li:last-child {
    margin-bottom: 0;
}

/* 컨트롤 */
.ttt-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.ttt-difficulty {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ttt-control-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #555;
}

.ttt-difficulty-buttons {
    display: flex;
    gap: 6px;
}

.ttt-diff-btn {
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    color: #555;
    background: #f0f0f0;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    white-space: nowrap;
}

.ttt-diff-btn:hover {
    background: #e5e5e5;
    color: #333;
}

.ttt-diff-btn.active {
    background: #2c3e50;
    color: #fff;
    border-color: #2c3e50;
}

.ttt-new-btn {
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.ttt-new-btn:hover {
    background: linear-gradient(135deg, #2980b9 0%, #1f6dad 100%);
}

/* 상태 바 */
.ttt-status-bar {
    text-align: center;
    margin-bottom: 16px;
}

.ttt-turn {
    display: inline-block;
    padding: 10px 28px;
    background: #2c3e50;
    border-radius: 10px;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
}

/* 보드 래퍼 */
.ttt-board-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    position: relative;
}

/* 동적 그리드 -- JS가 CSS 변수를 설정 */
.ttt-board {
    display: grid;
    grid-template-columns: repeat(var(--ttt-cols, 3), var(--ttt-cell, 96px));
    grid-template-rows: repeat(var(--ttt-cols, 3), var(--ttt-cell, 96px));
    gap: var(--ttt-gap, 6px);
    background: #2c3e50;
    border-radius: 12px;
    padding: var(--ttt-gap, 6px);
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

/* 셀 */
.ttt-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f6fa;
    border: none;
    border-radius: 8px;
    font-size: var(--ttt-mark, 2.8rem);
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
    font-family: inherit;
    line-height: 1;
    width: var(--ttt-cell, 96px);
    height: var(--ttt-cell, 96px);
    overflow: hidden;
    box-sizing: border-box;
}

.ttt-cell:hover:not(.ttt-cell--taken):not(.ttt-cell--disabled) {
    background: #e8eaf0;
    transform: scale(1.03);
}

.ttt-cell:active:not(.ttt-cell--taken):not(.ttt-cell--disabled) {
    transform: scale(0.97);
}

.ttt-cell--taken {
    cursor: default;
}

.ttt-cell--disabled {
    cursor: default;
    opacity: 0.85;
}

/* O 마크 */
.ttt-cell--O {
    color: #3498db;
}

/* X 마크 */
.ttt-cell--X {
    color: #e74c3c;
}

/* 승리 셀 하이라이트 */
.ttt-cell--win {
    background: #ffeaa7 !important;
    animation: tttWinPulse 0.6s ease-in-out 2;
}

@keyframes tttWinPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* 승리 라인 SVG */
.ttt-win-line {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 2;
}

.ttt-win-line line {
    stroke: #e74c3c;
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    animation: tttLineDraw 0.5s ease forwards;
}

.ttt-win-line line.win-player {
    stroke: #3498db;
}

@keyframes tttLineDraw {
    to { stroke-dashoffset: 0; }
}

/* 메시지 */
.ttt-message {
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    margin: 0 0 8px 0;
    min-height: 1.5em;
    color: #333;
}

.ttt-message:empty {
    visibility: hidden;
}

.ttt-message--win { color: #27ae60; }
.ttt-message--lose { color: #e74c3c; }
.ttt-message--draw { color: #f39c12; }

/* 전적 기록 */
.ttt-record {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.ttt-record-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.ttt-record-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #333;
    margin: 0;
}

.ttt-record-clear-btn {
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    color: #666;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
}

.ttt-record-clear-btn:hover {
    background: #e5e5e5;
    color: #333;
}

/* 승/무/패 요약 */
.ttt-stats {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.ttt-stat {
    flex: 1;
    text-align: center;
    padding: 12px 8px;
    border-radius: 10px;
    background: #f5f5f5;
}

.ttt-stat-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    margin-bottom: 4px;
}

.ttt-stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.ttt-stat--win .ttt-stat-value { color: #27ae60; }
.ttt-stat--draw .ttt-stat-value { color: #f39c12; }
.ttt-stat--lose .ttt-stat-value { color: #e74c3c; }

.ttt-record-empty {
    font-size: 0.9rem;
    color: #888;
    margin: 0 0 12px 0;
}

.ttt-record-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ttt-record-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #f5f5f5;
    border-radius: 10px;
    font-size: 0.9rem;
}

.ttt-record-item .record-result {
    font-weight: 700;
    min-width: 52px;
}

.ttt-record-item .record-result--win { color: #27ae60; }
.ttt-record-item .record-result--draw { color: #f39c12; }
.ttt-record-item .record-result--lose { color: #e74c3c; }

.ttt-record-item .record-level {
    font-weight: 600;
    color: #2c3e50;
}

.ttt-record-item .record-date {
    margin-left: auto;
    font-size: 0.8rem;
    color: #888;
}

/* 반응형 */
@media (max-width: 420px) {
    .ttt-controls {
        flex-direction: column;
        align-items: stretch;
    }
    .ttt-difficulty {
        justify-content: center;
    }
    .ttt-diff-btn {
        flex: 1;
        font-size: 0.8rem;
        padding: 8px 6px;
    }
    .ttt-new-btn {
        text-align: center;
    }
}
