/* ───────────────────────────────────────────────────────────────
   base.css : 共通トークン・全画面で使うレイアウト・コンポーネント
   各ゲーム固有のスタイルは games/<kind>.css（.game-<kind> でscope）
   ─────────────────────────────────────────────────────────────── */

:root {
    /* ─── 背景・サーフェス ─── */
    --bg-from: #f5f3ff;
    --bg-to: #fdf4ff;
    --bg-tint-1: rgba(196, 181, 253, 0.22);
    --bg-tint-2: rgba(251, 207, 232, 0.22);

    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-mute: #f1f5f9;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    /* ─── アクセント（プレイフルなバイオレット） ─── */
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-soft: #eef2ff;

    /* ─── プレイヤーカラー（共通セマンティック） ─── */
    --p1: #2563eb;
    --p1-strong: #1d4ed8;
    --p1-soft: #dbeafe;
    --p2: #ea580c;
    --p2-strong: #b91c1c;
    --p2-soft: #ffedd5;

    /* ─── ステータス ─── */
    --success: #10b981;
    --success-soft: #d1fae5;
    --warning: #f59e0b;
    --warning-soft: #fef3c7;
    --error: #ef4444;
    --error-soft: #fee2e2;

    /* ─── 角丸 ─── */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 18px;
    --r-xl: 24px;

    /* ─── 影 ─── */
    --sh-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --sh-md: 0 6px 18px rgba(15, 23, 42, 0.09);
    --sh-lg: 0 16px 40px rgba(15, 23, 42, 0.14);

    /* ─── イージング ─── */
    --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

    /* ─── ボードの最大サイズ（vmin で縦横どっちでもフィット） ─── */
    --board-max: min(560px, 92vmin);
    --board-max-wide: min(620px, 94vmin);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
}

body {
    min-height: 100dvh;
    background:
        radial-gradient(
            1100px 700px at 12% -10%,
            var(--bg-tint-1),
            transparent 60%
        ),
        radial-gradient(
            900px 600px at 110% 110%,
            var(--bg-tint-2),
            transparent 60%
        ),
        linear-gradient(135deg, var(--bg-from), var(--bg-to));
    background-attachment: fixed;
    color: var(--text);
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
        "Helvetica Neue", Arial, sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* ─── アプリ外殻 ─────────────────────────────────────────────── */

.retro-app {
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border-radius: 22px;
    box-shadow: var(--sh-lg);
    padding: 28px 28px 32px;
    position: relative;
    overflow: hidden;
    animation: fade-up 0.35s var(--ease-out);
}

/* ゲーム画面のときは少し広めに（盤の視認性確保） */
.retro-app:has(.game) {
    max-width: 720px;
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.retro-app h1 {
    margin: 0 0 22px;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-align: center;
    background: linear-gradient(135deg, #6366f1, #ec4899 60%, #f59e0b);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* ─── 共通ボタン ─────────────────────────────────────────────── */

button {
    appearance: none;
    border: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: var(--r-md);
    cursor: pointer;
    transition:
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease,
        transform 0.12s var(--ease-pop),
        box-shadow 0.15s ease;
}

button:active {
    transform: scale(0.96);
}

button.primary {
    background: var(--accent);
    color: white;
    font-size: 15px;
    padding: 12px 24px;
    box-shadow: var(--sh-sm);
}
button.primary:hover {
    background: var(--accent-hover);
    box-shadow: var(--sh-md);
    transform: translateY(-1px);
}

button.secondary {
    background: var(--surface-soft);
    color: var(--accent);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 240px;
    padding: 12px 24px;
    font-size: 15px;
}
button.secondary:hover {
    background: var(--surface);
    border-color: var(--accent);
}

button.ghost {
    background: var(--surface-soft);
    color: var(--text-muted);
    font-size: 12px;
    padding: 6px 12px;
    border-radius: var(--r-sm);
    font-weight: 500;
}
button.ghost:hover {
    background: var(--surface-mute);
    color: var(--text);
}
button.ghost.copied {
    background: var(--success-soft);
    color: var(--success);
}

/* ─── ゲーム画面の共通レイアウト ──────────────────────────────── */

/* 各ゲームの root には class="game game-<kind>" が付く */
.game {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: stretch;
}

.room-chrome {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ─── ステータスパネル ────────────────────────────────────────── */

.status {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.status-row:nth-child(2) {
    justify-content: space-between;
}

.status-text {
    font-size: 13px;
    color: var(--text-muted);
}

.status-divider {
    color: var(--text-faint);
}

.connection-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
}
.connection-dot.connected {
    background: var(--success);
}
.connection-dot.connecting {
    background: var(--warning);
    animation: pulse-dot 1.2s ease-in-out infinite;
}
.connection-dot.disconnected {
    background: var(--error);
}

@keyframes pulse-dot {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* ─── you-badge（共通の自分マーカー） ────────────────────────── */

.you-badge {
    font-size: 13px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--surface);
}
.you-badge.x {
    color: var(--p1-strong);
    background: var(--p1-soft);
}
.you-badge.o {
    color: var(--p2);
    background: var(--p2-soft);
}
.you-badge.p1 {
    color: var(--p1-strong);
    background: var(--p1-soft);
}
.you-badge.p2 {
    color: var(--p2-strong);
    background: #fee2e2;
}
.you-badge.black {
    color: #1a1a1a;
    background: #e5e7eb;
}
.you-badge.white {
    color: #1f2937;
    background: #ffffff;
    border: 1px solid var(--border-strong);
}
.you-badge.none {
    color: var(--text-muted);
}

/* ─── ルームコード ────────────────────────────────────────────── */

.room-code {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 4px 0 8px;
}
.room-code-label {
    font-size: 11px;
    color: var(--text-muted);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 600;
}
.room-code-value {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 30px;
    font-weight: 800;
    letter-spacing: 0.2em;
    color: var(--text);
}

/* ─── ターンバナー ────────────────────────────────────────────── */

.turn-banner {
    margin: 0;
    padding: 14px 16px;
    border-radius: var(--r-md);
    font-size: 15px;
    font-weight: 700;
    text-align: center;
    transition:
        background 0.2s ease,
        color 0.2s ease;
}

.turn-banner.your-turn {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #065f46;
    animation: glow 1.8s ease-in-out infinite;
}
@keyframes glow {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.18);
    }
}

.turn-banner.waiting-turn {
    background: var(--surface-soft);
    color: var(--text-muted);
}

.turn-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}
.turn-label {
    flex: 1;
}
.turn-timer-text {
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    font-weight: 700;
    opacity: 0.85;
}

.timer-bar {
    margin-top: 10px;
    height: 4px;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    overflow: hidden;
}
.timer-bar-fill {
    height: 100%;
    background: currentColor;
    transition:
        width 0.25s linear,
        background 0.2s ease;
    opacity: 0.85;
}
.timer-bar-fill.warning {
    background: var(--warning);
    opacity: 1;
}
.timer-bar-fill.danger {
    background: var(--error);
    opacity: 1;
    animation: timer-pulse 0.6s ease-in-out infinite;
}
@keyframes timer-pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.55;
    }
}

/* ─── エラー / 待機 ─────────────────────────────────────────── */

.error {
    margin: 0;
    padding: 10px 14px;
    background: var(--error-soft);
    color: var(--error);
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 600;
    animation: shake 0.32s ease;
}

@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-4px);
    }
    75% {
        transform: translateX(4px);
    }
}

.waiting {
    margin: 0;
    padding: 36px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.game-loading {
    padding: 36px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ─── ゲーム終了オーバーレイ ─────────────────────────────────── */

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 22px;
    animation: fade-in 0.25s ease;
    z-index: 10;
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.overlay-card {
    background: var(--surface);
    padding: 28px 32px 24px;
    border-radius: var(--r-lg);
    box-shadow: var(--sh-lg);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    min-width: 240px;
    animation: pop-in 0.3s var(--ease-pop);
}

@keyframes pop-in {
    0% {
        opacity: 0;
        transform: scale(0.85);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.overlay-card h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.overlay-card.you-won h2 {
    color: var(--success);
}
.overlay-card.you-lost h2 {
    color: var(--text-muted);
}
.overlay-card.draw h2 {
    color: var(--warning);
}
.overlay-card.neutral h2 {
    color: var(--text);
}

/* 勝利時はちょっと弾ける感を追加（紙吹雪っぽく） */
.overlay-card.you-won::before {
    content: "🎉";
    position: absolute;
    top: -12px;
    left: 12px;
    font-size: 28px;
    animation: confetti-l 0.9s var(--ease-pop) forwards;
}
.overlay-card.you-won::after {
    content: "✨";
    position: absolute;
    top: -12px;
    right: 12px;
    font-size: 28px;
    animation: confetti-r 0.9s var(--ease-pop) forwards;
}
.overlay-card {
    position: relative;
}

@keyframes confetti-l {
    0% {
        opacity: 0;
        transform: translate(0, 12px) rotate(0);
    }
    100% {
        opacity: 1;
        transform: translate(-8px, 0) rotate(-12deg);
    }
}
@keyframes confetti-r {
    0% {
        opacity: 0;
        transform: translate(0, 12px) rotate(0);
    }
    100% {
        opacity: 1;
        transform: translate(8px, 0) rotate(12deg);
    }
}

/* ─── 降参ボタン ─────────────────────────────────────────────── */

.resign-btn {
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    padding: 4px 10px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    font-weight: 600;
    margin-left: auto;
}
.resign-btn:hover {
    background: var(--error-soft);
    color: var(--error);
    border-color: var(--error);
}

/* ─── ダイアログ内ボタン行 ────────────────────────────────────── */

.button-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ─── モバイル ────────────────────────────────────────────────── */

@media (max-width: 640px) {
    body {
        padding: 8px;
        align-items: flex-start;
    }
    .retro-app {
        padding: 20px 16px 24px;
        border-radius: 16px;
    }
    .retro-app:has(.game) {
        padding: 14px 10px 18px;
        border-radius: 14px;
    }
    .retro-app h1 {
        font-size: 19px;
        margin-bottom: 14px;
    }
    .status {
        padding: 10px 12px;
        gap: 8px;
    }
    .room-code-value {
        font-size: 24px;
    }
    .turn-banner {
        padding: 10px 12px;
        font-size: 14px;
    }
    .overlay {
        border-radius: 14px;
    }
    .overlay-card {
        min-width: 200px;
        padding: 22px 24px 20px;
    }
    .overlay-card h2 {
        font-size: 20px;
    }
    .game {
        gap: 10px;
    }
    .room-chrome {
        gap: 12px;
    }
}

@media (max-width: 380px) {
    .retro-app:has(.game) {
        padding: 10px 6px 16px;
    }
}
