/* =============================================
   GomokuHub - Stylesheet
   ============================================= */

/* The HTML `hidden` attribute must always win over component display rules. */
[hidden] { display: none !important; }

:root {
    --bg: #f6f1e7;
    --bg-soft: #efe7d4;
    --paper: #ffffff;
    --ink: #1f1d18;
    --ink-soft: #555048;
    --accent: #8b3a1d;
    --accent-dark: #6a2c16;
    --line: #2c2620;
    --board: #e8b878;
    --board-dark: #d4a25a;
    --black: #1c1a17;
    --white: #f8f4ec;
    --shadow: 0 4px 18px rgba(40, 28, 16, 0.08);
    --radius: 10px;
    --maxw: 1140px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-serif: "Georgia", "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

.container {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: 0 24px;
}

/* ====================== Header ====================== */
.site-header {
    background: var(--paper);
    border-bottom: 1px solid #e2d8c4;
    position: sticky;
    top: 0;
    z-index: 50;
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 12px;
    padding-bottom: 12px;
    gap: 14px;
    flex-wrap: wrap;
}
.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--ink);
    letter-spacing: -0.01em;
}
.logo:hover { text-decoration: none; }
.logo-mark {
    font-size: 1.3rem;
    letter-spacing: -2px;
}
.main-nav {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    font-size: 0.95rem;
}
.main-nav a {
    color: var(--ink-soft);
    padding: 6px 2px;
    border-bottom: 2px solid transparent;
}
.main-nav a:hover {
    color: var(--accent);
    text-decoration: none;
}
.main-nav a.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ====================== Hero ====================== */
.hero {
    background: linear-gradient(135deg, var(--bg-soft) 0%, var(--bg) 100%);
    padding: 64px 0;
    border-bottom: 1px solid #e2d8c4;
}
.hero-inner {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 48px;
    align-items: center;
}
.hero h1 {
    font-family: var(--font-serif);
    font-size: 2.6rem;
    line-height: 1.15;
    margin: 0 0 16px;
    color: var(--ink);
    letter-spacing: -0.02em;
}
.hero .lead {
    font-size: 1.1rem;
    color: var(--ink-soft);
    margin: 0 0 28px;
}
.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }

/* ====================== Buttons ====================== */
.btn {
    display: inline-block;
    padding: 12px 22px;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.98rem;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.08s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
    text-align: center;
    font-family: inherit;
    box-shadow: 0 2px 6px rgba(40, 28, 16, 0.08);
}
.btn:hover { text-decoration: none; transform: translateY(-2px); box-shadow: 0 5px 14px rgba(40, 28, 16, 0.14); }
.btn:active { transform: translateY(0); box-shadow: 0 2px 6px rgba(40, 28, 16, 0.08); }
.btn-primary {
    background: linear-gradient(180deg, #a04525 0%, var(--accent) 100%);
    color: white;
    border-color: var(--accent-dark);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--accent) 0%, var(--accent-dark) 100%); color: white; }
.btn-secondary {
    background: var(--paper);
    color: var(--ink);
    border-color: #c7b793;
}
.btn-secondary:hover { background: var(--bg-soft); color: var(--ink); border-color: #b0a58a; }
.btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent-dark);
}

/* ====================== Mini Board (hero art) ====================== */
.hero-art { display: flex; justify-content: center; }
.board-mini {
    background: var(--board);
    border: 6px solid #6e4a25;
    border-radius: 6px;
    padding: 10px;
    box-shadow: var(--shadow);
}
.mini-row {
    display: flex;
}
.mini-row span {
    width: 28px;
    height: 28px;
    border-right: 1px solid #7a5a30;
    border-bottom: 1px solid #7a5a30;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.mini-row span:nth-child(8n) { border-right: none; }
.mini-row:nth-child(8n) span { border-bottom: none; }
.mini-row span::after {
    content: "";
    width: 22px;
    height: 22px;
    border-radius: 50%;
}
.mini-row span.b::after { background: var(--black); }
.mini-row span.w::after { background: var(--white); box-shadow: inset 0 0 0 1px #6a5a40; }

/* ====================== Sections ====================== */
section { padding: 40px 0; }
section h2 {
    font-family: var(--font-serif);
    font-size: 1.7rem;
    margin: 0 0 18px;
    color: var(--ink);
    letter-spacing: -0.01em;
}
.section-intro { color: var(--ink-soft); margin-top: -6px; margin-bottom: 20px; }

/* ====================== Features ====================== */
.features { background: var(--paper); }
.feature-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 22px;
}
.feature-card {
    background: var(--bg);
    border: 1px solid #e2d8c4;
    padding: 24px;
    border-radius: var(--radius);
}
.feature-card h3 { margin-top: 0; }

/* ====================== Articles Grid ====================== */
.article-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}
.article-card {
    background: var(--paper);
    border: 1px solid #e2d8c4;
    border-radius: 14px;
    padding: 18px;
    color: var(--ink);
    transition: transform 0.1s ease, box-shadow 0.15s ease;
    display: block;
}
.article-card:hover {
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: #c7b793;
}
.article-card h3 { margin-top: 0; color: var(--ink); }
.article-card p { color: var(--ink-soft); }
.article-card .read-more {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.95rem;
}

/* ====================== FAQ ====================== */
.faq { background: var(--paper); border-top: 1px solid #e2d8c4; padding: 32px 0; }
.faq-list { display: grid; gap: 10px; max-width: 800px; }
.faq details {
    background: var(--bg);
    border: 1px solid #e2d8c4;
    border-radius: 12px;
    padding: 12px 16px;
}
.faq summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--ink);
    font-size: 0.95rem;
}
.faq details[open] { box-shadow: var(--shadow); }
.faq p { margin: 8px 0 0; color: var(--ink-soft); font-size: 0.95rem; }

/* ====================== Footer ====================== */
.site-footer {
    background: #2a241d;
    color: #d6c9ad;
    padding: 36px 0 20px;
    margin-top: 32px;
}
.footer-inner {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr;
    gap: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid #4a3f30;
}
.site-footer h4 {
    color: white;
    margin: 0 0 10px;
    font-size: 0.95rem;
}
.site-footer a {
    color: #d6c9ad;
    display: block;
    padding: 3px 0;
    font-size: 0.9rem;
}
.site-footer a:hover { color: white; }
.site-footer strong { color: white; font-size: 1.1rem; }
.footer-bottom {
    padding-top: 16px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.85rem;
}
    font-size: 0.9rem;
    color: #a59a7e;
}

/* ====================== Page Header ====================== */
.page-header {
    background: linear-gradient(135deg, var(--bg-soft) 0%, var(--bg) 100%);
    border-bottom: 1px solid #e2d8c4;
    padding: 48px 0 32px;
}
.page-header h1 {
    font-family: var(--font-serif);
    font-size: 2.3rem;
    margin: 0 0 8px;
    letter-spacing: -0.01em;
}
.page-header .lead { color: var(--ink-soft); margin: 0; font-size: 1.05rem; }

/* ====================== Article (long-form) ====================== */
.article { padding: 32px 0 64px; }
.article-wrap { max-width: 780px; }
.breadcrumb { font-size: 0.9rem; color: var(--ink-soft); margin-bottom: 14px; }
.breadcrumb a { color: var(--ink-soft); }
.article-header { margin-bottom: 24px; padding-bottom: 18px; border-bottom: 1px solid #e2d8c4; }
.article-header h1 {
    font-family: var(--font-serif);
    font-size: 2.3rem;
    margin: 0 0 6px;
    letter-spacing: -0.01em;
    line-height: 1.2;
}
.article-meta { color: var(--ink-soft); font-size: 0.9rem; margin: 0; }
.article-body { font-size: 1.06rem; line-height: 1.75; color: #2a261f; }
.article-body .lead {
    font-size: 1.18rem;
    color: var(--ink);
    font-family: var(--font-serif);
    line-height: 1.5;
    margin: 0 0 28px;
    padding: 0 0 18px;
    border-bottom: 1px dashed #d8c8a4;
}
.article-body h2 {
    font-family: var(--font-serif);
    font-size: 1.55rem;
    margin-top: 38px;
    margin-bottom: 14px;
    color: var(--ink);
}
.article-body h3 {
    font-size: 1.2rem;
    margin-top: 26px;
    margin-bottom: 8px;
    color: var(--ink);
}
.article-body p, .article-body li { margin: 0 0 12px; }
.article-body ul, .article-body ol { padding-left: 22px; }
.article-body strong { color: var(--ink); }

.compare-table-wrap { overflow-x: auto; margin: 18px 0; }
.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.97rem;
    background: var(--paper);
    border: 1px solid #e2d8c4;
    border-radius: var(--radius);
    overflow: hidden;
}
.compare-table th, .compare-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid #e2d8c4;
    vertical-align: top;
}
.compare-table thead { background: var(--bg-soft); }
.compare-table th { color: var(--ink); font-weight: 700; }
.compare-table tr:last-child td { border-bottom: none; }

.related-articles {
    margin-top: 48px;
    padding: 22px;
    background: var(--bg-soft);
    border-radius: var(--radius);
    border-left: 4px solid var(--accent);
}
.related-articles h3 { margin-top: 0; }
.related-articles ul { list-style: none; padding: 0; margin: 0; }
.related-articles li { padding: 4px 0; }

/* ====================== Play Page ====================== */
.play-body { background: var(--bg); }
.play-main { padding: 32px 0 56px; }
.play-container h1 {
    font-family: var(--font-serif);
    font-size: 2.1rem;
    margin: 0 0 8px;
    letter-spacing: -0.01em;
}
.play-container .lead { color: var(--ink-soft); margin: 0 0 28px; }

.game-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 28px;
    align-items: start;
}
.game-sidebar { display: flex; flex-direction: column; gap: 18px; }
.panel {
    background: var(--paper);
    border: 1px solid #e2d8c4;
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.panel:hover { box-shadow: 0 6px 22px rgba(40, 28, 16, 0.1); }
.panel h2 {
    font-size: 1.05rem;
    margin: 0 0 12px;
    color: var(--ink);
    font-family: var(--font);
    letter-spacing: 0;
}
.panel label {
    display: block;
    font-size: 0.9rem;
    color: var(--ink-soft);
    margin-bottom: 12px;
}
.panel select {
    display: block;
    width: 100%;
    padding: 8px 10px;
    margin-top: 4px;
    border-radius: 6px;
    border: 1px solid #c7b793;
    background: var(--bg);
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--ink);
}
.buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.buttons .btn { flex: 1; padding: 10px 14px; font-size: 0.92rem; }
.status { margin: 0 0 6px; font-weight: 600; color: var(--ink); }
.moves-info { margin: 0; font-size: 0.88rem; color: var(--ink-soft); }
.quick-guide { padding-left: 18px; margin: 0; font-size: 0.92rem; color: var(--ink-soft); }
.quick-guide li { margin-bottom: 6px; }

.board-wrap {
    position: relative;
    background: var(--paper);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid #e2d8c4;
    box-shadow: 0 8px 28px rgba(40, 28, 16, 0.1);
    display: flex;
    justify-content: center;
}
#board {
    width: 100%;
    max-width: 600px;
    height: auto;
    aspect-ratio: 1 / 1;
    cursor: crosshair;
    display: block;
    border-radius: 10px;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.game-overlay {
    position: absolute;
    inset: 0;
    background: rgba(31, 29, 24, 0.82);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 5;
    backdrop-filter: blur(2px);
    animation: fadeIn 0.25s ease;
}
.overlay-box {
    background: var(--paper);
    padding: 36px 32px;
    border-radius: 16px;
    text-align: center;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    transform: translateY(0);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.overlay-box h2 { font-family: var(--font-serif); margin-top: 0; font-size: 1.7rem; }
.overlay-box p { color: var(--ink-soft); margin: 0 0 22px; font-size: 1.05rem; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes popIn {
    from { opacity: 0; transform: scale(0.92) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.play-articles { margin-top: 56px; }

/* ====================== Responsive ====================== */
@media (max-width: 900px) {
    .hero-inner { grid-template-columns: 1fr; }
    .hero h1 { font-size: 2rem; }
    .feature-grid { grid-template-columns: 1fr; }
    .footer-inner { grid-template-columns: 1fr; }
    .game-layout { grid-template-columns: 1fr; }
    .game-sidebar { order: 2; }
    .board-wrap { order: 1; }
    .article-header h1 { font-size: 1.8rem; }
    .main-nav { gap: 12px; font-size: 0.9rem; }
    .hero { padding: 40px 0; }
    section { padding: 40px 0; }
}
@media (max-width: 600px) {
    .container { padding: 0 14px; }
    .header-inner { flex-direction: column; align-items: flex-start; gap: 12px; }
    .main-nav { width: 100%; gap: 10px; font-size: 0.85rem; flex-wrap: wrap; }
    .main-nav a { padding: 6px 0; }
    .hero h1 { font-size: 1.75rem; }
    .article-header h1 { font-size: 1.55rem; }
    .panel { padding: 14px 16px; }
    .board-wrap { padding: 10px; border-radius: 12px; }
    .game-page-header { padding: 24px 0 18px; }
    .game-page-header h1 { font-size: 1.55rem; }
    .game-page-header .lead { font-size: 0.95rem; }
    .lobby-hero { padding: 32px 0 24px; }
    .lobby-hero h1 { font-size: 1.85rem; }
    .lobby-hero .lead { font-size: 0.95rem; margin-bottom: 16px; }
    .category-title { margin: 24px 0 6px; font-size: 1.25rem; }
    .game-grid { gap: 14px; padding: 16px 0 24px; grid-template-columns: repeat(2, 1fr); }
    .game-card { padding: 14px; }
    .game-card-icon { width: 42px; height: 42px; font-size: 1.25rem; margin-bottom: 10px; }
    .game-card h3 { font-size: 1rem; }
    .game-card p { font-size: 0.82rem; margin-bottom: 10px; }
    .btn { padding: 12px 18px; width: 100%; }
    .buttons { display: flex; flex-direction: column; gap: 10px; }
    select, input, button { min-height: 44px; }
}

/* ====================== Game Lobby ====================== */
.lobby-hero {
    background: linear-gradient(135deg, var(--paper) 0%, var(--bg-soft) 100%);
    padding: 48px 0 32px;
    text-align: center;
}
.lobby-hero h1 {
    font-family: var(--font-serif);
    font-size: 2.4rem;
    margin: 0 0 12px;
    color: var(--ink);
}
.lobby-hero .lead {
    font-size: 1.05rem;
    color: var(--ink-soft);
    max-width: 580px;
    margin: 0 auto 20px;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 18px;
    padding: 20px 0 32px;
}
.game-card {
    background: var(--paper);
    border: 1px solid #e2d8c4;
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow);
    transition: transform 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.18s ease;
    display: flex;
    flex-direction: column;
}
.game-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 26px rgba(40, 28, 16, 0.12);
    text-decoration: none;
    border-color: #d4c6a4;
}
.game-card-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--bg-soft) 0%, #f0e6d0 100%);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px rgba(139, 58, 29, 0.08);
}
.game-card h3 {
    margin: 0 0 6px;
    font-size: 1.1rem;
    color: var(--ink);
}
.game-card p {
    margin: 0 0 12px;
    font-size: 0.9rem;
    color: var(--ink-soft);
    flex: 1;
    line-height: 1.45;
}
.game-card-meta {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 600;
}

.category-title {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    margin: 32px 0 6px;
    color: var(--ink);
}
.category-desc {
    color: var(--ink-soft);
    margin: 0 0 12px;
    font-size: 0.95rem;
}

/* ====================== Game Page Common ====================== */
.game-page-header {
    text-align: center;
    padding: 40px 0 24px;
}
.game-page-header h1 {
    font-family: var(--font-serif);
    font-size: 2rem;
    margin: 0 0 8px;
}
.game-page-header .lead {
    color: var(--ink-soft);
    margin: 0;
}

/* ====================== Sudoku ====================== */
.sudoku-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    width: 100%;
}
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    max-width: 460px;
    aspect-ratio: 1 / 1;
    border: 4px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    background: var(--line);
    gap: 1px;
    box-shadow: inset 0 0 0 2px var(--line);
}
.sudoku-cell {
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.1rem, 4.5vw, 1.65rem);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: background 0.12s ease, transform 0.08s ease;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}
.sudoku-cell:hover { background: #f7f2e8; }
.sudoku-cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--line); }
.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--line); }
.sudoku-cell.fixed {
    background: #f0e9da;
    color: var(--ink);
    font-weight: 800;
}
.sudoku-cell.selected {
    background: #bfdbfe;
    box-shadow: inset 0 0 0 2px #3b82f6;
}
.sudoku-cell.same-number {
    background: #e0f2fe;
}
.sudoku-cell.error {
    color: #c0392b;
    background: #ffeaea;
    animation: shake 0.3s ease;
}
.sudoku-cell.notes {
    font-size: clamp(0.55rem, 2.2vw, 0.85rem);
    color: var(--ink-soft);
    letter-spacing: 1px;
    font-weight: 500;
}
.sudoku-numpad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 380px;
}
.sudoku-numpad button {
    padding: 14px;
    font-size: 1.15rem;
    font-weight: 700;
    border: 1px solid #c7b793;
    border-radius: 10px;
    background: linear-gradient(180deg, #ffffff 0%, #f7f2e8 100%);
    color: var(--ink);
    cursor: pointer;
    transition: transform 0.08s ease, box-shadow 0.1s ease;
    box-shadow: 0 2px 4px rgba(40, 28, 16, 0.06);
}
.sudoku-numpad button:hover { background: #f0e9da; transform: translateY(-1px); }
.sudoku-numpad button:active { transform: translateY(1px); }
.sudoku-numpad .num-clear { grid-column: span 2; }

@media (max-width: 600px) {
    .sudoku-wrap { gap: 16px; }
    .sudoku-grid { max-width: none; border-width: 3px; border-radius: 8px; }
    .sudoku-cell { font-size: clamp(1rem, 9vw, 1.5rem); }
    .sudoku-cell.notes { font-size: clamp(0.45rem, 4vw, 0.7rem); }
    .sudoku-numpad { max-width: none; gap: 8px; }
    .sudoku-numpad button { padding: 16px 10px; font-size: 1.25rem; }
}

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

/* ====================== Memory Match ====================== */
.memory-wrap {
    min-height: auto;
}
.memory-grid {
    display: grid;
    gap: 12px;
    width: 100%;
    max-width: 500px;
    perspective: 800px;
}
.memory-4 { grid-template-columns: repeat(4, 1fr); }
.memory-6 { grid-template-columns: repeat(6, 1fr); }
.memory-card {
    aspect-ratio: 1 / 1;
    background: transparent;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.8rem, 8vw, 2.6rem);
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    user-select: none;
}
.memory-card .front,
.memory-card .back {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    border-radius: 14px;
    box-shadow: 0 4px 10px rgba(40, 28, 16, 0.12);
}
.memory-card .front {
    background: linear-gradient(135deg, #a04525 0%, var(--accent) 100%);
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
    border: 2px solid var(--accent-dark);
}
.memory-card .back {
    background: linear-gradient(135deg, #ffffff 0%, #f7f2e8 100%);
    border: 2px solid #e2d8c4;
    transform: rotateY(180deg);
}
.memory-card.flipped,
.memory-card.matched {
    transform: rotateY(180deg);
}
.memory-card.matched {
    animation: matchPop 0.4s ease;
}
.memory-card.matched .back {
    background: linear-gradient(135deg, #e6f4ea 0%, #d4edda 100%);
    border-color: #8bc34a;
}
.memory-card:hover:not(.flipped):not(.matched) .front {
    filter: brightness(1.1);
}

@keyframes matchPop {
    0% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.12); }
    100% { transform: rotateY(180deg) scale(1); }
}

@media (max-width: 600px) {
    .memory-grid { gap: 8px; }
    .memory-card { border-radius: 10px; }
    .memory-card .front,
    .memory-card .back { border-radius: 10px; }
    .memory-card .front { font-size: 1.2rem; }
}

/* ====================== Solitaire ====================== */
.solitaire-wrap {
    min-height: auto;
}
.solitaire-table {
    width: 100%;
    max-width: 860px;
    padding: 16px;
}
.solitaire-top {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 12px;
    margin-bottom: 28px;
}
.solitaire-spacer {
    grid-column: span 1;
}
.solitaire-pile {
    aspect-ratio: 5 / 7;
    background: rgba(255,255,255,0.6);
    border: 2px dashed #c7b793;
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.solitaire-pile:hover { background: rgba(255,255,255,0.9); }
.solitaire-pile.empty .pile-label {
    color: #b0a58a;
    font-size: 1.5rem;
    font-weight: 700;
}
.solitaire-pile.foundation[data-suit="hearts"],
.solitaire-pile.foundation[data-suit="diamonds"] { border-color: #ef9a9a; }
.solitaire-pile.foundation[data-suit="clubs"],
.solitaire-pile.foundation[data-suit="spades"] { border-color: #9e9e9e; }
.solitaire-tableau {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 12px;
    min-height: 360px;
}
.tableau-column {
    position: relative;
    min-height: 100px;
    border-radius: 10px;
    border: 2px dashed #d8c8a4;
    background: rgba(255,255,255,0.35);
    transition: background 0.15s ease;
}
.tableau-column.drop-target {
    background: #e8f5e9;
    border-color: #81c784;
}
.card {
    position: absolute;
    width: calc(100% - 4px);
    left: 2px;
    aspect-ratio: 5 / 7;
    border-radius: 8px;
    background: linear-gradient(135deg, #ffffff 0%, #f9f6ef 100%);
    border: 1px solid #c7b793;
    box-shadow: 0 2px 5px rgba(0,0,0,0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 2.2vw, 1.5rem);
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.1s ease, transform 0.1s ease;
}
.card:active { cursor: grabbing; }
.card.face-down {
    background: repeating-linear-gradient(45deg, #7a3219 0px, #7a3219 8px, #9a4323 8px, #9a4323 16px);
    border-color: #5e2613;
}
.card.face-up.red { color: #c0392b; }
.card.face-up.black { color: #2c3e50; }
.card.selected,
.card.dragging {
    box-shadow: 0 0 0 3px #3b82f6, 0 8px 20px rgba(0,0,0,0.2);
    transform: translateY(-4px);
    z-index: 100 !important;
}
.card-rank {
    position: absolute;
    font-size: 0.6rem;
    line-height: 1;
    font-weight: 800;
}
.card-rank.top { top: 5px; left: 6px; }
.card-rank.bottom { bottom: 5px; right: 6px; transform: rotate(180deg); }
.card-suit {
    font-size: 1.8rem;
}
.drag-ghost {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.92;
    transform: rotate(3deg);
}

/* ====================== D-Pad ====================== */
.dpad {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
    width: 100%;
    max-width: 220px;
}
.dpad-row {
    display: flex;
    gap: 8px;
    justify-content: center;
}
.dpad button {
    width: 64px;
    height: 52px;
    font-size: 1.3rem;
    border: 1px solid #c7b793;
    border-radius: 10px;
    background: linear-gradient(180deg, #ffffff 0%, #f7f2e8 100%);
    color: var(--ink);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(40, 28, 16, 0.1);
}
.dpad button:active { background: #f0e9da; transform: translateY(1px); }

@media (max-width: 700px) {
    .dpad { display: flex; }
}

@media (max-width: 700px) {
    .solitaire-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .solitaire-table { min-width: 520px; padding: 10px; }
    .solitaire-top { gap: 8px; margin-bottom: 18px; }
    .solitaire-tableau { gap: 8px; min-height: 280px; }
    .tableau-column { min-height: 72px; }
    .card { font-size: 0.85rem; border-radius: 6px; }
    .card-rank { font-size: 0.5rem; }
    .card-suit { font-size: 1.2rem; }
}
