html.wiki-html,
body.wiki-body {
    height: auto !important;
    min-height: 100%;
    overflow: visible !important;
    touch-action: pan-y !important;
}

html.wiki-html {
    overflow-y: auto !important;
    scroll-behavior: smooth;
}

body.wiki-body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(165deg, #1a1410 0%, #0d0a08 40%, #12101a 100%);
    color: #e8e0d0;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.55;
    display: block !important;
}

body.wiki-body.wiki-sidebar-open {
    overflow: hidden !important;
    touch-action: none !important;
}

body.wiki-body * {
    user-select: text;
    -webkit-user-select: text;
}

.wiki-app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.wiki-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    background: rgba(13, 10, 8, 0.94);
    border-bottom: 2px solid var(--px-border, #4a3424);
    backdrop-filter: blur(10px);
}

.wiki-topbar-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.wiki-topbar-row--primary {
    min-height: 40px;
}

.wiki-topbar-row--search {
    min-width: 0;
}

.wiki-brand {
    flex: 1;
    min-width: 0;
}

.wiki-brand h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(9px, 2.4vw, 11px);
    color: var(--px-gold, #ffd54f);
    margin: 0 0 4px;
    line-height: 1.6;
}

.wiki-brand-tagline {
    margin: 0;
    font-size: 12px;
    color: #9a9080;
}

.wiki-search {
    width: 100%;
    min-width: 0;
    flex: 1;
    padding: 10px 12px;
    border: 2px solid var(--px-border, #4a3424);
    background: rgba(22, 16, 12, 0.9);
    color: #f5f0e6;
    font-size: 16px; /* ป้องกัน iOS zoom ตอนโฟกัส */
    border-radius: 2px;
    box-sizing: border-box;
}

.wiki-search::placeholder {
    color: #6a6058;
}

.wiki-link-game {
    flex-shrink: 0;
    font-size: 13px;
    color: var(--px-gold, #ffd54f);
    text-decoration: none;
    white-space: nowrap;
    padding: 8px 10px;
    border: 2px solid var(--px-border-light, #8d6e63);
    border-radius: 2px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    box-sizing: border-box;
}

.wiki-link-game:hover {
    background: rgba(255, 213, 79, 0.08);
}

.wiki-menu-toggle {
    display: none;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 44px;
    min-height: 44px;
    padding: 8px 12px;
    font-size: 13px;
    border: 2px solid var(--px-border, #4a3424);
    background: rgba(46, 36, 28, 0.8);
    color: #e8e0d0;
    cursor: pointer;
    border-radius: 2px;
    box-sizing: border-box;
}

.wiki-menu-toggle-icon {
    font-size: 16px;
    line-height: 1;
}

.wiki-shell {
    display: flex;
    flex: 1;
    align-items: stretch;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

@media (min-width: 861px) {
    .wiki-topbar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 12px 16px;
    }

    .wiki-topbar-row--primary {
        flex: 1 1 auto;
        min-width: 200px;
    }

    .wiki-topbar-row--search {
        flex: 1 1 240px;
        max-width: 360px;
        margin-left: auto;
    }

    .wiki-search {
        font-size: 14px;
        padding: 8px 12px;
    }
}

.wiki-sidebar {
    flex: 0 0 240px;
    position: sticky;
    top: 72px;
    align-self: flex-start;
    max-height: calc(100vh - 80px);
    max-height: calc(100dvh - 80px);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    border-right: 2px solid var(--px-border, #4a3424);
    background: rgba(14, 10, 8, 0.6);
}

.wiki-sidebar-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    padding: 16px 12px 32px;
}

.wiki-nav-group {
    margin-bottom: 18px;
}

.wiki-nav-group:first-child .wiki-nav-group-title {
    padding-top: 0;
}

.wiki-nav-group-title {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: var(--px-gold-dim, #c9a227);
    margin: 0 0 6px;
    padding: 6px 10px 4px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1.35;
    border-bottom: 1px solid rgba(141, 110, 99, 0.45);
}

.wiki-nav-link {
    display: block;
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    margin-bottom: 2px;
    border: none;
    background: transparent;
    color: #c8bfb0;
    font-size: 13px;
    cursor: pointer;
    border-radius: 2px;
    text-decoration: none;
}

.wiki-nav-link:hover,
.wiki-nav-link.is-active {
    background: rgba(255, 213, 79, 0.12);
    color: var(--px-gold, #ffd54f);
}

.wiki-nav-link.is-hidden {
    display: none;
}

.wiki-nav-sublink {
    padding-left: 18px;
    font-size: 12px;
}

.wiki-main-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.wiki-main {
    flex: 1;
    min-width: 0;
    padding: 20px 20px 48px;
    padding-bottom: max(48px, env(safe-area-inset-bottom));
    min-height: 240px;
}

.wiki-loading {
    margin: 24px 0;
    text-align: center;
    color: #9a9080;
    font-size: 14px;
}

.wiki-loading[hidden] {
    display: none !important;
}

.wiki-error {
    padding: 16px;
    color: #ef9a9a;
    text-align: center;
}

.wiki-page {
    max-width: 900px;
}

.wiki-page-lead {
    color: #c8bfb0;
    margin: 0 0 16px;
}

.wiki-quest-legend {
    margin: 0 0 16px;
    padding-left: 1.2em;
    color: #d5cbb8;
}

.wiki-quest-legend li {
    margin-bottom: 6px;
}

.wiki-quest-main-overview {
    margin: 0 0 20px;
    padding: 12px 14px;
    border: 1px solid #4a4035;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
}

.wiki-quest-main-overview .wiki-page-note {
    margin: 0 0 10px;
}

.wiki-quest-tree {
    margin: 0;
    padding-left: 1.2em;
    color: #d5cbb8;
    line-height: 1.5;
}

.wiki-quest-tree ul {
    margin: 4px 0 8px;
    padding-left: 1.2em;
}

.wiki-quest-tier {
    margin: 0 0 24px;
}

.wiki-quest-tier-heading {
    margin: 0 0 12px;
    font-size: 15px;
    color: #e8dcc8;
    border-bottom: 1px solid #4a4035;
    padding-bottom: 6px;
}

.wiki-quest-type-panel {
    padding: 4px 0 8px;
}

.wiki-quest-block {
    margin: 0 0 22px;
}

.wiki-quest-block:last-child {
    margin-bottom: 4px;
}

.wiki-quest-heading {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--px-gold, #ffd54f);
    text-shadow: 1px 1px 0 #000;
}

.wiki-quest-table {
    margin: 0;
}

.wiki-quest-table .wiki-table td:first-child,
.wiki-quest-table .wiki-table th:first-child {
    width: 7.5rem;
    white-space: nowrap;
    color: #bcaaa4;
    vertical-align: top;
}

.wiki-quest-table .wiki-table td:last-child {
    word-break: break-word;
}

.wiki-quest-step {
    margin: 0 0 4px;
    line-height: 1.45;
}

.wiki-quest-step:last-child {
    margin-bottom: 0;
}

.wiki-empty,
.wiki-page-note {
    color: #c8bfb0;
    margin: 12px 0 0;
}

.wiki-kind-heading {
    font-size: 15px;
    color: var(--px-gold-dim, #c9a227);
    margin: 20px 0 10px;
}

/* แท็บ + ตารางเดียว */
.wiki-tabbed-table {
    margin: 12px 0 20px;
    border: 2px solid var(--px-border, #4a3424);
    background: rgba(18, 14, 10, 0.92);
    box-shadow: 2px 2px 0 var(--px-shadow-deep, #080604);
}

.wiki-tab-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 4px 2px;
    padding: 8px 8px 0;
    border-bottom: 2px solid var(--px-border, #4a3424);
    background: rgba(0, 0, 0, 0.2);
}

.wiki-tab-btn {
    position: relative;
    margin: 0;
    padding: 9px 14px;
    border: 2px solid transparent;
    border-bottom: none;
    border-radius: 2px 2px 0 0;
    background: rgba(46, 36, 28, 0.45);
    color: #9a9080;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.25;
    cursor: pointer;
    transition:
        background 0.12s ease,
        color 0.12s ease;
}

.wiki-tab-btn:hover {
    color: #e8e0d0;
    background: rgba(46, 36, 28, 0.75);
}

.wiki-tab-btn.is-active {
    margin-bottom: -2px;
    padding-bottom: 11px;
    border-color: var(--px-border, #4a3424);
    border-bottom-color: rgba(18, 14, 10, 0.98);
    background: rgba(18, 14, 10, 0.98);
    color: var(--px-gold, #ffd54f);
    font-weight: 700;
    z-index: 1;
}

.wiki-tab-panel {
    min-height: 48px;
}

.wiki-tab-panel .wiki-table-wrap {
    margin: 0;
    border: none;
    border-radius: 0;
}

.wiki-tab-panel .wiki-table th:first-child,
.wiki-tab-panel .wiki-table td:first-child {
    padding-left: 14px;
}

.wiki-tab-panel .wiki-table th:last-child,
.wiki-tab-panel .wiki-table td:last-child {
    padding-right: 14px;
}

.wiki-tabbed-table--nested {
    margin-top: 4px;
}

.wiki-tabbed-table--nested .wiki-tab-bar {
    padding: 6px 6px 0;
    border-bottom-width: 1px;
    background: rgba(0, 0, 0, 0.15);
}

.wiki-tabbed-table--nested .wiki-tab-btn {
    padding: 6px 12px;
    font-size: 12px;
}

.wiki-tabbed-table--nested .wiki-tab-btn.is-active {
    padding-bottom: 8px;
    color: #e8d8a8;
}

.wiki-weapon-subtabs {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.wiki-subtab-hint {
    margin: 0;
    padding: 10px 14px 4px;
    font-size: 12px;
    color: #9a9080;
}

.wiki-page h4 {
    font-size: 14px;
    color: #d4c4a8;
    margin: 14px 0 8px;
}

.wiki-slot-list {
    margin: 0 0 16px;
    padding-left: 1.25rem;
    color: #c8bfb0;
}

.wiki-slot-list li {
    margin-bottom: 4px;
}

.wiki-harvest-meta {
    margin: 0 0 12px;
    padding-left: 0;
    list-style: none;
    color: #c8bfb0;
}

.wiki-harvest-meta li {
    margin-bottom: 6px;
}

.wiki-tbl-icon {
    vertical-align: middle;
    margin-right: 6px;
    image-rendering: pixelated;
}

.wiki-tbl-name {
    vertical-align: middle;
}

.wiki-aura-swatch {
    display: inline-block;
    width: 18px;
    height: 18px;
    vertical-align: middle;
    margin-right: 8px;
    border-radius: 3px;
    background: linear-gradient(135deg, var(--aura-core), var(--aura-glow));
    box-shadow:
        0 0 6px var(--aura-glow),
        inset 0 0 4px rgba(255, 255, 255, 0.35);
}

.wiki-table .wiki-tbl-row--click {
    cursor: pointer;
}

.wiki-table .wiki-tbl-row--click:hover td {
    background: rgba(255, 213, 79, 0.08);
}

.wiki-section {
    margin-bottom: 0;
}

.wiki-section h2 {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 2.6vw, 12px);
    color: var(--px-gold, #ffd54f);
    margin: 0 0 16px;
    line-height: 1.7;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--px-border, #4a3424);
}

.wiki-section h3 {
    font-size: 16px;
    color: #f0e6d8;
    margin: 24px 0 10px;
}

.wiki-section p,
.wiki-section li {
    color: #c8bfb0;
    margin: 0 0 10px;
}

/* ลิงก์ในเนื้อหา — ไม่ใช้น้ำเงิน (พื้นน้ำตาลอ่านยาก) */
.wiki-main a,
.wiki-detail-panel a,
.wiki-page a {
    color: var(--px-gold, #ffd54f);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

.wiki-main a:hover,
.wiki-detail-panel a:hover,
.wiki-page a:hover {
    color: #ffe082;
}

.wiki-main a:visited,
.wiki-detail-panel a:visited,
.wiki-page a:visited {
    color: #e6c35c;
}

.wiki-section ul,
.wiki-section ol {
    padding-left: 1.25rem;
    margin: 0 0 14px;
}

.wiki-lead {
    font-size: 16px;
    color: #e0d6c8;
    margin-bottom: 16px !important;
}

.wiki-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 10px;
    margin: 12px 0 20px;
}

.wiki-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 10px;
    border: 2px solid var(--px-border, #4a3424);
    background: rgba(22, 16, 12, 0.85);
    cursor: pointer;
    text-align: center;
    border-radius: 2px;
    transition: border-color 0.15s, background 0.15s;
}

.wiki-card:hover {
    border-color: var(--px-gold-dim, #c9a227);
    background: rgba(46, 36, 28, 0.9);
}

.wiki-card-icon {
    width: 40px;
    height: 40px;
    image-rendering: pixelated;
    object-fit: contain;
}

.wiki-card-icon-canvas {
    width: 40px;
    height: 40px;
    image-rendering: pixelated;
}

.wiki-card-name {
    font-size: 13px;
    font-weight: 600;
    color: #f0e6d8;
    line-height: 1.3;
}

.wiki-card-meta {
    font-size: 11px;
    color: #8a8070;
}

.wiki-table-wrap {
    overflow-x: auto;
    margin: 12px 0 20px;
    border: 2px solid var(--px-border, #4a3424);
    border-radius: 2px;
}

.wiki-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.wiki-table th,
.wiki-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(74, 52, 36, 0.6);
    vertical-align: top;
}

.wiki-table th {
    background: rgba(46, 36, 28, 0.8);
    color: var(--px-gold, #ffd54f);
    font-weight: 600;
    white-space: nowrap;
}

.wiki-table tr:last-child td {
    border-bottom: none;
}

.wiki-table tr:hover td {
    background: rgba(255, 213, 79, 0.04);
}

.wiki-pill {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    border: 1px solid var(--px-border-light, #8d6e63);
    border-radius: 2px;
    color: #c8bfb0;
    margin-right: 4px;
}

.wiki-callout {
    padding: 12px 14px;
    margin: 12px 0 16px;
    border-left: 4px solid var(--px-gold, #ffd54f);
    background: rgba(46, 36, 28, 0.5);
    border-radius: 0 2px 2px 0;
}

.wiki-callout strong {
    color: #f0e6d8;
}

.wiki-kbd {
    display: inline-block;
    padding: 1px 6px;
    font-size: 11px;
    font-family: inherit;
    border: 1px solid #6a6058;
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.35);
    color: #e8e0d0;
}

.wiki-map-graph {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
    padding: 20px;
    margin: 16px 0;
    border: 2px solid var(--px-border, #4a3424);
    background: rgba(22, 16, 12, 0.6);
}

.wiki-map-node {
    padding: 12px 20px;
    border: 2px solid var(--px-border-light, #8d6e63);
    background: rgba(46, 36, 28, 0.8);
    font-weight: 600;
    color: #f0e6d8;
    text-align: center;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    transition:
        background 0.12s ease,
        border-color 0.12s ease,
        color 0.12s ease;
}

.wiki-map-node:hover {
    border-color: var(--px-gold-dim, #c9a227);
    color: #fff8e8;
}

.wiki-map-node.is-active {
    border-color: var(--px-gold, #ffd54f);
    background: rgba(255, 213, 79, 0.12);
    color: var(--px-gold, #ffd54f);
}

.wiki-map-detail {
    margin-top: 16px;
    padding: 14px 16px;
    border: 2px solid var(--px-border, #4a3424);
    background: rgba(0, 0, 0, 0.25);
}

.wiki-map-detail[hidden] {
    display: none !important;
}

.wiki-map-detail h3 {
    margin: 0 0 10px;
    font-size: 16px;
    color: var(--px-gold, #ffd54f);
}

.wiki-map-detail ul {
    margin: 0;
    padding-left: 1.25rem;
    color: #c8bfb0;
}

.wiki-map-detail-hint {
    margin: 12px 0 0;
    color: #9a9080;
    font-size: 13px;
}

.wiki-map-detail-hint[hidden] {
    display: none !important;
}

.wiki-item-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 2px 4px 2px 0;
    padding: 4px 6px;
    border: none;
    border-radius: 2px;
    background: rgba(255, 213, 79, 0.08);
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    vertical-align: middle;
    text-align: left;
}

.wiki-item-chip:hover {
    background: rgba(255, 213, 79, 0.18);
}

.wiki-item-chip--row {
    display: inline-flex;
}

.wiki-tbl-monster-cell {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    vertical-align: middle;
}

.wiki-tbl-monster-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: block;
    image-rendering: pixelated;
    object-fit: contain;
}

.wiki-pet-colors {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    white-space: nowrap;
    vertical-align: middle;
}

.wiki-pet-color-icon {
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
    width: 28px;
    height: 28px;
}

.wiki-table--pets {
    table-layout: fixed;
}

.wiki-table--pets th:nth-child(1),
.wiki-table--pets td:nth-child(1) {
    width: 28%;
}

.wiki-table--pets th:nth-child(2),
.wiki-table--pets td:nth-child(2) {
    width: 42%;
    white-space: normal;
    line-height: 1.35;
    word-break: break-word;
}

.wiki-table--pets th:nth-child(3),
.wiki-table--pets td:nth-child(3) {
    width: 30%;
    white-space: nowrap;
    vertical-align: middle;
}

.wiki-pet-ability {
    display: inline-block;
    max-width: 100%;
}

.wiki-equip-roll-note p {
    margin: 8px 0 0;
}

.wiki-equip-roll-note ul {
    margin: 8px 0 0;
    padding-left: 1.25rem;
}

.wiki-map-edge {
    color: #8d6e63;
    font-size: 20px;
}

.wiki-emoji-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0;
}

.wiki-emoji {
    font-size: 22px;
    padding: 4px;
}

/* detail modal */
.wiki-detail-root {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.wiki-detail-root[hidden] {
    display: none !important;
}

.wiki-detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
}

.wiki-detail-panel {
    position: relative;
    z-index: 1;
    width: min(420px, 100%);
    max-height: min(85vh, 640px);
    overflow-y: auto;
    padding: 18px 20px 16px;
    border: 3px solid var(--px-border, #4a3424);
    background: var(--px-panel, rgba(22, 16, 12, 0.98));
    box-shadow: 4px 4px 0 var(--px-shadow-deep, #080604);
    box-sizing: border-box;
}

.wiki-detail-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    padding: 0 2px;
}

.wiki-detail-head img,
.wiki-detail-head canvas {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    image-rendering: pixelated;
}

.wiki-detail-title {
    font-size: 16px;
    font-weight: 700;
    color: #f0e6d8;
    margin: 0;
    line-height: 1.35;
}

.wiki-detail-rows {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.wiki-detail-rows .item-detail-row {
    display: grid;
    grid-template-columns: minmax(96px, 1.1fr) minmax(0, 1.4fr);
    gap: 10px 12px;
    align-items: baseline;
    padding: 9px 14px;
    border-bottom: none;
    border-radius: 2px;
    font-size: 13px;
    background: rgba(0, 0, 0, 0.28);
    box-sizing: border-box;
}

.wiki-detail-rows .item-detail-row:nth-child(odd) {
    background: rgba(0, 0, 0, 0.18);
}

.wiki-detail-rows .item-detail-row:last-child {
    border-bottom: none;
}

.wiki-detail-rows dt {
    color: #9a9080;
    margin: 0;
    padding: 0;
    line-height: 1.4;
}

.wiki-detail-rows dd {
    margin: 0;
    padding: 0;
    color: #e8e0d0;
    text-align: right;
    line-height: 1.4;
    word-break: break-word;
}

.wiki-detail-rows .item-detail-row--ability {
    grid-template-columns: auto 1fr;
}

.wiki-detail-rows .item-detail-row--ability dt,
.wiki-detail-rows .item-detail-row--ability dd {
    white-space: nowrap;
}

.wiki-detail-rows .item-detail-row--ability dd {
    word-break: normal;
}

.wiki-detail-rows .item-detail-row--ability dt.item-detail-dt--muted {
    color: transparent;
    user-select: none;
}

.wiki-detail-rows .item-detail-section {
    margin-top: 0;
}

.wiki-detail-rows .item-detail-section dt {
    grid-column: 1 / -1;
    color: var(--px-gold, #ffd54f);
    font-weight: 700;
    padding: 0;
    text-align: center;
    line-height: 1.4;
}

.wiki-detail-rows .item-detail-section dd {
    display: none;
}

.wiki-detail-flavor {
    margin: 12px 0 0;
    padding: 0 14px;
    font-size: 13px;
    font-style: italic;
    color: #8a8070;
    line-height: 1.5;
}

.wiki-detail-close {
    display: block;
    width: 100%;
    margin-top: 14px;
}

.codex-drop-row-icon {
    vertical-align: middle;
    margin-right: 4px;
    image-rendering: pixelated;
}

@media (max-width: 860px) {
    .wiki-menu-toggle {
        display: inline-flex;
    }

    .wiki-menu-toggle-label {
        display: none;
    }

    .wiki-topbar {
        gap: 8px;
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .wiki-brand h1 {
        font-size: 10px;
        margin-bottom: 2px;
    }

    .wiki-brand-tagline {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .wiki-link-game {
        padding: 8px 9px;
        font-size: 12px;
        min-height: 44px;
    }

    .wiki-search {
        padding: 11px 12px;
        font-size: 16px;
    }

    .wiki-shell {
        flex-direction: column;
    }

    .wiki-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(300px, 86vw);
        height: 100%;
        height: 100dvh;
        max-height: 100dvh;
        z-index: 30;
        /* ตอนปิดเท่านั้นที่ใช้ transform — ตอนเปิดเอาออก เพื่อให้เลื่อนได้บนมือถือ */
        transform: translateX(-105%);
        transition: transform 0.22s ease;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
        background: rgba(12, 9, 7, 0.98);
        pointer-events: none;
    }

    .wiki-sidebar.is-open {
        transform: none;
        pointer-events: auto;
    }

    .wiki-sidebar-scroll {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
        padding: 16px 12px;
        padding-top: max(88px, calc(72px + env(safe-area-inset-top)));
        padding-bottom: max(32px, calc(24px + env(safe-area-inset-bottom)));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .wiki-sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 25;
        background: rgba(0, 0, 0, 0.55);
    }

    .wiki-sidebar-backdrop[hidden] {
        display: none !important;
    }

    .wiki-nav-group-title {
        font-size: 11px;
        padding: 10px 12px 6px;
        /* ไม่ใช้ sticky — หัวหมวดหลายอันจะซ้อนกันจนเลื่อนไม่ถึงรายการล่าง */
        position: static;
        background: transparent;
    }

    .wiki-nav-link {
        padding: 12px 14px;
        min-height: 44px;
        font-size: 15px;
        display: flex;
        align-items: center;
        box-sizing: border-box;
        margin-bottom: 4px;
        border-radius: 4px;
    }

    .wiki-main {
        padding: 14px 12px 36px;
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(36px, env(safe-area-inset-bottom));
    }

    .wiki-section h2 {
        font-size: 11px;
        margin-bottom: 12px;
        line-height: 1.8;
    }

    .wiki-section h3 {
        font-size: 15px;
        margin: 18px 0 8px;
    }

    .wiki-lead,
    .wiki-page-lead {
        font-size: 14px;
        line-height: 1.55;
    }

    .wiki-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .wiki-card {
        padding: 12px 8px;
        min-height: 96px;
    }

    .wiki-card-name {
        font-size: 12px;
    }

    /* แท็บเลื่อนแนวนอนบนมือถือ */
    .wiki-tab-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0;
        padding: 6px 6px 0;
        overscroll-behavior-x: contain;
    }

    .wiki-tab-bar::-webkit-scrollbar {
        display: none;
    }

    .wiki-tab-btn {
        flex: 0 0 auto;
        padding: 10px 14px;
        font-size: 13px;
        white-space: nowrap;
        min-height: 40px;
    }

    .wiki-tab-btn.is-active {
        padding-bottom: 12px;
    }

    .wiki-tabbed-table--nested .wiki-tab-btn {
        padding: 8px 12px;
        min-height: 36px;
    }

    /* ตาราง: เลื่อนแนวนอน + คอลัมน์แรกติด */
    .wiki-table-wrap {
        margin: 10px 0 16px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    .wiki-table {
        font-size: 12px;
        min-width: 420px;
    }

    .wiki-table th,
    .wiki-table td {
        padding: 10px 10px;
    }

    .wiki-table th:first-child,
    .wiki-table td:first-child {
        position: sticky;
        left: 0;
        z-index: 1;
        background: rgba(28, 22, 18, 0.98);
        box-shadow: 2px 0 0 rgba(74, 52, 36, 0.45);
    }

    .wiki-table th:first-child {
        background: rgba(46, 36, 28, 0.98);
        z-index: 2;
    }

    .wiki-map-graph {
        flex-direction: column;
        gap: 10px;
        padding: 14px 12px;
    }

    .wiki-map-edge {
        transform: rotate(90deg);
        font-size: 18px;
    }

    .wiki-map-node {
        width: 100%;
        min-height: 48px;
        box-sizing: border-box;
    }

    /* รายละเอียดแบบ bottom sheet */
    .wiki-detail-root {
        align-items: flex-end;
        justify-content: stretch;
        padding: 0;
    }

    .wiki-detail-panel {
        width: 100%;
        max-width: none;
        max-height: min(88dvh, 88vh);
        border-radius: 12px 12px 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 16px 14px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
    }

    .wiki-detail-rows .item-detail-row {
        grid-template-columns: minmax(88px, 0.95fr) minmax(0, 1.35fr);
        padding: 10px 12px;
        font-size: 13px;
        gap: 8px 10px;
    }

    .wiki-detail-close {
        min-height: 48px;
        margin-top: 12px;
        font-size: 15px;
    }

    .wiki-callout {
        padding: 12px;
        font-size: 13px;
    }

    .wiki-math-block {
        padding: 10px;
        margin: 10px 0;
    }

    .wiki-math-block .katex {
        font-size: 0.95em;
    }
}

/* มือถือแนวตั้งแคบ */
@media (max-width: 860px) and (orientation: portrait) {
    .wiki-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .wiki-section ul,
    .wiki-section ol {
        padding-left: 1.1rem;
    }

    .wiki-detail-head {
        gap: 10px;
    }

    .wiki-detail-title {
        font-size: 15px;
    }
}

@media (max-width: 380px) {
    .wiki-brand-tagline {
        display: none;
    }

    .wiki-link-game {
        padding: 8px;
        font-size: 11px;
    }

    .wiki-card-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
}

.wiki-math-block {
    margin: 12px 0;
    padding: 12px 14px;
    overflow-x: auto;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
}

.wiki-math-block .katex {
    font-size: 1.05em;
}
