﻿
        :root {
            --main-font: 'Ringbearer', 'Microsoft YaHei', 'SimHei', 'KaiTi', 'STKaiti', 'serif';
            --border-color: #b7433c;
            --text-color: #3a2d1d;
            --background-color: #f7f3e9;
            --input-underline-color: #d1c5b0;
        }

        @font-face {
            font-family: 'Ringbearer';
            src: url('../fonts/ringbearer.TTF') format('truetype');
        }

        body {
            font-family: var(--main-font);
            background-color: #e0dace;
            color: var(--text-color);
            margin: 0;
            padding: 20px;
            font-size: 14px;
            line-height: 1.5;
        }

        .character-sheet {
            width: calc(297mm - 30px);
            height: calc(210mm - 30px);
            margin: auto;
            border: 1px solid var(--border-color);
            padding: 15px;
            background: #faf0e6;
            box-shadow: var(--box-shadow);
            position: relative;
        }

        .character-sheet::before {
            content: '';
            position: absolute;
            top: 15px;
            right: 15px;
            bottom: 15px;
            left: 15px;
            opacity: 0.25;
            pointer-events: none;
            z-index: 0;
        }

        h1, h2, legend {
            color: var(--border-color);
            border-bottom: 2px solid var(--border-color);
            padding-bottom: 2px;
            font-weight: bold;
        }
        h1 { text-align: center; margin-bottom: 15px; }

        .grid-container {
            display: grid;
            grid-template-columns: 3fr 1fr;
            gap: 15px;
            position: relative;
            z-index: 1;
        }

        input[type="text"], input[type="number"], textarea, select {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
            border: 2px solid #c8a077;
            background-color: var(--input-bg);
            border-radius: 4px;
            font-family: Ringbearer;
        }
        .header-right .points-row input[type="number"] {
            appearance: textfield;
            -moz-appearance: textfield;
        }
        .header-right .points-row input[type="number"]::-webkit-outer-spin-button,
        .header-right .points-row input[type="number"]::-webkit-inner-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }

        input[readonly], input.readonly {
            background-color: #f7f4ee;
            cursor: default;
        }

        textarea {
            resize: vertical;
            min-height: 60px;
        }

        .main-left {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 15px;
        }

        .main-right {
            display: flex;
            flex-direction: column;
            align-items: stretch;
        }

        .header-info {
            grid-column: span 3;
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-auto-rows: minmax(28px, auto);
            gap: 2px 8px;
            align-items: start;
            padding-bottom: 0;
        }

        .header-right {
            display: flex;
            flex-direction: column;
            gap: 12px;
            align-items: stretch;
        }

        .portrait-box {
            text-align: center;
        }

        .portrait-frame {
            position: relative;
            width: 150px;
            height: 150px;
            margin: 0 auto;
        }

        #portrait_preview {
            width: 100%;
            height: 100%;
            border: 2px solid var(--border-color);
            background: #fff;
            object-fit: cover;
            border-radius: 4px;
            display: block;
        }

        .portrait-placeholder {
            position: absolute;
            inset: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 4px;
            color: #6b5b4a;
            font-size: 0.95em;
            pointer-events: none;
        }

        .portrait-placeholder span {
            display: block;
        }

        .portrait-box.has-portrait .portrait-placeholder {
            display: none;
        }

        .portrait-box:not(.has-portrait) .portrait-frame {
            cursor: pointer;
        }

        .portrait-box:not(.has-portrait) .portrait-frame:hover {
            box-shadow: 0 0 0 2px rgba(183, 67, 60, 0.25);
            border-radius: 4px;
        }

        .portrait-remove {
            position: absolute;
            top: 4px;
            right: 4px;
            width: 20px;
            height: 20px;
            border: none;
            border-radius: 50%;
            background: rgba(183, 67, 60, 0.9);
            color: #fff;
            font-size: 16px;
            line-height: 20px;
            padding: 0;
            cursor: pointer;
            display: none;
        }

        .portrait-remove:hover {
            background: rgba(183, 67, 60, 1);
        }

        .portrait-box.has-portrait .portrait-frame:hover .portrait-remove {
            display: block;
        }

        .portrait-controls {
            margin-top: 8px;
        }

        .custom-file-upload {
            border: 1px solid #8b4513;
            display: inline-block;
            padding: 6px 12px;
            cursor: pointer;
            background-color: #8b4513;
            color: white;
            border-radius: 4px;
            font-size: 0.9em;
        }

        input[type="file"] {
            display: none;
        }

        .attributes-section, .skills-section, .combat-features-section {
            display: contents;
        }

        .info-item {
            display: flex;
            flex-direction: column;
            position: relative;
        }

        .info-item label {
            margin-bottom: 4px;
            font-size: 0.9em;
        }
        .info-item.inline-row {
            flex-direction: row;
            align-items: center;
            gap: 6px;
        }
        .info-item.inline-row label {
            margin-bottom: 0;
            white-space: nowrap;
        }

        .header-info .info-item {
            flex-direction: row;
            align-items: center;
            gap: 4px;
        }

        .header-info .info-item label {
            margin-bottom: 0;
            white-space: nowrap;
            line-height: 1;
        }

        .header-info .info-item input[type="text"],
        .header-info .info-item input[type="number"],
        .header-info .info-item select {
            flex: 1 1 auto;
            padding: 2px 6px;
            height: 28px;
            line-height: 1.1;
        }
        .header-info .info-item.char-name input[type="text"] {
            flex: 0 0 180px;
            width: 180px;
            margin-left: auto;
        }
        .header-info .info-item.heroic-culture select {
            flex: 0 0 180px;
            width: 180px;
            margin-left: auto;
        }
        .header-info .info-item.cultural-blessing input[type="text"] {
            flex: 0 0 180px;
            width: 180px;
            margin-left: auto;
        }
        .header-info .info-item.calling select,
        .header-info .info-item.char-age input[type="text"],
        .header-info .info-item.char-patron input[type="text"] {
            flex: 0 0 85px;
            width: 85px;
            margin-left: auto;
        }
        .header-info .info-item.char-treasure input[type="text"],
        .header-info .info-item.char-living-standard select,
        .header-info .info-item.shadow-path input[type="text"] {
            flex: 0 0 70px;
            width: 70px;
            margin-left: auto;
        }
        .header-info .trait-box select,
        .header-info .trait-box input[type="text"] {
            flex: 0 0 180px;
            width: 180px;
            margin-left: auto;
            height: 34px;
            padding: 1px 6px;
            font-size: 0.95em;
            line-height: 1.2;
        }
        .header-info .trait-box label {
            font-size: 0.85em;
            line-height: 1;
        }

        .header-info .info-row {
            display: flex;
            gap: 6px;
        }

        .header-info .info-row .info-item {
            flex: 1 1 0;
            min-width: 0;
        }

        .identity-group { grid-column: 1; grid-row: 1 / span 3; display: grid; gap: 10px; }
        .identity-group .info-item { grid-column: 1; }
        .info-item.cultural-blessing { align-items: center; flex-wrap: nowrap; }
        .second-column-group { grid-column: 2; grid-row: 1 / span 3; display: grid; gap: 10px; }
        .header-info #personal_traits_section {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-auto-rows: minmax(28px, auto);
            gap: 2px 8px;
            grid-column: 3;
            grid-row: 1 / span 3;
        }
        .header-info #personal_traits_section .trait-box { grid-column: 1 / -1; }
        .header-info #personal_traits_section .trait1-item { grid-row: 1; }
        .header-info #personal_traits_section .trait2-item { grid-row: 2; }
        .header-info #personal_traits_section .trait3-item { grid-row: 3; }
        .header-right .portrait-box { align-self: center; }
        .header-right .points-row { display: flex; gap: 6px; align-items: center; }
        .header-right .points-row .info-item { flex: 1 1 0; min-width: 0; flex-direction: row; align-items: center; gap: 6px; }
        .header-right .points-row .info-item label { margin-bottom: 0; white-space: nowrap; }
        .header-right .points-row .info-item input[type="number"] { width: 38px; padding: 2px 6px; height: 28px; }
        .header-right .header-extra { display: flex; flex-direction: column; gap: 10px; align-items: stretch; flex: 1 1 auto; min-height: 0; }
        .header-right .travel-gear-item { flex-direction: column; align-items: stretch; flex: 1 1 auto; min-height: 0; }
        .header-right .travel-gear-item label { margin-bottom: 6px; font-size: 1em; border-bottom: 2px solid var(--border-color); padding-bottom: 4px; }
        .header-right .travel-gear-item textarea { min-height: 190px; height: calc(100% - 50px); resize: none; }
        .header-info .attributes-section > div { grid-row: 4; }

        .gear-section {
            grid-column: span 3;
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 15px;
        }
        .gear-section > .gear-table { margin-top: -20px; }

        .status-checkbox-group, .game-mode-group { /* MODIFIED */
            display: flex;
            gap: 10px;
            align-items: center;
            flex-wrap: wrap;
            justify-content: center;
        }
        .game-mode-group label { /* MODIFIED */
            margin-bottom: 0;
        }

        .header-right .info-item.status-checks,
        .header-right .info-item.game-mode {
            text-align: center;
        }
        .header-right .info-item.status-checks > label,
        .header-right .info-item.game-mode > label {
            font-weight: bold;
        }
        
        /* NEW: Container for small diamond boxes in header */
        .secondary-stats-container {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 10px;
            padding-top: 10px;
        }

        #personal_traits_section h2 { margin-top: 0; }
        .description-box {
            position: absolute;
            left: 0;
            top: 100%;
            margin-top: 6px;
            width: 260px;
            max-width: 320px;
            font-size: 0.9em;
            min-height: 0;
            padding: 6px 8px;
            background: #fff;
            border: 1px dashed #c8a077;
            border-radius: 4px;
            white-space: pre-wrap;
            box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
            display: none;
            z-index: 20;
        }
        .info-item:hover .description-box,
        .info-item:focus-within .description-box,
        .trait-box:hover .description-box,
        .trait-box:focus-within .description-box {
            display: block;
        }
        #king_of_men_bonus { margin-top: 8px; padding: 5px; background-color: #fff; border: 1px solid var(--border-color); border-radius: 4px; }
        #king_of_men_bonus:not(.hidden) { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
        #king_of_men_bonus button { margin: 0px; padding: 0px 2px; font-family: Ringbearer; }
        .hidden { display: none; }

        /* --- Diamond Attribute Box Styles --- */
        .diamond-box {
            border: 2px solid var(--border-color);
            border-radius: 0;
            transform: rotate(45deg);
            position: relative;
        }
        .square-box-small {
            border-radius: 6px;
            transform: none;
        }
        .diamond-content {
            width: 100%;
            height: 100%;
            transform: rotate(-45deg);
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .square-box-small .diamond-content {
            transform: none;
        }
        .diamond-box .attr-title { position: absolute; font-weight: bold; color: var(--border-color); text-align: center; width: 100%; }
        .diamond-box .attr-derived { position: absolute; text-align: center; width: 100%; }
        .diamond-box .attr-tn, .diamond-box .attr-val { position: absolute; text-align: center; }
        .diamond-box .attr-tn input, .diamond-box .attr-val input { border: 1px solid var(--border-color); text-align: center; padding: 0; background-color: white; }
        #endurance_val, #hope_val, #parry_val { font-size: 1.35em; }
        #body_tn, #body_val, #heart_tn, #heart_val, #wits_tn, #wits_val {
            appearance: textfield;
            -moz-appearance: textfield;
        }
        #body_tn::-webkit-outer-spin-button,
        #body_tn::-webkit-inner-spin-button,
        #body_val::-webkit-outer-spin-button,
        #body_val::-webkit-inner-spin-button,
        #heart_tn::-webkit-outer-spin-button,
        #heart_tn::-webkit-inner-spin-button,
        #heart_val::-webkit-outer-spin-button,
        #heart_val::-webkit-inner-spin-button,
        #wits_tn::-webkit-outer-spin-button,
        #wits_tn::-webkit-inner-spin-button,
        #wits_val::-webkit-outer-spin-button,
        #wits_val::-webkit-inner-spin-button {
            -webkit-appearance: none;
            margin: 0;
        }

        /* Large Diamond Box Styles (Main Attributes) */
        .diamond-box:not(.diamond-box-small) { width: 110px; height: 110px; margin: 20px auto 12px; }
        .diamond-box:not(.diamond-box-small) .attr-title { top: 2px; font-size: 1em; }
        .diamond-box:not(.diamond-box-small) .attr-derived { bottom: 7px; font-size: 0.9em; }
        .diamond-box:not(.diamond-box-small) .attr-tn, .diamond-box:not(.diamond-box-small) .attr-val { width: 38px; }
        .diamond-box:not(.diamond-box-small) .attr-tn { left: 0px; }
        .diamond-box:not(.diamond-box-small) .attr-val { right: 0px; }
        .diamond-box:not(.diamond-box-small) .attr-tn, .diamond-box:not(.diamond-box-small) .attr-val { top: 22px; }
        .diamond-box:not(.diamond-box-small) .attr-tn label, .diamond-box:not(.diamond-box-small) .attr-val label { font-size: 1em; }
        .diamond-box:not(.diamond-box-small) .attr-tn, .diamond-box:not(.diamond-box-small) .attr-val { width: 46px; }
        .diamond-box:not(.diamond-box-small) .attr-tn input, .diamond-box:not(.diamond-box-small) .attr-val input { width: 34px; height: 34px; font-size: 1em; }

        /* NEW: Small Diamond Box Styles (Header) */
        .diamond-box-small { width: 120px; height: 120px; margin: 6px auto; }
        .diamond-box-small .attr-title { top: 6px; font-size: 0.95em; }
        .diamond-box-small .attr-derived { bottom: 6px; font-size: 1.05em; line-height: 1.2; }
        .diamond-box-small .attr-tn, .diamond-box-small .attr-val { top: 10px; width: 46px; }
        .diamond-box-small .attr-tn { left: 6px; }
        .diamond-box-small .attr-val { right: 6px; }
        .diamond-box-small .attr-tn label, .diamond-box-small .attr-val label { font-size: 0.95em; }
        .diamond-box-small .attr-tn input, .diamond-box-small .attr-val input { width: 30px; height: 30px; font-size: 1.1em; }
        
        .current-stat-input-diamond { width: 38px !important; padding: 1px !important; text-align: center; font-size: 1.2em !important; display: inline-block; vertical-align: middle; margin-left: 4px; margin-top: 2px; }
        .secondary-stats-container #load_val,
        .secondary-stats-container #fatigue_val,
        .secondary-stats-container #shadow_val,
        .secondary-stats-container #shadow_scar_val {
            width: 38px;
            height: 38px;
            font-size: 1.1em;
        }

        .skills-column { grid-column: span 1; padding: 10px; position: relative; z-index: 2; }
        .skills-section .skills-column { margin-top: -10px; }
        .skills-column h2 { margin-top: 0; text-align: center; }

        /* MODIFIED: Skill Item Layout */
        .skill-item {
            display: flex;
            align-items: center;
            margin-bottom: 6px;
            gap: 8px;
            font-size: 0.9em;
        }
        .specialization-container {
            display: flex;
            align-items: center;
            gap: 4px;
            font-size: 0.85em;
        }
        .specialization-container input[type="checkbox"] {
            width: 14px;
            height: 14px;
            margin: 0;
            flex-shrink: 0;
        }
        .skill-item > .skill-name-label {
            flex-grow: 1;
            margin: 0;
        }

        .skill-ranks { display: flex; }
        .skill-ranks input[type="checkbox"] { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border: 1px solid var(--border-color); margin: 0 2px; cursor: pointer; position: relative; }
        .skill-ranks input[type="checkbox"]::before { content: ''; position: absolute; top: 50%; left: 50%; width: 12px; height: 12px; background-color: var(--border-color); transform: translate(-50%, -50%) scale(0); transition: transform 0.2s ease-in-out; }
        .skill-ranks input[type="checkbox"]:checked::before { transform: translate(-50%, -50%) scale(1); }
        .section-break { grid-column: span 3; border-top: 2px solid var(--border-color); margin-top: 10px; }
        .combat-proficiencies, .feature-box { grid-column: span 1; padding: 10px; font-size: 0.95em; margin-top: 10px; }
        .combat-proficiencies h2, .feature-box h2 { font-size: 1.05em; }
        .combat-features-section > div { margin-top: -40px; }
        .feature-box .info-item { margin-top: 10px; }
        .feature-title-bar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }
        .feature-title-text { flex: 1 1 auto; }
        .feature-title-input {
            display: flex;
            align-items: center;
        }
        .feature-title-input input[type="number"] {
            width: 60px;
            padding: 2px 6px;
            height: 24px;
        }
        .visually-hidden {
            position: absolute;
            width: 1px;
            height: 1px;
            padding: 0;
            margin: -1px;
            overflow: hidden;
            clip: rect(0, 0, 0, 0);
            border: 0;
            white-space: nowrap;
        }
        #rewards_container, #virtues_container {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 8px 10px;
        }
        #rewards_container .description-box,
        #virtues_container .description-box {
            font-size: 1em;
        }
        #rewards_container .info-item,
        #virtues_container .info-item {
            margin-top: 0;
        }
        #rewards_container select,
        #virtues_container select {
            font-size: 0.85em;
        }
        #rewards_container label {
            font-size: 0.65em;
        }
        #customRewardModal textarea {
            min-height: 110px;
            height: 110px;
            resize: none;
        }
        .custom-reward-list-section label {
            display: block;
            margin-bottom: 6px;
            margin-top: 6px;
            font-weight: bold;
        }
        .custom-reward-list {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            min-height: 32px;
        }
        .custom-reward-list button {
            border: 1px solid var(--border-color);
            background-color: #fff;
            color: var(--text-color);
            border-radius: 3px;
            padding: 4px 8px;
            cursor: pointer;
            font-family: Ringbearer;
            font-size: 0.85em;
        }
        .custom-reward-list-empty {
            color: #6b5b4a;
            font-size: 0.85em;
            padding: 4px 0;
        }
        .custom-reward-list button.active {
            background-color: var(--border-color);
            color: #fff;
        }
        .custom-reward-list-actions {
            display: flex;
            gap: 8px;
            margin-top: 8px;
        }
        .custom-reward-divider {
            border: none;
            border-top: 1px solid #c8a077;
            margin: 10px 0 6px;
        }
        .custom-reward-list-actions button {
            padding: 6px 10px;
            border-radius: 3px;
            border: none;
            cursor: pointer;
            font-family: Ringbearer;
        }
        #custom_reward_add {
            background-color: #8b4513;
            color: #fff;
        }
        #custom_reward_delete {
            background-color: #c04040;
            color: #fff;
        }
        #personal_traits_section { display: grid; }
        .trait-box { display: flex; align-items: center; gap: 6px; padding: 0; border: none; background-color: transparent; position: relative; }
        .trait-box label { margin-bottom: 0; white-space: nowrap; }
        .trait-box select,
        .trait-box input[type="text"] { flex: 1 1 auto; }
        .gear-table { grid-column: span 1; }
        .gear-table-wide { grid-column: span 2; }
        .protective-gear-table { margin-top: -30px; }
        .gear-table table { width: 100%; border-collapse: collapse; }
        .gear-table th, .gear-table td { border: 1px solid var(--border-color); padding: 8px; text-align: center; font-size: 0.85em; }
        .gear-table th { background-color: var(--header-bg); }
        .gear-table tbody tr:hover td { background-color: #e2d4c3; }
        .gear-table input { text-align: center; font-size: 0.95em; }
        .gear-table input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
        .gear-table input[type="number"]::-webkit-outer-spin-button,
        .gear-table input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
        .gear-table .short-input { margin: 0 auto; display: block; }
        .protective-gear-table tbody tr { cursor: pointer; }
        .gear-controls { margin-top: 5px; text-align: right; }
        .gear-controls button, .select-protective-gear-btn, .clear-protective-gear-btn { background-color: #8b4513; color: white; border: none; padding: 4px 8px; border-radius: 3px; cursor: pointer; font-family: Ringbearer; }
        .clear-protective-gear-btn { background-color: #c04040; }
        #combat_gear_body input[data-key="load"] { max-width: 50px; }
        #combat_gear_body input[data-key="notes"] { max-width: 140px; }
        .buttons-section { grid-column: 1 / -1; display: flex; justify-content: center; gap: 12px; padding-top: 20px; }
        .buttons-section button { padding: 10px 20px; margin: 0; font-family: Ringbearer; font-size: 1em; background-color: var(--border-color); color: white; border: none; border-radius: 5px; cursor: pointer; box-shadow: var(--box-shadow); }
        .buttons-section button:hover { opacity: 0.9; }

        @media print {
            .portrait-controls {
                display: none !important;
            }
        }
        .short-input { max-width: 80px; }
        .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); display: flex; justify-content: center; align-items: center; z-index: 1000; transition: opacity 0.3s ease; }
        .modal-content { background-color: var(--background-color); padding: 25px; border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.3); border: 2px solid var(--border-color); width: 90%; max-width: 500px; }
        .modal-content h2 { margin-top: 0; text-align: center; }
        .modal-form-item { margin-bottom: 15px; }
        .modal-form-item label { display: block; margin-bottom: 5px; }
        .modal-buttons { text-align: right; margin-top: 20px; }
        .modal-buttons button { padding: 8px 16px; margin-left: 10px; font-family: Ringbearer; font-size: 1em; background-color: var(--border-color); color: white; border: none; border-radius: 5px; cursor: pointer; }
        .modal-buttons button[type="button"] { background-color: #a9a9a9; }
        #clear_combat_gear_btn { background-color: #8b4513; }
        #clear_protective_gear_btn { background-color: #8b4513; }
        .modal-overlay.hidden { display: none; }
        .portrait-crop-modal { max-width: 560px; }
        .portrait-crop-area { display: flex; justify-content: center; margin: 10px 0 15px; }
        .portrait-crop-frame {
            width: 220px;
            height: 220px;
            border: 2px dashed var(--border-color);
            background: #fff;
            position: relative;
            overflow: hidden;
            cursor: grab;
            touch-action: none;
        }
        .portrait-crop-frame:active { cursor: grabbing; }
        #portrait_crop_image {
            position: absolute;
            top: 0;
            left: 0;
            transform-origin: top left;
            user-select: none;
            -webkit-user-drag: none;
        }
        .portrait-crop-controls {
            display: flex;
            align-items: center;
            gap: 10px;
            justify-content: center;
        }
        @media screen and (max-width: 992px) { .attributes-section > div, .skills-column, .combat-proficiencies, .feature-box { grid-column: span 3 !important; } .header-info { display: flex; flex-wrap: wrap; } .info-item { width: 48%; } .portrait-box { order: -1; width: 100%; margin-bottom: 15px; } .secondary-stats-container { order: 1; width: 100%; } }
        @media screen and (max-width: 768px) { .points-container { grid-template-columns: 1fr; } }
        @media print {
            @page { size: 297mm 210mm; margin: 0; }
            html, body { width: 297mm; height: 210mm; padding: 0; margin: 0; }
            * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            body { background-color: #e0dace; }
            .character-sheet {
                width: 297mm;
                height: 210mm;
                margin: 0;
                box-sizing: border-box;
                transform: none;
                overflow: hidden;
                position: relative;
                background: #faf0e6;
            }
            .buttons-section { display: none; }
            .gear-controls { display: none; }
        }
    
