@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Crimson+Text:ital,wght@0,400;0,600;0,700;1,400&display=swap');

:root {
  --parchment: #f4e4c1;
  --parchment-dark: #e8d5a3;
  --ink: #2c1810;
  --ink-light: #5a3a28;
  --accent: #8b1a1a;
  --accent-light: #b22222;
  --gold: #c9a84c;
  --gold-dark: #a07c2a;
  --green: #2d6a2d;
  --green-light: #4a9a4a;
  --blue: #2a4a7a;
  --shadow: rgba(44, 24, 16, 0.15);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Crimson Text', Georgia, serif;
  background: #3a2a1a;
  color: var(--ink);
  height: 100vh;
  overflow: hidden;
  line-height: 1.5;
}

.page {
  background:
    linear-gradient(to right, rgba(44, 24, 16, 0.08) 0%, transparent 3%, transparent 97%, rgba(44, 24, 16, 0.08) 100%),
    linear-gradient(to bottom, rgba(44, 24, 16, 0.05) 0%, transparent 2%, transparent 98%, rgba(44, 24, 16, 0.05) 100%),
    var(--parchment);
  min-height: 100%;
  padding: 2rem 2.5rem;
}

/* ---- Split layout (feuille + PDF) ---- */
.split-container {
  display: flex;
  height: 100vh;
  gap: 0;
  align-items: stretch;
}

.left-panel {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

.right-panel {
  width: 60%;
  min-width: 320px;
  background: rgba(255,255,255,0.95);
  border-left: 2px solid var(--gold);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.pdf-header {
  padding: 1rem;
  background: var(--parchment-dark);
  border-bottom: 1px solid var(--gold);
  font-family: 'Cinzel', serif;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
}

.pdf-frame {
  width: 100%;
  border: none;
  flex: 1;
}

@media (max-width: 900px) {
  body { height: auto; overflow: auto; }
  .split-container { flex-direction: column; height: auto; }
  .left-panel { overflow-y: visible; }
  .right-panel { width: 100%; min-width: auto; border-left: none; border-top: 2px solid var(--gold); height: 80vh; }
}

h1 {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  text-align: center;
  color: var(--accent);
  border-bottom: 3px double var(--gold);
  padding-bottom: 0.6rem;
  margin-bottom: 0.3rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.subtitle {
  text-align: center;
  font-style: italic;
  color: var(--ink-light);
  margin-bottom: 1.5rem;
  font-size: 1.05rem;
}

h2 {
  font-family: 'Cinzel', serif;
  font-size: 1.15rem;
  color: var(--accent);
  border-bottom: 1px solid var(--gold);
  padding-bottom: 0.3rem;
  margin: 1.5rem 0 0.8rem;
  letter-spacing: 1px;
}

/* --- Sections --- */
.section {
  background: rgba(255,255,255,0.25);
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}

/* --- Character creation --- */
#creation-section {
  text-align: center;
}

#creation-section p {
  margin-bottom: 0.8rem;
  font-size: 1.05rem;
}

.potion-choice {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin: 0.8rem 0;
}

.potion-choice label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--parchment-dark);
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
}

.potion-choice label:hover {
  background: var(--gold);
  color: #fff;
}

.potion-choice input[type="radio"]:checked + span {
  font-weight: 700;
  color: var(--accent);
}

.btn {
  font-family: 'Cinzel', serif;
  font-size: 0.95rem;
  padding: 0.5rem 1.4rem;
  border: 2px solid var(--gold-dark);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 1px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-light); }

.btn-secondary {
  background: var(--parchment-dark);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--gold); color: #fff; }

.btn-danger {
  background: #6a1a1a;
  color: #fff;
}
.btn-danger:hover { background: var(--accent-light); }

.btn-success {
  background: var(--green);
  color: #fff;
}
.btn-success:hover { background: var(--green-light); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-small {
  font-size: 0.8rem;
  padding: 0.25rem 0.6rem;
}

/* --- Stats --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.stat-card {
  text-align: center;
  background: rgba(255,255,255,0.3);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 0.8rem 0.5rem;
}

.stat-label {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  letter-spacing: 1px;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}

.stat-initial {
  font-size: 0.8rem;
  color: var(--ink-light);
  margin-bottom: 0.2rem;
}

.stat-value {
  font-family: 'Cinzel', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 0.4rem;
}

.stat-effective {
  font-size: 0.8rem;
  color: var(--blue);
  margin-bottom: 0.2rem;
}

.stat-bar-track {
  width: 100%;
  height: 10px;
  background: rgba(44, 24, 16, 0.15);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.4s ease, background 0.4s ease;
}

.stat-bar-fill.hab { background: linear-gradient(90deg, var(--accent), var(--gold)); }
.stat-bar-fill.end { background: linear-gradient(90deg, #a22, #4a4); }
.stat-bar-fill.cha { background: linear-gradient(90deg, var(--blue), var(--gold)); }

.stat-controls {
  display: flex;
  justify-content: center;
  gap: 0.3rem;
}

.stat-controls button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--gold);
  border-radius: 50%;
  background: var(--parchment-dark);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}

.stat-controls button:hover {
  background: var(--gold);
  color: #fff;
}

/* --- Provisions & Potion row --- */
.row-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.row-flex > * {
  flex: 1;
  min-width: 250px;
}

.counter-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.5rem 0;
}

.counter-value {
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  font-weight: 700;
  min-width: 2ch;
  text-align: center;
}

.dose-pips {
  display: flex;
  gap: 0.3rem;
  margin: 0.5rem 0;
}

.dose-pip {
  width: 20px;
  height: 20px;
  border: 2px solid var(--gold-dark);
  border-radius: 50%;
  background: var(--green);
  transition: background 0.3s;
}

.dose-pip.empty {
  background: rgba(44, 24, 16, 0.15);
}

.potion-type-label {
  font-weight: 600;
  color: var(--accent);
  font-size: 1rem;
}

/* --- Combat --- */
.combat-inputs {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.combat-inputs label {
  font-size: 0.85rem;
  font-weight: 600;
  display: block;
  margin-bottom: 0.2rem;
}

.combat-inputs input {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: rgba(255,255,255,0.5);
  font-family: 'Crimson Text', serif;
  font-size: 1rem;
  color: var(--ink);
}

.combat-mode-selector {
  margin-bottom: 0.8rem;
  padding: 0.5rem;
  background: rgba(255,255,255,0.3);
  border-radius: 4px;
  border: 1px solid var(--gold);
}

.combat-mode-selector label {
  margin-right: 1rem;
  font-weight: 600;
}

.combat-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.combat-creature-stats {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  margin-bottom: 0.8rem;
  padding: 0.5rem 0.8rem;
  background: rgba(139, 26, 26, 0.08);
  border-radius: 4px;
  border: 1px solid rgba(139, 26, 26, 0.2);
}

.combat-creature-stats .creature-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  color: var(--accent);
  font-size: 1.1rem;
}

.combat-creature-stats span {
  font-size: 0.95rem;
}

.combat-log {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: rgba(255,255,255,0.3);
  padding: 0.6rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.combat-log:empty::before {
  content: "Aucun combat en cours...";
  color: var(--ink-light);
  font-style: italic;
}

.log-round { color: var(--accent); font-weight: 700; }
.log-hit { color: var(--green); }
.log-hurt { color: var(--accent); }
.log-tie { color: var(--ink-light); font-style: italic; }
.log-luck { color: var(--blue); }
.log-death { color: var(--accent); font-weight: 700; font-size: 1.05rem; }
.log-flee { color: #886a00; font-weight: 600; }
.log-armor { color: var(--gold); }
.log-weapon { color: var(--blue); }
.log-hab-test { color: var(--blue); font-style: italic; }

/* --- Encounters table --- */
.encounters-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.encounters-table th {
  font-family: 'Cinzel', serif;
  background: var(--parchment-dark);
  border: 1px solid var(--gold);
  padding: 0.3rem 0.6rem;
  text-align: left;
  font-size: 0.8rem;
  letter-spacing: 1px;
}

.encounters-table td {
  border: 1px solid var(--gold);
  padding: 0.3rem 0.6rem;
}

.encounters-table tr:nth-child(even) {
  background: rgba(255,255,255,0.15);
}

.result-win { color: var(--green); font-weight: 600; }
.result-flee { color: #886a00; font-weight: 600; }
.result-loss { color: var(--accent); font-weight: 600; }

/* --- Equipment --- */
.equipment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.equipment-card {
  background: rgba(255,255,255,0.3);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 1rem;
  position: relative;
}

.equipment-card.equipped {
  border-color: var(--green);
  background: rgba(45, 106, 45, 0.08);
}

.equipment-card.broken {
  border-color: var(--accent);
  background: rgba(139, 26, 26, 0.08);
}

.equipment-card h4 {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.equipment-stats {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.durability-bar {
  width: 100%;
  height: 8px;
  background: rgba(44, 24, 16, 0.15);
  border-radius: 4px;
  overflow: hidden;
  margin: 0.3rem 0;
}

.durability-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--green), var(--gold));
  transition: width 0.3s ease;
}

.durability-fill.low {
  background: linear-gradient(90deg, #a22, var(--accent));
}

.equipment-actions {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.equipment-actions button {
  flex: 1;
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
}

.inventory-list {
  list-style: none;
  margin: 0.5rem 0;
}

.inventory-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px dotted var(--gold);
}

.inventory-list li:last-child { border-bottom: none; }

.inventory-list .remove-item {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 0.3rem;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.inventory-list .remove-item:hover { opacity: 1; }

.add-item-row {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.add-item-row input {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: rgba(255,255,255,0.5);
  font-family: 'Crimson Text', serif;
  font-size: 0.95rem;
  color: var(--ink);
}

textarea.notes {
  width: 100%;
  min-height: 100px;
  padding: 0.6rem;
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: rgba(255,255,255,0.4);
  font-family: 'Crimson Text', serif;
  font-size: 0.95rem;
  color: var(--ink);
  resize: vertical;
}

/* --- Dice animation --- */
.dice-result {
  display: inline-flex;
  gap: 0.3rem;
  margin: 0 0.3rem;
}

.die {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--ink);
  border-radius: 5px;
  background: #fff;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
}

@keyframes diceRoll {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(15deg) scale(1.1); }
  50% { transform: rotate(-10deg) scale(1.05); }
  75% { transform: rotate(5deg) scale(1.1); }
}

.die.rolling {
  animation: diceRoll 0.4s ease-in-out;
}

.footer {
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 0.8rem;
  border-top: 2px double var(--gold);
}

.hidden { display: none !important; }

@media (max-width: 900px) {
  .page { padding: 1rem; }
  h1 { font-size: 1.3rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .combat-inputs { grid-template-columns: 1fr; }
  .row-flex { flex-direction: column; }
  .equipment-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .page { padding: 0.75rem; }
  h1 { font-size: 1.1rem; }
  .stats-grid { grid-template-columns: 1fr; }
  .combat-inputs { grid-template-columns: 1fr; }
  .row-flex { flex-direction: column; }
  .equipment-grid { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .page { box-shadow: none; padding: 1rem; }
  .btn, .stat-controls, .add-item-row, .combat-buttons, #creation-section,
  .remove-item, .footer { display: none !important; }
}
