/* ==========================================================================
   Knave Character Sheet — Fantasy UI
   Inspired by Knave 2e official sheet + Infinity Engine games
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 17px; -webkit-font-smoothing: antialiased; }

body {
    font-family: 'Crimson Text', serif;
    color: #d4c4a0;
    min-height: 100vh;
    background-color: #0d0d1a;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(40,40,70,0.5) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(30,30,55,0.4) 0%, transparent 40%),
        radial-gradient(ellipse at 50% 80%, rgba(50,45,60,0.3) 0%, transparent 45%);
    background-attachment: fixed;
}

/* ==========================================================================
   Home Page
   ========================================================================== */

.page-container { max-width: 1020px; margin: 0 auto; min-height: 100vh; }

.home-content {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 100vh; text-align: center; padding: 2rem;
}

.game-title {
    font-family: 'Cinzel', serif; font-size: 4rem; font-weight: 700;
    letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 0.5rem;
    background: linear-gradient(180deg, #e0c570 0%, #c9a959 40%, #b8942e 100%);
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 6px rgba(0,0,0,0.8));
}
.subtitle {
    font-style: italic; font-size: 1.3rem; color: #a89870;
    letter-spacing: 0.08em; margin-bottom: 2.5rem;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn, .btn-create {
    font-family: 'Cinzel', serif; font-weight: 700; color: #2c1810;
    padding: 0.45rem 1.1rem; border: 2px solid #c9a959; border-radius: 2px;
    cursor: pointer; transition: all 0.2s; text-transform: uppercase;
    letter-spacing: 0.06em; font-size: 0.8rem;
    background: linear-gradient(180deg, #d4b896 0%, #c4a882 40%, #b89c74 100%);
    text-shadow: 0 1px 0 rgba(255,255,255,0.25);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn:hover, .btn-create:hover {
    background: linear-gradient(180deg, #e0c8a4 0%, #d4b896 40%, #c4a882 100%);
    border-color: #e0c570; transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.4), 0 0 10px rgba(201,169,89,0.15);
}
.btn:active, .btn-create:active {
    transform: translateY(0);
    background: linear-gradient(180deg, #b89c74 0%, #c4a882 60%, #d4b896 100%);
}
.btn-create { font-size: 1rem; padding: 0.8rem 2rem; }

/* ==========================================================================
   Character Sheet Panel
   ========================================================================== */

.character-sheet {
    background:
        linear-gradient(rgba(180,150,100,0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(180,150,100,0.025) 1px, transparent 1px),
        linear-gradient(160deg, #d9bc98 0%, #c8ac82 40%, #d2b690 70%, #cdb08a 100%);
    background-size: 22px 22px, 22px 22px, 100% 100%;
    color: #2c1810;
    border: 3px solid #c9a959;
    border-radius: 2px;
    padding: 1rem 1.2rem;
    margin: 0.8rem auto;
    position: relative;
    box-shadow:
        0 0 0 1px #b8942e, 0 0 0 4px rgba(13,13,26,0.7),
        0 0 0 5px #7a6020, 0 10px 35px rgba(0,0,0,0.7),
        inset 0 0 50px rgba(160,130,80,0.08);
}

/* Gold corner accents */
.character-sheet::before, .character-sheet::after {
    content: ''; position: absolute; width: 22px; height: 22px;
    border-color: #c9a959; border-style: solid; pointer-events: none;
}
.character-sheet::before { top: 5px; left: 5px; border-width: 2px 0 0 2px; }
.character-sheet::after  { top: 5px; right: 5px; border-width: 2px 2px 0 0; }

/* ==========================================================================
   Dark Banner — shared style for ability labels, section headers
   ========================================================================== */

/* Mixin-like class: dark ink banner with gold text */
.banner-label {
    display: inline-block;
    background: linear-gradient(180deg, #2a1e0e 0%, #1a1208 100%);
    color: #c9a959;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.18rem 0.55rem;
    border-radius: 1px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
    box-shadow: 0 1px 3px rgba(0,0,0,0.4), inset 0 1px 0 rgba(201,169,89,0.15);
    white-space: nowrap;
}

/* Section titles use the banner style */
.section-title {
    font-family: 'Cinzel', serif; font-size: 0.75rem; font-weight: 700;
    color: #c9a959; text-transform: uppercase; letter-spacing: 0.12em;
    margin-bottom: 0.5rem; padding: 0.2rem 0.6rem;
    background: linear-gradient(180deg, #2a1e0e 0%, #1a1208 100%);
    display: inline-block; border-radius: 1px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5), inset 0 1px 0 rgba(201,169,89,0.1);
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* ==========================================================================
   Inputs
   ========================================================================== */

.field-input {
    font-family: 'Crimson Text', serif; font-size: 0.95rem; color: #2c1810;
    background: rgba(232,213,181,0.85); border: 1px solid #a08060;
    border-radius: 1px; padding: 0.2rem 0.4rem;
    transition: border-color 0.15s, box-shadow 0.15s; outline: none;
}
.field-input:focus {
    border-color: #c9a959; box-shadow: 0 0 5px rgba(201,169,89,0.5);
    background: rgba(240,224,196,0.95);
}
.field-input::placeholder { color: #9a8060; font-style: italic; }

.field-name {
    font-family: 'Cinzel', serif; font-size: 1.25rem; font-weight: 700;
    padding: 0.2rem 0.5rem; flex: 1; min-width: 140px;
    background: rgba(232,213,181,0.85); border: 1px solid #a08060;
    border-radius: 1px; color: #2c1810; outline: none; transition: all 0.15s;
}
.field-name:focus { border-color: #c9a959; box-shadow: 0 0 6px rgba(201,169,89,0.5); }
.field-name::placeholder { color: #9a8060; font-style: italic; font-family: 'Crimson Text', serif; font-weight: 400; }

.field-stat {
    font-size: 1rem; font-weight: 600; width: 50px; text-align: center;
    padding: 0.18rem 0.25rem;
}

/* ==========================================================================
   Header: Name, Level, XP
   ========================================================================== */

.section-header {
    display: flex; align-items: center; gap: 0.8rem;
    margin-bottom: 0.75rem; padding-bottom: 0.6rem;
    border-bottom: 1px solid rgba(201,169,89,0.25);
}
.field-label {
    font-family: 'Cinzel', serif; font-size: 0.7rem; font-weight: 700;
    color: #6a4a2a; text-transform: uppercase; letter-spacing: 0.06em;
    display: flex; align-items: center; gap: 0.3rem; white-space: nowrap;
}
.header-stats { display: flex; gap: 0.7rem; margin-left: auto; }

/* ==========================================================================
   Middle Row: Abilities + Combat (left) | Portrait + Careers (right)
   ========================================================================== */

.middle-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 1rem;
    margin-bottom: 0.75rem;
    align-items: start;
}

/* Left column: abilities + combat stacked */
.left-col {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 220px;
}

/* Abilities list — each row: dark label banner + input */
.section-abilities { }

.abilities-list {
    display: flex; flex-direction: column; gap: 2px;
}

.ability-row {
    display: flex; align-items: center; gap: 0;
}

.ability-label {
    /* Dark ink banner label — the signature Knave look */
    background: linear-gradient(180deg, #2a1e0e 0%, #1a1208 100%);
    color: #c9a959;
    font-family: 'Cinzel', serif;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 0.22rem 0.55rem;
    width: 60px;
    text-align: right;
    flex-shrink: 0;
    border-radius: 1px 0 0 1px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
    box-shadow: 1px 0 0 rgba(201,169,89,0.2), 0 1px 3px rgba(0,0,0,0.3);
    line-height: 1.6;
}

.ability-row .field-input {
    border-radius: 0 1px 1px 0;
    border-left: none;
    width: 50px;
    text-align: center;
}

/* Combat inline with abilities */
.section-combat { }

.combat-row {
    display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.hp-group {
    display: flex; align-items: center; gap: 0.25rem;
}
.hp-label {
    background: linear-gradient(180deg, #2a1e0e 0%, #1a1208 100%);
    color: #c9a959; font-family: 'Cinzel', serif;
    font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.1em; padding: 0.22rem 0.45rem; border-radius: 1px 0 0 1px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
    box-shadow: 1px 0 0 rgba(201,169,89,0.2), 0 1px 3px rgba(0,0,0,0.3);
    line-height: 1.6;
}
.hp-group .field-input:first-of-type { border-radius: 0; border-left: none; width: 46px; text-align: center; }
.hp-group .field-input:last-of-type  { border-radius: 0 1px 1px 0; width: 46px; text-align: center; }
.hp-sep { color: #6a4a2a; font-weight: 700; font-size: 0.9rem; padding: 0 0.1rem; }

.hp-bar-wrapper {
    flex: 1; min-width: 80px;
    position: relative;
    cursor: help;
}
.hp-bar-wrapper[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
    padding: 5px 8px;
    background: #1a1410;
    color: #c9a959;
    border: 1px solid #5a4828;
    border-radius: 3px;
    font-size: 0.72rem;
    font-family: var(--font-ui);
    line-height: 1.4;
    text-transform: none;
    letter-spacing: 0;
    pointer-events: none;
    white-space: nowrap;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.hp-bar-wrapper:hover::after { opacity: 1; }

.hp-bar-container {
    width: 100%; height: 14px;
    background: #2a1a0e; border: 1px solid #5a4020;
    border-radius: 1px; overflow: hidden;
    box-shadow: inset 0 2px 3px rgba(0,0,0,0.5);
}
.hp-bar {
    height: 100%;
    background: linear-gradient(180deg, #3db55e 0%, #267a3e 100%);
    transition: width 0.35s ease, background 0.35s ease;
    box-shadow: inset 0 1px 0 rgba(120,255,160,0.25);
}
.hp-bar.hp-bar-over {
    background: linear-gradient(180deg, #4a9edd 0%, #2868a8 100%);
    box-shadow: inset 0 1px 0 rgba(120,200,255,0.25);
}

/* Middle column: Portrait only */
.portrait-careers-col,
.portrait-col {
    display: flex; flex-direction: column; gap: 0.7rem; flex-shrink: 0; width: 200px;
}

/* ==========================================================================
   Portrait
   ========================================================================== */

.portrait-frame {
    width: 200px; height: 210px;
    border: 3px solid #c9a959; border-radius: 1px;
    overflow: hidden; position: relative; background: #120e0a;
    box-shadow: 0 0 0 2px #b8942e, inset 0 0 15px rgba(0,0,0,0.7), 0 4px 12px rgba(0,0,0,0.6);
}
.portrait-frame::before, .portrait-frame::after {
    content: ''; position: absolute; z-index: 2; pointer-events: none;
}
.portrait-frame::before {
    top: -1px; left: -1px; width: 14px; height: 14px;
    border-top: 3px solid #e0c570; border-left: 3px solid #e0c570;
}
.portrait-frame::after {
    bottom: -1px; right: -1px; width: 14px; height: 14px;
    border-bottom: 3px solid #e0c570; border-right: 3px solid #e0c570;
}
.portrait-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.portrait-placeholder {
    width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
    color: #4a3a28; font-style: italic; font-size: 0.85rem;
}
.portrait-form {
    margin-top: 0.35rem; display: flex; flex-direction: column; gap: 0.25rem;
}
.portrait-form .field-input { font-size: 0.78rem; padding: 0.18rem 0.3rem; width: 100%; }
.portrait-form .btn { font-size: 0.7rem; padding: 0.22rem 0.6rem; }

/* ==========================================================================
   Inventory — two columns, numbered slots 1-10 | 11-20
   ========================================================================== */

.section-inventory { margin-bottom: 0.7rem; margin-top: 0.7rem; }

.inventory-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
}

.inventory-slot {
    display: block;
    padding: 0.15rem 0.3rem;
    background: rgba(220,196,160,0.5);
    border: 1px solid rgba(160,128,90,0.45);
    border-radius: 1px;
    transition: background 0.12s;
}
.inventory-slot:hover { background: rgba(230,208,172,0.7); }

.inventory-slot-row {
    display: flex; align-items: center; gap: 0.3rem;
    min-height: 26px;
}

.inventory-slot-extra {
    display: none;
    align-items: center; gap: 0.5rem;
    padding: 0.2rem 0 0.1rem 20px;
    flex-wrap: wrap;
}
.inventory-slot.expanded .inventory-slot-extra { display: flex; }

.extra-label {
    display: flex; align-items: center; gap: 0.25rem;
    font-family: 'Cinzel', serif; font-size: 0.6rem; font-weight: 700;
    color: #8a6a40; text-transform: uppercase; letter-spacing: 0.05em;
    white-space: nowrap;
}
.extra-desc-label { flex: 1; }
.extra-kind-select {
    font-size: 0.72rem; padding: 0.1rem 0.2rem;
    background: rgba(232,213,181,0.55); border: 1px solid rgba(150,118,80,0.4);
    border-radius: 1px; color: #2c1810;
}
.extra-kind-locked {
    font-size: 0.72rem; color: #6a5a40; font-style: italic;
}
.extra-desc-input {
    font-size: 0.78rem; padding: 0.1rem 0.25rem; min-width: 0; width: 100%;
    background: rgba(232,213,181,0.55); border: 1px solid rgba(150,118,80,0.4);
    border-radius: 1px;
}

.slot-toggle {
    background: none; border: none; cursor: pointer; padding: 0;
}
.slot-number {
    font-family: 'Cinzel', serif; font-size: 0.62rem; font-weight: 700;
    color: #8a6a40; width: 16px; text-align: right; flex-shrink: 0;
    line-height: 1;
}
.slot-toggle:hover .slot-number,
.slot-toggle:focus .slot-number { color: #c9a959; outline: none; }
.inventory-slot.expanded .slot-toggle .slot-number { color: #c9a959; }


.field-item-name {
    flex: 1; font-size: 0.82rem; padding: 0.12rem 0.28rem; min-width: 0;
    background: rgba(232,213,181,0.55); border: 1px solid rgba(150,118,80,0.4);
    border-radius: 1px;
}
.field-item-slots {
    width: 42px; font-size: 0.88rem; text-align: center; flex-shrink: 0;
    padding: 0.12rem 0.2rem;
    background: rgba(232,213,181,0.55); border: 1px solid rgba(150,118,80,0.4);
    border-radius: 1px;
}

/* ==========================================================================
   Change Log
   ========================================================================== */

.section-changelog {
    margin-top: 0.7rem; padding-top: 0.6rem;
    border-top: 1px solid rgba(201,169,89,0.2);
}

.change-log {
    max-height: 160px; overflow-y: auto;
    display: flex; flex-direction: column-reverse; /* newest at top */
    gap: 1px;
    /* Fade at bottom */
    mask-image: linear-gradient(to top, transparent 0%, black 12%);
    -webkit-mask-image: linear-gradient(to top, transparent 0%, black 12%);
}

.log-entry {
    display: flex; align-items: baseline; gap: 0.55rem;
    padding: 0.18rem 0.4rem;
    border-left: 2px solid rgba(201,169,89,0.4);
    background: rgba(0,0,0,0.03);
    border-radius: 0 1px 1px 0;
    animation: log-appear 0.25s ease-out;
}
.log-entry:hover { background: rgba(0,0,0,0.07); }

.log-time {
    font-family: 'Cinzel', serif; font-size: 0.62rem; font-weight: 700;
    color: #9a7a50; letter-spacing: 0.04em; flex-shrink: 0;
}
.log-message {
    font-family: 'Crimson Text', serif; font-size: 0.88rem;
    color: #3a2818; font-style: italic;
}

@keyframes log-appear {
    from { opacity: 0; transform: translateX(-5px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ==========================================================================
   Save Animation
   ========================================================================== */

.saved { animation: save-glow 0.5s ease-out; }
@keyframes save-glow {
    0%   { box-shadow: 0 0 7px #c9a959; }
    100% { box-shadow: none; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 680px) {
    .character-sheet { padding: 0.7rem; }
    .middle-row { grid-template-columns: 1fr; }
    .left-col { min-width: 0; }
    .portrait-careers-col, .portrait-col { width: 100%; flex-direction: row; gap: 0.8rem; }
    .section-background { grid-column: 1 / -1; }
    .portrait-frame { width: 130px; height: 140px; }
    .section-header { flex-direction: column; align-items: flex-start; }
    .header-stats { margin-left: 0; }
}

@media (max-width: 460px) {
    .inventory-grid { grid-template-columns: 1fr; }
    .portrait-careers-col, .portrait-col { flex-direction: column; }
    .portrait-frame { width: 100%; height: 180px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 7px; }
::-webkit-scrollbar-track { background: #1a1a2e; }
::-webkit-scrollbar-thumb { background: #4a3a2a; border: 1px solid #5a4828; border-radius: 1px; }

::selection { background: rgba(201,169,89,0.3); color: #2c1810; }

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 0.35; }
input[type="number"]:hover::-webkit-inner-spin-button,
input[type="number"]:hover::-webkit-outer-spin-button { opacity: 1; }

.btn-generate { display: inline-block; margin-top: 0.75rem; text-decoration: none; }
.btn-save { float: right; margin-bottom: 1rem; }

.item-kind {
    display: inline-block;
    font-size: 0.6rem;
    font-family: var(--font-ui);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1px 4px;
    border-radius: 2px;
    border: 1px solid currentColor;
    opacity: 0.75;
    margin-right: 3px;
    vertical-align: middle;
    pointer-events: none;
}
.kind-weapon  { color: #c46e6e; }
.kind-armor   { color: #9aabb4; }
.kind-spell   { color: #7ea8c4; }
.kind-other   { color: #8a9aaa; }

/* Spell description tooltip */
.item-kind[data-tooltip] {
    cursor: help;
    /* override the pointer-events:none from .item-kind so hover fires */
    pointer-events: auto;
    position: relative;
}
/* hovered slot must be on top so the tooltip isn't painted over by sibling cells */
.inventory-slot:has([data-tooltip]:hover) {
    position: relative;
    z-index: 10;
}
.item-kind[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    width: 240px;
    padding: 6px 8px;
    background: #1a1410;
    color: #c9a959;
    border: 1px solid #5a4828;
    border-radius: 3px;
    font-size: 0.72rem;
    font-family: var(--font-ui);
    line-height: 1.4;
    text-transform: none;
    letter-spacing: 0;
    pointer-events: none;
    white-space: normal;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.15s ease;
}
.item-kind[data-tooltip]:hover::after {
    opacity: 1;
}

/* ==========================================================================
   Custom number spinners
   ========================================================================== */

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { display: none; }

.num-wrap { display: inline-flex; align-items: stretch; }
.num-btns { display: flex; flex-direction: column; margin-left: 2px; }
.num-btn {
    display: flex; align-items: center; justify-content: center;
    width: 18px; flex: 1; padding: 0;
    background: rgba(201,169,89,0.12);
    border: 1px solid rgba(201,169,89,0.32);
    color: #b8922a; cursor: pointer;
    transition: background 0.1s, color 0.1s;
}
.num-btn:hover { background: rgba(201,169,89,0.38); color: #e0c060; }
.num-btn:active { background: rgba(201,169,89,0.6); }
.num-up { border-radius: 0 3px 0 0; border-bottom-width: 0; }
.num-dn { border-radius: 0 0 3px 0; }

/* ==========================================================================
   Background / additional info
   ========================================================================== */

.section-background { margin-bottom: 0.7rem; }

.background-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.25rem;
}

.bg-field { display: flex; align-items: center; gap: 0.5rem; }
.bg-label {
    font-family: 'Cinzel', serif; font-size: 0.68rem; font-weight: 700;
    color: #9a7a50; text-transform: uppercase; letter-spacing: 0.05em;
    white-space: nowrap; flex-shrink: 0; min-width: 68px;
}
.bg-input { flex: 1; font-size: 0.88rem; padding: 0.14rem 0.3rem; }
.bg-value { font-size: 0.88rem; color: #3a2010; font-style: italic; }
