/* Base: copied from template/styles.css with minor Minecraft accents */
:root {
    --md-sys-color-primary: #4e8c31; /* Slightly darker/softer green */
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-surface: #f5f0e6; /* Softer parchment-like color */
    --md-sys-color-on-surface: #4a3a2e; /* Softer dark brown */
    --md-sys-color-surface-variant: #e8dfd1; /* Softer variant */
    --md-sys-color-outline: #9e8a73; /* Muted brownish outline */
    --md-sys-color-inverse-surface: #4a3a2e;
    --md-sys-color-inverse-on-surface: #f5f0e6;
    --radius-s: 2px; /* Very slight rounding for softness */
    --radius-m: 4px;
    --mc-border: 3px solid #4a3a2e; /* Thinner and softer border */
    --mc-panel: #c6c6c6;
    --mc-panel-shadow: #777777; /* Softer shadow */
    --mc-panel-light: #ffffff;
    --elev-1: 2px 2px 0 rgba(74, 58, 46, 0.15); /* Softer pixel shadow */
    --elev-2: 4px 4px 0 rgba(74, 58, 46, 0.15);
}

@media (prefers-color-scheme: dark) {
    :root {
        --md-sys-color-primary: #6abf4a; /* Brighter green for dark mode readability */
        --md-sys-color-on-primary: #1e1e1e;
        --md-sys-color-surface: #252423; /* Warm dark gray, less harsh than pure #1e1e1e */
        --md-sys-color-on-surface: #d6cfc7; /* Softer light gray/parchment */
        --md-sys-color-surface-variant: #3a3836;
        --md-sys-color-outline: #8b7d70;
        --md-sys-color-inverse-surface: #f5f0e6;
        --md-sys-color-inverse-on-surface: #4a3a2e;
    }
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: "Roboto", "Noto Sans JP", system-ui, -apple-system, sans-serif;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    image-rendering: pixelated;
}

h1, h2, h3, h4, .mc-font {
    font-family: "Roboto", "Noto Sans JP", system-ui, -apple-system, sans-serif;
}

.material-icons-outlined {
    font-variation-settings: 'OPSZ' 24;
}

.elevation-1 {
    box-shadow: var(--elev-1);
}

.elevation-2 {
    box-shadow: var(--elev-2);
}

/* App Bar */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--md-sys-color-surface);
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.brand-icon {
    color: var(--md-sys-color-primary);
}

.spacer {
    flex: 1;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-surface);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-grid;
    place-items: center;
}

.icon-btn:hover {
    background: color-mix(in oklab, var(--md-sys-color-primary) 12%, transparent);
}

.icon-btn:active {
    background: color-mix(in oklab, var(--md-sys-color-primary) 18%, transparent);
}

/* Navigation Drawer */
.nav-drawer {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--md-sys-color-surface);
    border-right: var(--mc-border);
    transform: translateX(0);
    transition: transform .2s ease;
}

.nav-drawer .drawer-header {
    padding: 12px 16px;
    font-weight: 600;
}

.drawer-nav {
    display: flex;
    flex-direction: column;
    padding: 4px;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-s);
    border: none;
    cursor: pointer;
    background: transparent;
    color: inherit;
    text-align: left;
}

.nav-item:hover {
    background: color-mix(in oklab, var(--md-sys-color-primary) 10%, transparent);
}

.nav-item.active {
    background: var(--mc-panel);
    border-top: 2px solid var(--mc-panel-shadow);
    border-left: 2px solid var(--mc-panel-shadow);
    border-bottom: 2px solid var(--mc-panel-light);
    border-right: 2px solid var(--mc-panel-light);
}

/* Layout */
.content {
    margin-left: 280px;
    padding: 16px;
    max-width: 1200px;
}

@media (max-width: 920px) {
    .nav-drawer {
        transform: translateX(-100%);
        top: 56px;
    }

    .nav-drawer.open {
        transform: translateX(0);
    }

    .content {
        margin-left: 0;
        padding: 16px;
    }
}

/* Search */
.search-section {
    display: grid;
    gap: 12px;
}

.search-field {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 28px;
    background: var(--md-sys-color-inverse-on-surface);
    color: var(--md-sys-color-on-surface);
}

.search-field input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    color: inherit;
    padding: 8px;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--mc-panel);
    border-top: 2px solid var(--mc-panel-light);
    border-left: 2px solid var(--mc-panel-light);
    border-bottom: 2px solid var(--mc-panel-shadow);
    border-right: 2px solid var(--mc-panel-shadow);
    font-size: 12px;
    color: #3d2b1f;
    text-decoration: none;
    border-radius: var(--radius-s);
}

.chip[href]:hover {
    background: #d6d6d6;
}

.chip[href]:active {
    border-top: 2px solid var(--mc-panel-shadow);
    border-left: 2px solid var(--mc-panel-shadow);
    border-bottom: 2px solid var(--mc-panel-light);
    border-right: 2px solid var(--mc-panel-light);
}

.chip button {
    border: none;
    background: transparent;
    cursor: pointer;
    display: inline-grid;
    place-items: center;
}

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    color: var(--md-sys-color-outline);
}

.breadcrumbs a {
    color: inherit;
    text-decoration: none;
}

.breadcrumbs .sep {
    opacity: .6;
}

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
    align-items: stretch;
}

@media (max-width: 599px) {
    .cards {
        grid-template-columns: repeat(1, 1fr);
    }
}

@media (min-width: 600px) and (max-width: 1023px) {
    .cards {
        grid-template-columns: repeat(6, 1fr);
    }
}

@media (min-width: 1024px) {
    .cards {
        grid-template-columns: repeat(12, 1fr);
    }
}

.kb-card {
    grid-column: span 12;
    background: var(--md-sys-color-inverse-on-surface);
    border: var(--mc-border);
    padding: 16px;
    display: grid;
    gap: 8px;
    position: relative;
    border-radius: var(--radius-s);
}

.kb-card::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

@media (min-width: 600px) {
    .kb-card {
        grid-column: span 3;
    }
}

@media (min-width: 1024px) {
    .kb-card {
        grid-column: span 3;
    }
}

.kb-card header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.kb-card h3 {
    margin: 0;
    font-size: 1.05rem;
}

.kb-card p {
    margin: 0;
    color: var(--md-sys-color-on-surface);
    opacity: .9;
}

.kb-card footer {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Empty state */
.empty-state {
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 24px;
    color: var(--md-sys-color-outline);
}

/* Footer */
.app-footer {
    margin-top: 24px;
    padding: 16px;
    border-top: 1px solid var(--md-sys-color-surface-variant);
}

.app-footer .container {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
}

.app-footer .link {
    color: var(--md-sys-color-primary);
    text-decoration: none;
}

/* Focus styles */
:focus-visible {
    outline: 2px solid var(--md-sys-color-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Ensure [hidden] hides elements */
[hidden] {
    display: none !important;
}

/* Explicit light/dark override when set by JS */
[data-theme="dark"] {
    --md-sys-color-primary: #6abf4a;
    --md-sys-color-on-primary: #1e1e1e;
    --md-sys-color-surface: #252423;
    --md-sys-color-on-surface: #d6cfc7;
    --md-sys-color-surface-variant: #3a3836;
    --md-sys-color-outline: #8b7d70;
    --md-sys-color-inverse-surface: #f5f0e6;
    --md-sys-color-inverse-on-surface: #4a3a2e;
}

[data-theme="light"] {
    --md-sys-color-primary: #4e8c31;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-surface: #f5f0e6;
    --md-sys-color-on-surface: #4a3a2e;
    --md-sys-color-surface-variant: #e8dfd1;
    --md-sys-color-outline: #9e8a73;
    --md-sys-color-inverse-surface: #4a3a2e;
    --md-sys-color-inverse-on-surface: #f5f0e6;
}


/* Crafting grid (3x3) */
.craft-grid {
    --cell: 48px;
    display: grid;
    grid-template-columns: repeat(3, var(--cell));
    gap: 4px;
    padding: 4px;
    border: 2px solid #373737;
    background: #8b8b8b;
    width: max-content;
    image-rendering: pixelated;
}

.craft-cell {
    width: var(--cell);
    height: var(--cell);
    display: grid;
    place-items: center;
    background: #8b8b8b;
    border-top: 2px solid var(--mc-panel-shadow);
    border-left: 2px solid var(--mc-panel-shadow);
    border-bottom: 2px solid var(--mc-panel-light);
    border-right: 2px solid var(--mc-panel-light);
    color: #3d2b1f;
    font-size: 11px;
    font-weight: bold;
    text-align: center;
    padding: 2px;
    box-sizing: border-box;
}

.craft-cell:empty {
    background: #8b8b8b;
}

.craft-legend {
    margin-top: 8px;
    font-size: 12px;
    color: var(--md-sys-color-outline);
}

@media (max-width: 480px) {
    .craft-grid {
        --cell: 36px;
        gap: 4px;
        padding: 8px;
    }
}
