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

:root {
    --bg: #ffffff;
    --text: #1a1a1b;
    --text-muted: #787c7e;
    --border: #d3d6da;
    --tile-border-filled: #878a8c;
    --key-bg: #e2e5e9;
    --key-text: #1a1a1b;
    --correct: #6aaa64;
    --present: #c9b458;
    --absent: #787c7e;
    --modal-bg: #ffffff;
    --overlay: rgba(0, 0, 0, 0.5);
    --toast-bg: #1a1a1b;
    --toast-text: #ffffff;
}

[data-theme="dark"] {
    --bg: #121213;
    --text: #f8f8f8;
    --text-muted: #818384;
    --border: #3a3a3c;
    --tile-border-filled: #565758;
    --key-bg: #818384;
    --key-text: #f8f8f8;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --modal-bg: #1e1e1f;
    --overlay: rgba(0, 0, 0, 0.6);
    --toast-bg: #f8f8f8;
    --toast-text: #121213;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.2s, color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

/* ===== 헤더 ===== */
.header {
    width: 100%;
    max-width: 500px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.title {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.15em;
}

.header-right { display: flex; gap: 4px; }

.icon-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover { background: var(--key-bg); }

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }

/* ===== 게임 영역 ===== */
.game {
    width: 100%;
    max-width: 500px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 12px 8px calc(12px + env(safe-area-inset-bottom));
}

/* ===== 보드 ===== */
.board {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 5px;
    padding: 6px 0;
}

.board-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
}

.tile {
    width: min(52px, 13vw);
    height: min(52px, 13vw);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    user-select: none;
    transition: background 0.3s, border-color 0.3s, color 0.3s;
    border-radius: 4px;
}

.tile.filled {
    border-color: var(--tile-border-filled);
    animation: pop 0.1s ease;
}

.tile.correct, .tile.present, .tile.absent {
    border-color: transparent;
    color: #fff;
}

.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent  { background: var(--absent); }

@keyframes pop {
    50% { transform: scale(1.1); }
}

.board-row.shake {
    animation: shake 0.4s ease;
}

@keyframes shake {
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* ===== 토스트 ===== */
.toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    z-index: 50;
    white-space: nowrap;
}

.toast.show { opacity: 1; }

/* ===== 키보드 ===== */
.keyboard {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 5px;
}

.key {
    flex: 1;
    max-width: 44px;
    height: 52px;
    border: none;
    border-radius: 5px;
    background: var(--key-bg);
    color: var(--key-text);
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.key.wide { max-width: 60px; font-size: 0.85rem; }

.key.enter-key {
    max-width: none;
    height: 46px;
    font-size: 1rem;
}

.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent  { background: var(--absent); color: #fff; opacity: 0.7; }

.key.shift-on { background: var(--text); color: var(--bg); }

/* ===== 모달 ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--modal-bg);
    border-radius: 14px;
    padding: 28px 24px 24px;
    max-width: 380px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal h2 {
    font-size: 1.15rem;
    margin-bottom: 12px;
}

.modal p, .modal li {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 6px;
}

.modal ul { padding-left: 18px; margin-bottom: 12px; }

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
}

.example { margin: 14px 0; }

.ex-row { display: flex; gap: 4px; margin: 10px 0 4px; }

.tile.small {
    width: 34px;
    height: 34px;
    font-size: 1rem;
}

.green { color: var(--correct); }
.yellow { color: var(--present); }
.muted { color: var(--text-muted); font-size: 0.8rem; }

.answer-reveal {
    font-size: 1rem;
    text-align: center;
    padding: 8px;
    border-radius: 8px;
    background: var(--key-bg);
    margin-bottom: 14px;
}

.answer-reveal strong { font-size: 1.15rem; letter-spacing: 0.1em; }

/* ===== 통계 ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 16px 0;
    text-align: center;
}

.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-label { font-size: 0.7rem; color: var(--text-muted); }

.countdown-wrap {
    text-align: center;
    margin: 16px 0;
}

.countdown {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.share-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: var(--correct);
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.share-btn:active { transform: scale(0.98); }

/* ===== 오늘의 랭킹 ===== */
.rank-section {
    margin: 16px 0 4px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.rank-title {
    font-size: 0.85rem;
    margin: 0 0 8px;
    text-align: center;
}

.rank-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
}

.rank-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 8px;
    font-size: 0.85rem;
}

.rank-item.rank-me {
    background: color-mix(in srgb, var(--correct) 15%, transparent);
    font-weight: 700;
}

.rank-no {
    width: 26px;
    text-align: center;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.rank-nick {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-score {
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.rank-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 10px 0;
    list-style: none;
}
