:root {
    --bg: #171b18;
    --panel: #252a25;
    --panel2: #30362f;
    --line: #4c5548;
    --text: #ece5cc;
    --muted: #bdb69f;
    --accent: #d2b66d;
    --danger: #a94d44;
    --good: #83b36b;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    background: radial-gradient(circle at top, #2d332d 0, var(--bg) 55%);
    color: var(--text);
    font-family: Georgia, 'Times New Roman', serif;
}
button, input { font: inherit; }
button {
    border: 1px solid #6b735f;
    background: linear-gradient(#424a3f, #30362f);
    color: var(--text);
    padding: 7px 11px;
    border-radius: 3px;
    cursor: pointer;
}
button:hover { filter: brightness(1.12); }
button:disabled { opacity: .45; cursor: default; }
button.danger { border-color: #87504b; }
#app { max-width: 1500px; margin: auto; }
.topbar {
    min-height: 70px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(18, 21, 18, .86);
}
h1 { margin: 0; font-size: 26px; color: #e0c680; letter-spacing: .5px; }
.subtitle, .muted { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.status { color: var(--muted); font-size: 12px; min-width: 80px; text-align: right; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 12px; padding: 12px; }
.game-column { min-width: 0; }
.hud, .context-panel, .log-card, .sidebar {
    border: 1px solid var(--line);
    background: rgba(37, 42, 37, .94);
    box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.hud { padding: 9px 12px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.bars { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 13px; }
progress { width: 115px; height: 12px; }
#canvasWrap { position: relative; overflow: hidden; border: 1px solid #606853; border-top: 0; background: #0e1110; }
#gameCanvas { display: block; width: 100%; height: auto; touch-action: none; image-rendering: pixelated; }
#floatingMessage {
    position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
    min-width: 100px; text-align: center; pointer-events: none;
    color: #fff3b5; text-shadow: 1px 1px 3px #000; font-weight: bold; opacity: 0;
}
.controls-note { padding: 7px 10px; font-size: 12px; color: var(--muted); background: #1c211d; border: 1px solid var(--line); border-top:0; }
.context-panel { min-height: 62px; margin-top: 10px; padding: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#contextActions { display:flex; gap:6px; flex-wrap:wrap; justify-content:flex-end; }
.log-card { margin-top: 10px; padding: 10px; }
.section-title { color: var(--accent); font-weight: bold; margin-bottom: 8px; }
#journal { height: 105px; overflow-y: auto; font-size: 12px; line-height: 1.5; }
.journal-line { border-bottom: 1px dotted #42483f; padding: 2px 0; }
.sidebar { min-height: 700px; padding: 10px; }
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-bottom: 12px; }
.tab { padding: 6px 3px; font-size: 12px; }
.tab.active { color: #171b18; background: #d1bb7d; border-color:#ead99f; }
.tab-pane { display:none; }
.tab-pane.active { display:block; }
.item-row, .skill-row, .recipe-row, .equip-row {
    border-bottom: 1px solid #42483f;
    padding: 7px 4px;
}
.item-row, .equip-row { display:flex; justify-content:space-between; gap:8px; align-items:center; }
.item-actions { display:flex; gap:4px; }
.item-actions button { font-size: 11px; padding: 3px 6px; }
.skill-header { display:flex; justify-content:space-between; gap:8px; align-items:center; }
.skill-controls { display:flex; align-items:center; gap:5px; }
.skill-lock, .skill-use { font-size:11px; padding:2px 6px; min-width:27px; }
.skill-lock.up { color:#b8d9a8; }
.skill-lock.locked { color:#d7d0b7; }
.skill-lock.down { color:#e2a29b; }
.skill-track { height: 6px; margin-top: 5px; background:#161916; border:1px solid #4c5548; }
.skill-fill { height:100%; background:#b59a59; }
.recipe-row { display:grid; grid-template-columns: 1fr auto; gap:8px; }
.recipe-row small { display:block; color:var(--muted); margin-top:3px; }
.quality { color:#9cc687; }
.rare { color:#90b8df; }
.legendary { color:#d9a95c; }

@media (min-width: 901px) {
    .topbar { min-height: 60px; padding-top: 9px; padding-bottom: 9px; }
    .layout { padding-top: 9px; }
    .hud { padding-top: 7px; padding-bottom: 7px; }
    .context-panel { margin-top: 8px; min-height: 56px; padding: 8px 10px; }
}

@media (max-width: 900px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { min-height: auto; }
    .topbar { align-items:flex-start; }
    .status { display:none; }
}


.mobile-only { display: none; }
.mobile-quickbar {
    display: none;
    gap: 8px;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    background: rgba(37, 42, 37, .96);
    box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.mobile-quickbar button {
    flex: 1 1 auto;
    min-width: 0;
    padding: 9px 8px;
    font-size: 13px;
}
.sidebar-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}
.sidebar-close {
    font-size: 24px;
    line-height: 1;
    padding: 2px 10px 6px;
}
.sidebar-backdrop {
    display: none;
}

@media (max-width: 900px) {
    body { padding-bottom: calc(env(safe-area-inset-bottom) + 8px); }
    .mobile-only { display: block; }
    .mobile-quickbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .55);
        opacity: 0;
        pointer-events: none;
        transition: opacity .18s ease;
        z-index: 18;
    }
    .sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: min(92vw, 430px);
        max-width: 430px;
        min-height: auto;
        overflow-y: auto;
        z-index: 19;
        transform: translateX(104%);
        transition: transform .18s ease;
        padding-top: calc(10px + env(safe-area-inset-top));
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .sidebar-backdrop.mobile-open {
        opacity: 1;
        pointer-events: auto;
    }
    .tabs {
        position: sticky;
        top: 0;
        background: rgba(37,42,37,.98);
        padding-top: 8px;
        z-index: 1;
    }
}


.journal-toggle {
    position: absolute;
    left: 10px;
    top: 10px;
    z-index: 6;
    padding: 6px 10px;
    background: rgba(28, 31, 27, .88);
    border-color: #9d8755;
    box-shadow: 0 3px 10px rgba(0,0,0,.28);
}
.journal-overlay {
    position: absolute;
    left: 10px;
    top: 48px;
    width: min(330px, 38%);
    height: 67%;
    z-index: 5;
    display: none;
    flex-direction: column;
    border: 1px solid #7b704f;
    background: rgba(28, 31, 27, .93);
    box-shadow: 0 8px 24px rgba(0,0,0,.42);
    backdrop-filter: blur(2px);
}
.journal-overlay.open { display: flex; }
.journal-overlay-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 9px;
    color: var(--accent);
    border-bottom: 1px solid #5a543f;
    background: rgba(48, 46, 37, .96);
}
.journal-close { padding: 0 7px 3px; font-size: 20px; line-height: 1; }
.journal-overlay-body {
    overflow-y: auto;
    padding: 7px 9px;
    font-size: 12px;
    line-height: 1.45;
}
.gear-detail {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}
.bank-count { color: var(--muted); font-size: 12px; }
.open-all-row {
    display: flex;
    justify-content: flex-end;
    padding: 4px 0 8px;
    border-bottom: 1px solid #42483f;
}
.bank-locked {
    border: 1px dashed #5b624f;
    padding: 10px;
    color: var(--muted);
    font-size: 12px;
}
.mobile-journal { display: none; }

@media (max-width: 900px) {
    .journal-toggle, .journal-overlay { display: none !important; }
    .mobile-journal { display: block; }
    .tabs { grid-template-columns: repeat(5, 1fr); }
    .tab { font-size: 11px; }
}

/* V1.10 crafting readability */
.craft-summary-wrap {
    border: 1px solid #5a604f;
    background: rgba(25, 29, 25, .8);
    padding: 8px;
    margin-bottom: 10px;
}
.craft-summary-title {
    color: var(--accent);
    font-weight: bold;
    font-size: 12px;
    margin-bottom: 6px;
}
.craft-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.craft-chip {
    display: inline-block;
    border: 1px solid #4d5548;
    background: #20251f;
    padding: 4px 6px;
    font-size: 11px;
    color: var(--muted);
}
.craft-chip b { color: var(--text); }
.recipe-group-title {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin: 13px 0 4px;
    padding: 6px 4px;
    color: var(--accent);
    border-bottom: 1px solid #67604a;
}
.recipe-group-title span {
    color: var(--muted);
    font-size: 11px;
    text-align: right;
}
.recipe-row small { line-height: 1.35; }
.recipe-row button { min-width: 72px; align-self: center; }

@media (max-width: 900px) {
    .craft-summary { gap: 4px; }
    .craft-chip { font-size: 10px; }
    .recipe-row { grid-template-columns: minmax(0, 1fr) auto; }
    .recipe-row button { min-width: 64px; padding-left: 6px; padding-right: 6px; }
}
