:root {
    --bg-color: #121213;
    --text-color: #ffffff;
    --border-color: #3a3a3c;
    --correct-color: #538d4e;
    --present-color: #b59f3b;
    --absent-color: #3a3a3c;
    --tile-bg-empty: transparent;
    --tile-bg-filled: #121213;
    --tile-border-empty: #3a3a3c;
    --tile-border-filled: #565758;
    --primary-color: #d4af37; /* Megido Gold */
    --primary-hover: #b8962e;
    --keyboard-bg: #818384;
}

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

.d-none {
    display: none !important;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    overflow-y: hidden;
}

#game-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    height: 60px;
    border-bottom: 1px solid var(--border-color);
}

header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 2px;
    margin: 0;
}

button {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    font-family: inherit;
}

#help-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background-color 0.2s;
}

#giveup-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 0 8px;
    background-color: #272729;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

#help-btn:hover, #giveup-btn:hover {
    background-color: #3a3a3c;
}

.btn-icon {
    font-size: 18px;
    line-height: 1;
}

.btn-label {
    font-size: 9px;
    color: #a1a1aa;
    white-space: nowrap;
}

#mode-btn {
    background-color: var(--primary-color);
    color: #000;
    padding: 6px 12px;
    border-radius: 16px;
    font-weight: bold;
    font-size: 13px;
    white-space: nowrap;
    transition: background-color 0.2s;
}

/* モードサブタイトル（タイトル直下） */
#mode-subtitle {
    text-align: center;
    font-size: 13px;
    font-weight: bold;
    color: var(--primary-color);
    letter-spacing: 1px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
}

#mode-btn:hover {
    background-color: var(--primary-hover);
}

main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 10px; /* 20pxから10pxへ */
    padding-bottom: 20px; /* 40pxから20pxへ */
    overflow-y: auto;
}

#hint-container {
    margin-bottom: 20px;
    text-align: center;
    font-size: 16px;
    color: #a1a1aa;
}

#word-length-hint {
    color: var(--primary-color);
    font-size: 20px;
}

#board-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    width: 100%;
    margin-bottom: 10px; /* 20pxから10pxへ */
}

#board {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px;
    box-sizing: border-box;
    width: 100%;
}

.tile-row {
    display: grid;
    grid-gap: 5px;
    width: 100%;
}

.tile-row:nth-child(6) {
    margin-top: 15px; /* 5行目と6行目の間に隙間を作る */
}

.tile {
    width: 100%;
    aspect-ratio: 1;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    font-weight: bold;
    border: 2px solid var(--tile-border-empty);
    background-color: var(--tile-bg-empty);
    text-transform: uppercase;
    user-select: none;
}

.tile::before {
    content: "\200b"; /* 空でも高さを確保するためのゼロ幅スペース */
}

.tile[data-state="tbd"] {
    background-color: var(--tile-bg-filled);
    border-color: var(--tile-border-filled);
    animation: popIn 0.1s;
}

.tile.correct {
    background-color: var(--correct-color);
    border-color: var(--correct-color);
    color: white;
}

.tile.present {
    background-color: var(--present-color);
    border-color: var(--present-color);
    color: white;
}

.tile.absent {
    background-color: var(--absent-color);
    border-color: var(--absent-color);
    color: white;
}

/* Animations */
@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    40% {
        transform: scale(1.1);
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.flip {
    animation: flip 0.38s ease-in forwards;
}

@keyframes flip {
    0% { transform: rotateX(0); }
    50% { transform: rotateX(90deg); }
    100% { transform: rotateX(0); }
}

.bounce {
    animation: bounce 0.4s;
}

@keyframes bounce {
    0%, 20% { transform: translateY(0); }
    40% { transform: translateY(-20px); }
    50% { transform: translateY(5px); }
    60% { transform: translateY(-10px); }
    80% { transform: translateY(2px); }
    100% { transform: translateY(0); }
}

.shake {
    animation: shake 0.45s;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

#bottom-controls {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 10px;
    background-color: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    z-index: 10;
}

#input-container {
    display: flex;
    width: 100%;
    max-width: 400px;
    gap: 6px;
    margin-bottom: 0;
    flex-wrap: nowrap; /* 改行を防ぐ */
    align-items: stretch;
}

#guess-input {
    flex-grow: 1;
    min-width: 0; /* flexで收縮できるように */
    padding: 10px 10px;
    font-size: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background-color: #272729;
    color: white;
    outline: none;
    transition: border-color 0.2s;
}

#guess-input:focus {
    border-color: var(--primary-color);
}

#submit-btn {
    background-color: var(--primary-color);
    color: #000;
    padding: 0 14px;
    font-size: 14px;
    font-weight: bold;
    border-radius: 8px;
    white-space: nowrap;
    flex-shrink: 0;
    transition: transform 0.1s, background-color 0.2s;
}

#submit-btn:active {
    transform: scale(0.95);
}

/* メギド一覧ボタン（あてるボタン横） */
#list-btn {
    background-color: #272729;
    color: var(--primary-color);
    border: 1px solid var(--border-color);
    padding: 0 12px;
    font-size: 18px;
    border-radius: 8px;
    transition: background-color 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

#list-btn:hover {
    background-color: #3a3a3c;
}

#play-again-container {
    display: flex;
    width: 100%;
    max-width: 400px;
    margin-bottom: 0;
}

#play-again-btn {
    background-color: var(--primary-color);
    color: #000;
    width: 100%;
    padding: 15px;
    font-size: 18px;
    font-weight: bold;
    border-radius: 8px;
    transition: transform 0.1s, background-color 0.2s;
}

#play-again-btn:active {
    transform: scale(0.95);
}

#megido-list-container {
    text-align: left;
    margin-top: 10px;
    padding: 10px;
    background: #1e1e1e;
    border-radius: 5px;
}

.megido-list-item {
    padding: 5px 0;
    border-bottom: 1px solid #333;
    display: flex;
    font-size: 16px;
}

.megido-id {
    color: var(--primary-color);
    width: 60px;
    font-weight: bold;
}

.megido-name {
    flex-grow: 1;
}

#message-container {
    position: fixed;
    bottom: 90px; /* 入力バーの直上に表示 */
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.message {
    background-color: var(--text-color);
    color: var(--bg-color);
    padding: 12px 20px;
    border-radius: 4px;
    font-weight: bold;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.message.fade-out {
    opacity: 0;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 30px;
    max-width: 90%;
    width: 400px;
    max-height: 85vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding-bottom: 60px;
}

.modal.hidden .modal-content {
    transform: translateY(20px);
}

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

.modal-header h2 {
    margin: 0;
    font-size: 24px;
    flex-grow: 1;
    text-align: center;
}

.modal-close-btn {
    background: none;
    border: none;
    color: #a1a1aa;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    flex-shrink: 0;
}

.modal-close-btn:hover {
    color: var(--text-color);
}

.modal h2 {
    margin-bottom: 20px;
    font-size: 24px;
}

#result-target-word {
    font-size: 28px;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 20px;
    letter-spacing: 2px;
}

#share-btn, #next-btn, #close-modal-btn, #close-help-btn, .modal-close-bottom-btn {
    display: block;
    width: 100%;
    padding: 14px;
    margin-top: 10px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
}

#share-btn {
    background-color: #1DA1F2;
    color: white;
}

#share-btn:hover {
    background-color: #1a8cd8;
}

#next-btn {
    background-color: var(--primary-color);
    color: black;
}

#close-modal-btn, #close-help-btn, .modal-close-bottom-btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    margin-top: 20px;
    color: var(--text-color);
}

.help-examples {
    text-align: left;
    margin: 20px 0;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.help-example {
    margin-bottom: 15px;
}

.help-example .tile-row {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
}

.help-example .tile {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
}

.tile.disabled-tile {
    background-color: #1a1a1c;
    border-color: #2a2a2c;
    color: #4a4a4c;
    opacity: 0.5;
}

/* フリーモード チェイン・ストリーク表示 */
#streak-info {
    margin: 12px 0;
    padding: 14px;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 1px solid var(--primary-color);
    border-radius: 10px;
    text-align: center;
}

.chain-number {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--primary-color);
    line-height: 1;
    text-shadow: 0 0 20px rgba(212, 175, 55, 0.5);
}

.chain-label {
    font-size: 1rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.streak-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 8px;
    font-size: 12px;
    color: #a1a1aa;
}

.streak-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.streak-stat-value {
    font-size: 18px;
    font-weight: bold;
    color: #fff;
}

/* スマホ向けのレスポンシブ調整 */
@media (max-width: 500px) {
    .tile {
        font-size: 1.3rem; /* 画面が狭い時はフォントを小さくして枠に収める */
    }
}

@media (max-width: 380px) {
    .tile {
        font-size: 1.1rem; /* さらに狭い時 */
    }
    header h1 {
        font-size: 18px; /* ヘッダータイトルを縮小してボタンとの衝突を回避 */
    }
    #mode-btn {
        font-size: 10px;
        padding: 3px 6px;
    }
}
