@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&display=swap');

/* Basic resets */
body {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    background: #f7f7f7;
}

/* Ensure all elements use border-box sizing */
* {
    box-sizing: border-box;
}

/* Title Bar */
.title-bar {
    background-color: #333;
    color: white;
    text-align: center;
    padding: 20px;
    margin: 0;
    font-family: 'Cinzel', serif;
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 0.1em;
}

/* Controls styling */
.controls {
    text-align: center;
    margin: 20px;
}
.controls button {
    margin: 0 10px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
}
.controls label {
    margin: 0 10px;
    cursor: pointer;
}

/* Main container for the character sheet */
.character-sheet {
    /* Compact, high-contrast layout inspired by the reference */
    width: 100%;
    max-width: 880px;
    margin: 12px auto;
    padding: 12px;
    background: #fff;
    border: 6px solid #000;
    box-shadow: none;
    display: grid;
    grid-template-columns: 120px 1fr;
    grid-gap: 12px;
}

/* Character Number Box */
.character-number-box {
    grid-column: 1;
    /* Make the number box span the full height of the sheet so all boxes are identical size */
    grid-row: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 2px solid #333;
    /* restore original box sizing; the large number will be an independent element */
    padding: 10px;
    position: relative;
    overflow: hidden; /* ensure the display stays visually inside the box */
    justify-content: center;
}
.character-number-box input {
    /* keep the input for semantics but visually hide it; the visual number is rendered separately */
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    font-weight: 900;
    border: none;
    background-color: transparent;
    line-height: 1;
    height: auto;
    padding: 0;
    margin: 0;
}

/* Independent visual number inside the box */
.character-number-display {
    --character-number-size: 16rem; /* define once so it's easy to change */
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) scale(1);
    display: inline-block;
    align-items: center;
    justify-content: center;
    width: auto; /* allow it to size to content so JS can measure natural size */
    height: auto;
    font-size: var(--character-number-size);
    font-weight: 900;
    font-family: 'Cinzel', serif;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    text-align: center;
    white-space: nowrap;
}

/* Small screens: scale the visual number down so it doesn't overflow the page */
@media (max-width: 480px) {
    .character-number-display {
        font-size: calc(var(--character-number-size) / 4);
    }
}

/* Top Row Fields */
.top-row {
    grid-column: 2;
    display: grid;
    grid-template-rows: auto auto;
    grid-gap: 10px;
}
.top-row .first-row,
.top-row .second-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-gap: 10px;
}
.top-row .field {
    display: flex;
    flex-direction: column;
}
.top-row label {
    font-weight: 900;
    font-size: 0.85em;
    letter-spacing: 0.06em;
}
.top-row input {
    padding: 4px;
    width: 100%;
    border-bottom: 2px solid #000;
    background: transparent;
    font-weight: 700;
}

/* Add borders to alignment, lineage, and past life fields */
.alignment-box,
.lineage-box,
.past-life-box,
.name-box {
    border: 2px solid #000;
    padding: 8px;
}

.alignment-box input,
.lineage-box input,
.past-life-box input,
.name-box input {
    border: none !important;
    background: transparent;
    font-size: inherit;
    font-weight: normal;
}

/* Hit Points Row */
.hp-row {
    grid-column: 1 / span 2;
    display: flex;
    align-items: center;
    margin-top: 10px;
}
.hp-row label {
    font-weight: bold;
    margin-right: 10px;
}
.hp-row input {
    padding: 6px 8px;
    margin-right: 6px;
    width: 70px;
    border: 2px solid #000;
    text-align: center;
    font-weight: 700;
}

/* Separator between current and max HP */
.hp-row .hp-sep {
    display: inline-block;
    width: 18px;
    text-align: center;
    font-weight: bold;
    margin: 0 4px;
    user-select: none;
}

/* Stats Section */
.stats-section {
    grid-column: 1 / span 2;
    display: grid;
    /* two columns: attributes and derived stats */
    grid-template-columns: 180px 1fr;
    grid-gap: 12px;
    margin-top: 10px;
}
.attributes, .derived-stats {
    border: 2px solid #000;
    padding: 8px;
    display: flex;
    flex-direction: column;
}
.attributes label, .derived-stats label {
    font-weight: 900;
    font-size: 0.95rem;
}
.attributes div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}
.attributes div label {
    flex: 1 1 auto;
    min-width: 0; /* allow truncation instead of wrapping */
    margin-right: 8px;
    white-space: nowrap; /* prevent wrapping so labels stay on one line */
    overflow: hidden;
    text-overflow: ellipsis;
}
.attributes input {
    flex: 0 0 48px;
    max-width: 48px;
    text-align: center;
    font-weight: 900;
    border: 2px solid #000;
}

/* Skills Die Container - horizontal row after HP */
.skills-die-container {
    grid-column: 1 / span 2;
    display: flex;
    flex-direction: row;
    gap: 12px;
    margin-top: 10px;
}

/* Individual skill boxes */
.skill-bonus-box,
.skill-die-box {
    border: 2px solid #000;
    padding: 8px 12px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.skill-bonus-box label,
.skill-die-box label {
    font-weight: 900;
    font-size: 0.95rem;
    display: block;
    text-align: left;
    padding: 2px 0;
}
.skill-bonus-box span,
.skill-die-box span {
    /* Make the numeric/value text not bold to match other labels */
    font-weight: 400;
    display: block;
    font-size: 1.1rem;
    text-align: center;
}

/* Speed & Carried Items */
.speed-carried {
    grid-column: 1 / span 2;
    display: grid;
    grid-template-columns: 1fr;
    grid-gap: 10px;
    margin-top: 10px;
}
.speed-field {
    display: flex;
    flex-direction: column;
    border: 2px solid #000;
    padding: 8px;
}
.speed-field label {
    font-weight: bold;
}
.speed-field input {
    padding: 6px;
    width: 100%;
    border: 2px solid #000;
}

/* Speed box when shown on the skills row */
.speed-box {
    border: 2px solid #000;
    padding: 8px 12px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex: 0 0 120px; /* keep a compact width */
}
.speed-box label {
    /* Match the appearance of other stat box labels */
    font-weight: 900;
    font-size: 0.95rem;
    display: block;
    text-align: left;
    padding: 2px 0;
}
.speed-box input {
    padding: 6px;
    width: 56px;
    border: 2px solid #000;
    text-align: center;
    font-weight: 900;
}
.carried-items {
    grid-column: 1 / span 2;
    display: flex;
    flex-direction: column;
    border: 2px solid #000;
    padding: 8px;
    margin-top: 10px;
}
.carried-items label {
    font-weight: bold;
}
.carried-items textarea {
    padding: 6px;
    width: 100%;
    resize: vertical;
    border: none;
    background: transparent;
    font-family: sans-serif;
    font-size: 1rem;
}

/* Skills Section */
.skills-section {
    display: flex;
    flex-direction: column;
    border: 2px solid #000;
    padding: 8px;
}
.skills-section label {
    font-weight: bold;
}
.skills-section textarea {
    padding: 6px;
    width: 100%;
    resize: vertical;
    border: 2px solid #000;
}

/* Sparks & Shadows */
.sparks-shadows {
    grid-column: 1 / span 2;
    display: flex;
    margin-top: 10px;
    gap: 10px;
}
.sparks, .shadows {
    flex: 1;
    border: 2px solid #000;
    padding: 8px;
}
.sparks label, .shadows label {
    font-weight: bold;
    display: block;
    margin-bottom: 5px;
}

/* Weapon Attack Section */
.weapon-attack-static {
    grid-column: 1 / span 2;
    margin-top: 10px;
    border: 2px solid #000;
    padding: 8px;
}
.weapon-attack-static h3 {
    margin: 0 0 5px 0;
    font-size: 1.1em;
    font-weight: bold;
}
.weapon-attack-static p {
    margin: 4px 0;
}
.info-spacing {
    display: inline-block;
    width: 30px;
}

/* Lineage Talent */
.lineage-talent {
    grid-column: 1 / span 2;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
}
.lineage-talent label {
    font-weight: bold;
}
.lineage-talent-text {
    padding: 6px;
    width: 100%;
    min-height: 2em;
    border: 2px solid #000;
    background: #fff;
}

/* Sheets Container */
.sheets-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-gap: 20px;
    margin: 20px;
}

/* Remove border for read-only fields */
/* Read-only fields should look like plain text and not be interactable */
input[readonly],
textarea[readonly] {
    border: none;
    background-color: transparent;
    pointer-events: none; /* prevent clicking into the control */
    cursor: default; /* don't show text cursor */
    user-select: none; /* optional: prevent selection so fields behave like static text */
    outline: none; /* remove focus outline in case of programmatic focus */
    padding: 0; /* make them blend with surrounding text */
    font: inherit;
    color: inherit;
}
/* Keep guard input clean */
input.guard {
    border: none;
    background-color: transparent;
}

/* Hide spinner arrows for number fields that are readonly so they appear as text */
input[type=number][readonly]::-webkit-outer-spin-button,
input[type=number][readonly]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number][readonly] {
    -moz-appearance: textfield; /* Firefox */
}

/* Print layout tweaks to ensure sheets stay letter-friendly */
@media print {
    body {
        background: #fff;
    }
    .sheets-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .character-sheet {
        max-width: 48%;
        page-break-inside: avoid;
        border-width: 4px;
        padding: 8px;
    }
}
