:root {
    --bg-primary: #e0f7fa;
    --green-neon: #00acc1;
    --green-dark: #00838f;
    --text-primary: #37474f;
    --text-secondary: #546e7a;
    /* モバイル最適化サイズ (375pxベースで固定) — さらに95%に縮小 */
    --clue-size: 20px;
    --cell-size: 32px;
    --font-title: 'Orbitron', sans-serif;
    --font-body: 'Noto Sans JP', sans-serif;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 100%;
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

#game-safe-area.mobile-viewport,
#game-safe-area {
    position: absolute !important;
    top: 0 !important;
    left: 50% !important;
    width: 375px !important;
    height: var(--viewport-height, 667px) !important;
    transform: translate(-50%, 0) scale(var(--scale-factor, 1)) !important;
    transform-origin: top center !important;
    overflow: hidden !important;
    background: var(--bg-primary) !important;
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.15) !important;
}

/* モバイル版における広告バナーの最適化（スケーリングコンテナ内最上部） */
.ad-banner {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 50px !important;
    z-index: 1000 !important;
    background: #ffffff !important;
    border-bottom: 1px solid #eee !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.7rem !important;
    color: #999 !important;
}

/* ① ゲームヘッダー */
.game-header {
    height: 42px !important; /* 57pxから42pxに縮小 */
    padding: 0 8px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(0, 188, 212, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}


.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-btn {
    background: white;
    border: 1px solid var(--green-neon);
    color: var(--green-dark);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.game-meta-info {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-family: var(--font-title);
}

/* 難易度テキスト */
#game-difficulty {
    font-size: 0.75rem;
    font-weight: bold;
    letter-spacing: 0.5px;
}

#game-difficulty.diff-easy {
    color: #4caf50 !important;
}

#game-difficulty.diff-normal {
    color: #ff9800 !important;
}

#game-difficulty.diff-hard {
    color: #f44336 !important;
}

/* ステージ情報 */
#game-stage {
    font-size: 0.7rem;
    font-weight: bold;
    color: var(--green-dark);
    opacity: 0.85;
    letter-spacing: 0.5px;
}

/* カスタムアイコンボタン */
.icon-btn-custom {
    background-color: white;
    background-size: 80% !important; /* アイコン画像がはみ出さないようにサイズ調整 */
    background-position: center;
    background-repeat: no-repeat;
    border: 1px solid var(--green-neon);
    border-radius: 6px !important; /* ボタンの角丸もテンキーと合わせる */
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 188, 212, 0.15);
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box !important;
}

/* ヘッダー内のカスタムアイコンボタンは固定サイズ */
.game-header .icon-btn-custom {
    width: 33px !important; /* テンキーボタン幅に近いサイズに縮小 */
    height: 32px !important; /* テンキーボタンと同じ高さ */
}

.icon-btn-custom.guide {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect x='10' y='6' width='20' height='28' rx='3' fill='none' stroke='%2300838f' stroke-width='2.5'/%3E%3Cpath d='M15 14h10 M15 20h10 M15 26h6' stroke='%2300acc1' stroke-width='2' stroke-linecap='round'/%3E%3Ccircle cx='28' cy='28' r='7' fill='white' stroke='%2300838f' stroke-width='1.5'/%3E%3Cpath d='M26 26.5 a2 2 0 1 1 3 1.5 v1.5 m0 2.5 v0.1' fill='none' stroke='%2300838f' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

.icon-btn-custom.save {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M10 29 a6 6 0 0 1 0 -12 a8 8 0 0 1 15 -4 a6 6 0 0 1 5 16 Z' fill='none' stroke='%2300838f' stroke-width='2.5' stroke-linejoin='round'/%3E%3Cpath d='M20 38 v-16 M16 26 l4 -4 l4 4' fill='none' stroke='%2300acc1' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    position: relative;
}

.icon-btn-custom.save.success::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M10 20 l7 7 l13 -13' fill='none' stroke='%234caf50' stroke-width='5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
    z-index: 10;
    animation: save-pop-adjusted 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.icon-btn-custom.save.error::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M12 12 l16 16 M28 12 l-16 16' fill='none' stroke='%23f44336' stroke-width='5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-size: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
    z-index: 10;
    animation: save-pop-adjusted 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes save-pop-adjusted {
    0% { transform: translateY(-50%) scale(0); opacity: 0; }
    100% { transform: translateY(-50%) scale(1); opacity: 1; }
}

.icon-btn-custom.save.loading {
    opacity: 0.8;
    cursor: wait;
}

.icon-btn-custom.save.guest-disabled {
    opacity: 0.5;
    filter: grayscale(1);
    cursor: not-allowed;
}

.icon-btn-custom.save.guest-disabled:active {
    transform: none;
    background-color: white;
}

.icon-btn-custom.hint {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Cpath d='M20 3 v4 M11 5 l3 3 M29 5 l-3 3' stroke='%2300acc1' stroke-width='1.2' stroke-linecap='round'/%3E%3Cpath d='M14 23 A8 8 0 1 1 26 23 L24 30 H16 L14 23' fill='none' stroke='%2300838f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M16 34 h8' stroke='%2300838f' stroke-width='2.5' stroke-linecap='round'/%3E%3C/svg%3E");
}

.icon-btn-custom.assist {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect x='6' y='6' width='28' height='28' rx='2' fill='none' stroke='%2300838f' stroke-width='2.5'/%3E%3Cline x1='15.3' y1='6' x2='15.3' y2='34' stroke='%2300838f' stroke-width='1.8'/%3E%3Cline x1='24.6' y1='6' x2='24.6' y2='34' stroke='%2300838f' stroke-width='1.8'/%3E%3Cline x1='6' y1='15.3' x2='34' y2='15.3' stroke='%2300838f' stroke-width='1.8'/%3E%3Cline x1='6' y1='24.6' x2='34' y2='24.6' stroke='%2300838f' stroke-width='1.8'/%3E%3Cg stroke='%2300acc1' stroke-width='1.2' stroke-dasharray='1,1' stroke-linecap='round' opacity='0.7'%3E%3Cline x1='4' y1='20' x2='36' y2='20'/%3E%3Cline x1='20' y1='4' x2='20' y2='36'/%3E%3Cline x1='8' y1='8' x2='32' y2='32'/%3E%3Cline x1='32' y1='8' x2='8' y2='32'/%3E%3C/g%3E%3C/svg%3E");
}

.icon-btn-custom:active {
    transform: scale(0.95);
    background-color: #f0fdff;
}

.timer-display {
    font-family: var(--font-title);
    font-size: 0.9rem;
    font-weight: 900;
    color: var(--green-dark);
    letter-spacing: 0.5px;
    min-width: 45px;
    text-align: right;
    text-shadow: 0 0 4px rgba(0, 131, 143, 0.15);
}

/* ② ゲームレイアウト */
#game-screen {
    padding-top: 50px !important;
    justify-content: flex-start !important;
}

.game-layout {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start !important;
    padding: 5px;
    overflow-y: auto;
    margin-bottom: var(--numpad-margin, 74px) !important; /* トグル状態に連動する動的マージン */
}

.board-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0px;
}

.clues {
    display: flex;
    gap: 1px;
}

.clue-cell {
    width: var(--cell-size);
    height: var(--clue-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: bold;
    color: var(--green-dark);
}

.clue-cell.match {
    color: #39ff14 !important;
    text-shadow: 0 0 8px rgba(57, 255, 20, 0.6) !important;
}

.clue-cell.over {
    color: #ff5252 !important;
    text-shadow: 0 0 8px rgba(255, 82, 82, 0.6) !important;
}

.clues-left,
.clues-right {
    flex-direction: column;
}

.clues-left .clue-cell,
.clues-right .clue-cell {
    width: var(--clue-size);
    height: var(--cell-size);
}

.board-middle {
    display: flex;
    gap: 1px;
}

.grid {
    display: grid;
    gap: 1px;
    background: #b0bec5;
    border: 2px solid var(--green-dark);
    position: relative;
    touch-action: none;
}

.cell {
    background: white;
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    font-weight: bold;
    position: relative;
    user-select: none;
}

/* ③ ナンバーパネル (スケーリングコンテナ内最下部) */
.number-panel {
    background: rgba(245, 247, 249, 0.95);
    backdrop-filter: blur(10px);
    padding: 6px 6px !important;
    border-top: 1px solid var(--green-neon);
    display: flex;
    flex-direction: column;
    gap: 3px !important;
    z-index: 9999 !important;
    width: 100% !important;
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.1);
    box-sizing: border-box !important;
}

.input-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    position: relative; /* トグルボタン絶対配置の基準点 */
    min-height: 28px; /* 最小化時にも高さを維持 */
    width: 100%;
}

.control-btn {
    background: white;
    border: 1px solid #cfd8dc;
    padding: 4px 12px !important;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 900;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.control-btn.active {
    border-color: var(--green-neon);
    color: var(--green-neon);
}

.numpad {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 3px !important;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box !important;
}

.num-btn {
    width: auto !important; /* PC用の44px固定幅をクリア */
    height: 32px !important; /* 縦幅を少し狭めてコンパクト化 */
    background: white;
    border: 1px solid #cfd8dc;
    padding: 0 !important; /* 横幅はグリッドの1fr分配に任せる */
    border-radius: 6px;
    font-size: 0.85rem !important;
    font-weight: 900;
    color: var(--text-primary);
    font-family: var(--font-body), sans-serif !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box !important;
}

/* PC閲覧用のガイド */
@media (min-width: 600px) {
    body {
        max-width: 430px;
        margin: 0 auto;
        border: 1px solid #ddd;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.1);
    }
}

/* アシストメニューのモバイル用ポップアップ表示 */
.assist-dropdown {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -55%) !important;
    z-index: 10000 !important;
    width: 90% !important;
    max-width: 320px !important;
    margin: 0 !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.assist-dropdown.active {
    transform: translate(-50%, -50%) !important;
}

.assist-dropdown-content {
    width: 100% !important;
    border-color: var(--blue-neon) !important;
}

/* --- Mobile Specific Number Highlight --- */
.cell.highlight-match {
    background: rgba(255, 235, 59, 0.3) !important;
    box-shadow: inset 0 0 10px rgba(255, 235, 59, 0.45);
    border-color: rgba(255, 235, 59, 0.65) !important;
}

.cell.placed.highlight-match {
    background: rgba(255, 215, 0, 0.2) !important;
    box-shadow: inset 0 0 0 4px rgba(255, 215, 0, 0.85) !important;
    border-color: rgba(255, 215, 0, 0.9) !important;
}

.cell.placed.highlight-match .val-container {
    color: #ffd700 !important;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.8), 0 0 10px rgba(255, 215, 0, 0.5), 0 0 4px rgba(0,0,0,0.9) !important;
}

.cell.highlight-match-memo {
    background: rgba(255, 235, 59, 0.16) !important;
    box-shadow: inset 0 0 5px rgba(255, 235, 59, 0.25);
}

/* --- Mobile Numpad Toggle / Minimization --- */
.control-btn.toggle-btn {
    position: absolute !important;
    left: 6px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10 !important;
    width: 28px !important;
    padding: 2px 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.number-panel.minimized {
    padding: 4px 6px !important;
}

.number-panel.minimized .numpad {
    display: none !important;
}

.number-panel.minimized .control-btn:not(.toggle-btn):not(.menu-btn) {
    display: none !important;
}

/* 盤面に表示されるメモの数字を70%に縮小 */
.memo-cell {
    font-size: 0.52rem !important;
}

/* --- Sidebar & Menu Layout --- */
.game-sidebar {
    position: absolute !important;
    top: 50px !important; /* 広告枠（50px）の直下から開始 */
    left: -250px !important;
    width: 250px !important;
    height: calc(100% - 50px) !important;
    background: rgba(224, 247, 250, 0.98) !important;
    backdrop-filter: blur(10px) !important;
    border-right: 2px solid var(--green-neon) !important;
    z-index: 9500 !important;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.1) !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 20px 15px !important;
    box-sizing: border-box !important;
    gap: 15px !important;
}

.game-sidebar.active {
    left: 0 !important;
}

.sidebar-title {
    font-family: var(--font-title);
    font-size: 1.1rem;
    color: var(--green-dark);
    border-bottom: 2px solid var(--green-neon);
    padding-bottom: 8px;
    margin-bottom: 10px;
    font-weight: 900;
    letter-spacing: 1px;
}

.sidebar-btn-container {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
}

.game-sidebar .sidebar-btn-container .icon-btn-custom,
.game-sidebar .sidebar-btn-container .nav-btn {
    width: 100% !important;
    height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding-left: 45px !important;
    box-sizing: border-box !important;
    font-size: 0.85rem !important;
    font-weight: bold !important;
    border-radius: 8px !important;
    position: relative !important;
    background-color: white !important;
    border: 1px solid var(--green-neon) !important;
    box-shadow: 0 2px 8px rgba(0, 188, 212, 0.15) !important;
    color: var(--green-dark) !important;
}

.game-sidebar .sidebar-btn-container .icon-btn-custom {
    background-position: 12px center !important;
    background-size: 24px !important;
}

.sidebar-btn-container .nav-btn::before {
    content: '←';
    position: absolute;
    left: 16px;
    font-size: 1.1rem;
    color: var(--green-dark);
}



.sidebar-overlay {
    position: absolute !important;
    top: 50px !important; /* 広告枠（50px）の直下から開始 */
    left: 0 !important;
    width: 100% !important;
    height: calc(100% - 50px) !important;
    background: rgba(0, 0, 0, 0.3) !important;
    z-index: 9000 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.control-btn.menu-btn {
    position: absolute !important;
    right: 6px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10 !important;
    padding: 2px 8px !important;
    font-size: 0.7rem !important;
    font-weight: 900 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--green-neon) !important;
    color: white !important;
    border: 1px solid var(--green-dark) !important;
    border-radius: 6px !important;
}

/* --- Sidebar Hint Log Integration --- */
.sidebar-hint-log-section {
    margin-top: 15px !important;
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important; /* 残りのスペース全体を占める */
    min-height: 120px !important;
    border-top: 1px dashed var(--green-neon) !important;
    padding-top: 15px !important;
    overflow: hidden !important;
}

.sidebar-hint-log-header {
    font-family: var(--font-title);
    font-size: 0.9rem;
    color: var(--green-dark);
    font-weight: 900;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.sidebar-hint-log-body {
    flex: 1 !important;
    overflow: hidden !important;
    background: rgba(255, 255, 255, 0.5) !important;
    border-radius: 8px !important;
    border: 1px solid rgba(0, 188, 212, 0.2) !important;
    display: flex !important;
    flex-direction: column !important;
}

.sidebar-hint-log-body .hint-log-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow-y: auto !important;
    flex: 1 !important;
    height: 100% !important;
    -webkit-overflow-scrolling: touch;
}

/* モバイルのシアンテーマに合わせたヒントログアイテムの調整 */
.sidebar-hint-log-body .hint-log-item {
    padding: 8px 10px !important;
    border-bottom: 1px solid rgba(0, 188, 212, 0.1) !important;
    cursor: pointer !important;
    transition: background 0.15s !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 4px !important;
    align-items: flex-start !important;
}

.sidebar-hint-log-body .hint-log-item:hover {
    background: rgba(0, 172, 193, 0.05) !important;
}

.sidebar-hint-log-body .hint-log-item.active {
    background: rgba(0, 172, 193, 0.1) !important;
    border-left: 3px solid var(--green-neon) !important;
}

.sidebar-hint-log-body .hint-log-pos {
    font-family: var(--font-title) !important;
    font-size: 0.75rem !important;
    color: var(--green-dark) !important;
    font-weight: bold !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important; /* 被り防止: 文字の長さに合わせて占有幅を自動確保 */
    padding-top: 0 !important;
}

.sidebar-hint-log-body .hint-log-advice {
    font-size: 0.75rem !important;
    color: var(--text-primary) !important;
    line-height: 1.3 !important;
}

.sidebar-hint-log-body .hint-log-list:empty::after {
    content: 'まだヒントを使用していません' !important;
    display: block !important;
    padding: 15px !important;
    text-align: center !important;
    color: var(--text-secondary) !important;
    font-size: 0.75rem !important;
}

/* 英語版ヒントログ空メッセージ */
html[lang="en"] .sidebar-hint-log-body .hint-log-list:empty::after {
    content: 'No hints used yet' !important;
}

/* --- Sidebar Cloud Save Loader Control --- */
/* 通常時はマイクロローダーを非表示 */
.sidebar-btn-container #btn-cloud-save .sidebar-loader {
    display: none !important;
}

/* ローディング時（.loadingクラス付与時）のみ右端に表示 */
.sidebar-btn-container #btn-cloud-save.loading .sidebar-loader {
    display: grid !important;
    position: absolute !important;
    right: 14px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 10 !important;
}


