/* ============== LICHTERRA – CHARAKTERBOGEN ============== */

:root {
  --bg-deep:        #0f0d0a;
  --bg-mid:         #1a1612;
  --bg-light:       #221d17;
  --panel:          #1e1a14;
  --panel-edge:     #3b2f1f;
  --gold:           #c9a352;
  --gold-bright:    #e8c87a;
  --gold-dim:       #8a7038;
  --ink:            #e8dcc1;
  --ink-dim:        #b9ac8b;
  --ink-muted:      #847861;
  --crimson:        #8a2a2a;
  --crimson-bright: #c54040;
  --shadow:         rgba(0, 0, 0, 0.55);
  --green-good:     #6b9e4a;
  --red-bad:        #b04a3a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, "Cormorant Garamond", serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

body {
  background:
    radial-gradient(ellipse at top, rgba(60, 40, 20, 0.35), transparent 60%),
    radial-gradient(ellipse at bottom, rgba(40, 20, 10, 0.4), transparent 70%),
    linear-gradient(180deg, #0e0c08 0%, #181410 50%, #0a0806 100%);
  background-attachment: fixed;
}

.vignette {
  position: fixed; inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.55) 100%);
  z-index: 1;
}

/* ============== TOPBAR ============== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: linear-gradient(180deg, rgba(20, 15, 10, 0.98) 0%, rgba(20, 15, 10, 0.92) 100%);
  border-bottom: 1px solid var(--panel-edge);
  box-shadow: 0 4px 12px var(--shadow);
  backdrop-filter: blur(4px);
}

.brand h1 {
  margin: 0;
  font-family: "Cinzel", "Trajan Pro", "Cormorant Garamond", serif;
  font-size: 28px;
  letter-spacing: 6px;
  color: var(--gold-bright);
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(0,0,0,0.7), 0 0 18px rgba(201, 163, 82, 0.18);
  font-weight: 600;
}

.brand .subtitle {
  display: block;
  font-size: 12px;
  letter-spacing: 4px;
  color: var(--ink-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

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

button {
  background: linear-gradient(180deg, #2a2218 0%, #1a1410 100%);
  color: var(--gold);
  border: 1px solid var(--panel-edge);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s ease;
}

button:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
  box-shadow: 0 0 8px rgba(201, 163, 82, 0.25);
}

button:active {
  transform: translateY(1px);
}

.add-btn {
  margin-left: auto;
  font-size: 12px;
  padding: 5px 10px;
}

/* ============== MAIN / PANELS ============== */
.sheet {
  position: relative;
  z-index: 2;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 100px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 4px;
  padding: 18px 20px 20px;
  position: relative;
  box-shadow: 0 4px 14px var(--shadow), inset 0 0 0 1px rgba(201, 163, 82, 0.04);
  min-width: 0; /* erlaubt Schrumpfen im Grid */
}

.panel::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  background:
    linear-gradient(135deg, transparent 0 8px, var(--gold-dim) 8px 9px, transparent 9px) top left / 24px 24px no-repeat,
    linear-gradient(225deg, transparent 0 8px, var(--gold-dim) 8px 9px, transparent 9px) top right / 24px 24px no-repeat,
    linear-gradient( 45deg, transparent 0 8px, var(--gold-dim) 8px 9px, transparent 9px) bottom left / 24px 24px no-repeat,
    linear-gradient(-45deg, transparent 0 8px, var(--gold-dim) 8px 9px, transparent 9px) bottom right / 24px 24px no-repeat;
  opacity: 0.35;
}

.panel-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--panel-edge);
}

.panel-head h2 {
  margin: 0;
  font-family: "Cinzel", "Cormorant Garamond", Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  color: var(--gold-bright);
  letter-spacing: 2px;
}

.panel-head .hint {
  font-size: 12px;
  color: var(--ink-muted);
  font-style: italic;
}

/* full-width panels */
#panel-identitaet,
#panel-vitalitaet,
#panel-attribute,
#panel-magie,
#panel-eigenschaften,
#panel-aktionen,
#panel-zauber,
#panel-koerper,
#panel-ausruestung {
  grid-column: 1 / -1;
}

/* ============== FORM CONTROLS ============== */
label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--ink-muted);
  text-transform: uppercase;
  gap: 4px;
}

label.full { grid-column: 1 / -1; }

input[type="text"],
input[type="number"],
select,
textarea {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-edge);
  color: var(--ink);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
  border-radius: 2px;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(201, 163, 82, 0.2);
}

select option {
  background: var(--bg-mid);
  color: var(--ink);
}

textarea { resize: vertical; min-height: 80px; }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 16px;
}

.grid > * { min-width: 0; }
label { min-width: 0; }
input, select, textarea { min-width: 0; width: 100%; }

.identitaet-grid label:nth-child(-n+3) { grid-column: span 1; }

/* ============== PORTRAIT ============== */
.identitaet-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.portrait-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.portrait-frame {
  position: relative;
  width: 240px;
  height: 320px;
  border: 1px solid var(--panel-edge);
  background: linear-gradient(180deg, #1a1410 0%, #0e0c08 100%);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(201, 163, 82, 0.07), 0 4px 12px rgba(0,0,0,0.4);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.portrait-frame::before {
  content: "";
  position: absolute;
  inset: 6px;
  pointer-events: none;
  border: 1px solid rgba(201, 163, 82, 0.15);
  border-radius: 2px;
  z-index: 2;
}

.portrait-frame:hover {
  border-color: var(--gold-dim);
}

.portrait-frame.dragover {
  border-color: var(--gold);
  box-shadow: 0 0 14px rgba(201, 163, 82, 0.45), inset 0 0 0 2px var(--gold-dim);
}

.portrait-frame.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50' width='42'%3E%3Ccircle cx='25' cy='25' r='20' stroke='%23c9a352' stroke-width='3' fill='none' stroke-linecap='round' stroke-dasharray='80 30'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 25 25' to='360 25 25' dur='1.2s' repeatCount='indefinite'/%3E%3C/circle%3E%3C/svg%3E") center no-repeat;
  z-index: 3;
}

#portrait-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.portrait-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--ink-muted);
  text-align: center;
  padding: 20px;
}

.portrait-placeholder[hidden],
.portrait-overlay[hidden] { display: none !important; }

.portrait-icon {
  font-size: 48px;
  color: var(--gold-dim);
  opacity: 0.5;
}

.portrait-hint-text {
  font-size: 12px;
  letter-spacing: 1px;
  line-height: 1.6;
  font-style: italic;
}

.portrait-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 6px;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.2s;
}

.portrait-frame:hover .portrait-overlay { opacity: 1; }

.portrait-overlay button {
  width: 28px;
  height: 28px;
  padding: 0;
  background: rgba(15, 13, 10, 0.85);
  border: 1px solid var(--gold-dim);
  font-size: 14px;
  color: var(--gold);
}

.portrait-overlay .portrait-remove:hover {
  color: var(--crimson-bright);
  border-color: var(--crimson);
}

.portrait-controls {
  display: flex;
}

.portrait-controls button {
  width: 100%;
  font-size: 13px;
}

@media (max-width: 800px) {
  .identitaet-layout { grid-template-columns: 1fr; }
  .portrait-wrap { max-width: 320px; margin: 0 auto; }
  .portrait-frame { width: 100%; height: auto; aspect-ratio: 3 / 4; }
}

@media print {
  .portrait-controls { display: none !important; }
  .portrait-frame { box-shadow: none; border: 1px solid #888; }
  .portrait-frame::before { display: none; }
  .identitaet-layout { grid-template-columns: 180px 1fr; gap: 16px; }
  .portrait-frame { width: 180px; height: 240px; }
}

/* ============== RACE INFO ============== */
.race-info {
  margin-top: 18px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.25);
  border-left: 3px solid var(--gold-dim);
  border-radius: 0 4px 4px 0;
  font-size: 14px;
  color: var(--ink-dim);
  line-height: 1.6;
}

.race-info h3 {
  margin: 0 0 6px;
  font-family: "Cinzel", Georgia, serif;
  color: var(--gold);
  font-size: 15px;
  letter-spacing: 1.5px;
}

.race-info .info-block { margin-bottom: 12px; }
.race-info .info-block:last-child { margin-bottom: 0; }

/* ============== VITAL & ATTRIBUTE ============== */
.vital-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.vital-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-edge);
  padding: 12px;
  text-align: center;
  border-radius: 4px;
  position: relative;
}

.vital-card .vital-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}

.vital-card .vital-values {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.vital-card input {
  width: 56px !important;
  text-align: center;
  font-size: 18px;
  padding: 4px;
  background: rgba(0,0,0,0.4);
}

.vital-card .vital-slash {
  color: var(--ink-muted);
  font-size: 18px;
}

.vital-card.unavailable {
  opacity: 0.35;
}

.vital-card.unavailable input {
  pointer-events: none;
}

.attr-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.attr-card {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--panel-edge);
  padding: 14px 12px;
  border-radius: 4px;
  text-align: center;
}

.attr-card .attr-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 8px;
}

.attr-card input {
  width: 64px !important;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  padding: 6px;
  color: var(--gold-bright);
  background: rgba(0,0,0,0.4);
}

.attr-card.unavailable {
  opacity: 0.35;
}

/* ============== MAGIE ============== */
.magie-groups {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.magie-group h3 {
  margin: 0 0 8px;
  font-family: "Cinzel", Georgia, serif;
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--panel-edge);
  padding-bottom: 4px;
}

.magie-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.magie-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 2px;
  background: rgba(0,0,0,0.15);
  border: 1px solid transparent;
  font-size: 14px;
}

.magie-item.active {
  background: rgba(201, 163, 82, 0.12);
  border-color: var(--gold-dim);
  color: var(--gold-bright);
}

.magie-item input { margin: 0; accent-color: var(--gold); }

.magie-item .lock {
  font-size: 11px;
  color: var(--ink-muted);
  margin-left: auto;
}

.magie-hint {
  margin: 14px 0 0;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-muted);
}

/* ============== EIGENSCHAFTEN / AKTIONEN ============== */
.list { display: flex; flex-direction: column; gap: 10px; }

.list-item {
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--panel-edge);
  border-left: 3px solid var(--gold-dim);
  border-radius: 0 4px 4px 0;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 200px 1fr auto;
  gap: 12px;
  align-items: start;
}

.list-item.from-race { border-left-color: var(--gold); }

.list-item input,
.list-item textarea {
  background: transparent;
  border: none;
  padding: 2px 4px;
  font-size: 14px;
}

.list-item input { font-weight: 600; color: var(--gold-bright); }
.list-item textarea { color: var(--ink); resize: none; }

.list-item .delete {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-muted);
  font-size: 16px;
  padding: 2px 6px;
}

.list-item .delete:hover {
  color: var(--crimson-bright);
  border-color: var(--crimson);
}

/* tables */
.aktionen-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.aktionen-table thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
  padding: 6px 10px;
  border-bottom: 1px solid var(--panel-edge);
  font-weight: normal;
}

.aktionen-table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(60, 47, 31, 0.4);
  vertical-align: top;
}

.aktionen-table tr.from-race td { background: rgba(201, 163, 82, 0.04); }

.aktionen-table input,
.aktionen-table textarea {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 6px;
  font-size: 14px;
  color: var(--ink);
}

.aktionen-table textarea { resize: vertical; min-height: 28px; font-family: inherit; }

.aktionen-table input:focus,
.aktionen-table textarea:focus {
  background: rgba(0,0,0,0.3);
  border-color: var(--panel-edge);
}

.aktionen-table .col-name    { width: 22%; }
.aktionen-table .col-schaden { width: 12%; }
.aktionen-table .col-aus     { width: 10%; }
.aktionen-table .col-delete  { width: 32px; }

.aktionen-table .delete {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
}

.aktionen-table .delete:hover { color: var(--crimson-bright); border-color: var(--crimson); }

/* ============== KÖRPER & ERNÄHRUNG ============== */
.koerper-grid { grid-template-columns: 1fr 1fr; }

.koerper-grid h3 {
  margin: 0 0 8px;
  font-family: "Cinzel", Georgia, serif;
  font-size: 13px;
  color: var(--gold);
  letter-spacing: 2px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--panel-edge);
  padding-bottom: 4px;
}

.koerper-data {
  font-size: 14px;
  line-height: 1.7;
}

.koerper-data .row { display: flex; gap: 8px; }
.koerper-data .row span:first-child {
  color: var(--gold);
  min-width: 90px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.ernaehrung-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.ernaehrung-item {
  padding: 6px 10px;
  border-radius: 2px;
  font-size: 13px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--panel-edge);
  color: var(--ink-muted);
}

.ernaehrung-item.ja {
  background: rgba(107, 158, 74, 0.12);
  border-color: rgba(107, 158, 74, 0.5);
  color: #b8d29e;
}

.ernaehrung-item.ja::before { content: "✓ "; }
.ernaehrung-item:not(.ja)::before { content: "✕ "; opacity: 0.4; }

.ernaehrung-sonder {
  margin-top: 10px;
  font-style: italic;
  font-size: 13px;
  color: var(--gold);
}

/* ============== FOOTBAR ============== */
.footbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  padding: 8px 24px;
  background: rgba(15, 13, 10, 0.95);
  border-top: 1px solid var(--panel-edge);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ink-muted);
  text-transform: uppercase;
  display: flex;
  gap: 12px;
  align-items: center;
}

.footbar strong { color: var(--gold-bright); font-weight: 600; letter-spacing: 0; text-transform: none; }
.footbar .dot { color: var(--gold-dim); }

#save-state.saving { color: var(--gold-bright); }

/* ============== MODAL ============== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal[hidden] { display: none !important; }

/* Auch Variant-Wrap respektiert hidden */
.variant-wrap[hidden] { display: none !important; }

.modal-card {
  background: var(--panel);
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  padding: 24px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.7);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--panel-edge);
}

.modal-head h2 {
  margin: 0;
  font-family: "Cinzel", Georgia, serif;
  font-size: 22px;
  color: var(--gold-bright);
  letter-spacing: 2px;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--ink-muted);
  padding: 0 8px;
}

.modal-close:hover { color: var(--gold-bright); }

.hero-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.hero-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--panel-edge);
  margin-bottom: 8px;
  border-radius: 3px;
  background: rgba(0,0,0,0.2);
  transition: all 0.15s;
}

.hero-list li:hover {
  border-color: var(--gold);
  background: rgba(201, 163, 82, 0.05);
}

.hero-list li.current {
  border-left: 3px solid var(--gold);
}

.hero-list .hero-info { flex: 1; cursor: pointer; }
.hero-list .hero-name { font-size: 16px; color: var(--gold-bright); font-weight: 600; }
.hero-list .hero-meta { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }
.hero-list .hero-actions { display: flex; gap: 6px; }
.hero-list button { padding: 4px 10px; font-size: 12px; }
.hero-list button.danger { color: var(--crimson-bright); }
.hero-list button.danger:hover { border-color: var(--crimson); }

/* ============== RESPONSIVE ============== */
@media (max-width: 900px) {
  .sheet { grid-template-columns: 1fr; }
  .grid, .vital-grid, .attr-grid, .magie-groups { grid-template-columns: 1fr 1fr; }
  .topbar { flex-direction: column; gap: 10px; }
  .brand h1 { font-size: 22px; letter-spacing: 4px; }
}

@media (max-width: 550px) {
  .grid, .vital-grid, .attr-grid, .magie-groups { grid-template-columns: 1fr; }
  .list-item { grid-template-columns: 1fr; }
}

/* ============== PRINT ============== */
@media print {
  body { background: white; color: black; font-size: 11pt; }
  .vignette, .topbar, .footbar, .modal, .add-btn, .delete, #variant-wrap { display: none !important; }
  .sheet { grid-template-columns: 1fr 1fr; padding: 0; gap: 12px; max-width: 100%; }
  .panel { background: white; border: 1px solid #aaa; box-shadow: none; padding: 10px; break-inside: avoid; }
  .panel::before { display: none; }
  .panel-head h2 { color: #000; font-size: 14pt; }
  .panel-head .hint { display: none; }
  input, select, textarea { background: transparent; border: none; color: #000; }
  .vital-card, .attr-card, .list-item { background: transparent; border: 1px solid #ccc; }
  .vital-card .vital-label, .attr-card .attr-label { color: #000; }
  .magie-item.active { background: #f0e8d0; color: #000; }
  .race-info { background: #faf4e4; color: #333; border-color: #aaa; }
  #panel-identitaet, #panel-magie, #panel-eigenschaften,
  #panel-aktionen, #panel-zauber, #panel-koerper, #panel-ausruestung { grid-column: 1 / -1; }
}
