/* ═══════════════════════════════════════
   SADS – Spiel Aus Du Sau
   Pirate P&P System Stylesheet
   Mobile-First, Dark Pirate Theme
   ═══════════════════════════════════════ */

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

/* ── CSS Variables ── */
:root {
  --bg: #110e0a;
  --bg2: #1a1410;
  --card: rgba(26,20,14,.92);
  --card-hover: rgba(34,26,18,.95);
  --gold: #c9a84c;
  --gold-dim: #a08030;
  --gold-glow: rgba(201,168,76,.25);
  --red: #8b2020;
  --red-bright: #c0392b;
  --green: #2d6b3f;
  --blue: #2a5a8a;
  --text: #e8dcc8;
  --text2: #c4b89a;
  --muted: #8a7e6a;
  --border: rgba(201,168,76,.12);
  --border-h: rgba(201,168,76,.35);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.6);
  --transition: .2s cubic-bezier(.4,0,.2,1);
  --font-head: 'Cinzel', serif;
  --font-body: 'Crimson Text', 'Georgia', serif;
  --header-h: 56px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body::before {
  content: '';
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(201,168,76,.06) 0%, transparent 60%);
  pointer-events: none; z-index: 0;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--gold); text-decoration: none; transition: color var(--transition); }
a:hover { color: #e6c35a; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 4px; }

/* ── Typography ── */
h1, h2, h3, h4 { font-family: var(--font-head); color: var(--gold); font-weight: 700; line-height: 1.2; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
p { margin-bottom: .8em; }

/* ── Header / Nav ── */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(17,14,10,.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.site-header .logo-sm { height: 40px; width: 40px; object-fit: contain; border-radius: 6px; }
.site-header .site-title {
  font-family: var(--font-head); font-size: 1.1rem; color: var(--gold);
  margin-left: 10px; white-space: nowrap;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-left a { display: flex; align-items: center; gap: 10px; }

nav { display: flex; gap: 4px; }
nav a {
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-family: var(--font-head); font-size: .75rem; letter-spacing: .5px;
  color: var(--text2); transition: all var(--transition); text-transform: uppercase;
}
nav a:hover, nav a.active { color: var(--gold); background: rgba(201,168,76,.1); }

/* Mobile nav */
.nav-toggle { display: none; background: none; border: none; color: var(--gold); font-size: 1.5rem; cursor: pointer; padding: 8px; }
@media (max-width: 600px) {
  .nav-toggle { display: block; }
  nav {
    display: none; position: absolute; top: var(--header-h); right: 0;
    background: rgba(17,14,10,.98); border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    flex-direction: column; padding: 8px; min-width: 180px;
    box-shadow: var(--shadow-lg);
  }
  nav.open { display: flex; }
  nav a { padding: 12px 16px; font-size: .85rem; }
  .site-header .site-title { font-size: .95rem; }
}

/* ── Main Content ── */
.main { position: relative; z-index: 1; max-width: 1200px; margin: 0 auto; padding: 16px; }
.main-wide { max-width: 1400px; }

/* ── Hero Section ── */
.hero {
  text-align: center; padding: 40px 16px;
  background: radial-gradient(ellipse at center, rgba(201,168,76,.08) 0%, transparent 70%);
}
.hero-logo { max-width: 320px; margin: 0 auto 24px; filter: drop-shadow(0 8px 24px rgba(0,0,0,.6)); }
.hero h1 { font-size: 2.5rem; margin-bottom: 8px; text-shadow: 0 2px 8px rgba(0,0,0,.5); }
.hero .subtitle { font-size: 1.2rem; color: var(--text2); margin-bottom: 24px; font-style: italic; }
.hero-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius-sm);
  font-family: var(--font-head); font-size: .85rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  cursor: pointer; border: none; transition: all var(--transition);
  text-decoration: none;
}
.btn:active { transform: scale(.95); }
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dim));
  color: #1a1410; box-shadow: 0 2px 12px var(--gold-glow);
}
.btn-primary:hover { background: linear-gradient(135deg, #e6c35a, var(--gold)); color: #1a1410; box-shadow: 0 4px 20px var(--gold-glow); }
.btn-secondary {
  background: transparent; color: var(--gold);
  border: 1px solid var(--gold-dim);
}
.btn-secondary:hover { background: rgba(201,168,76,.1); border-color: var(--gold); color: var(--gold); }
.btn-danger { background: transparent; color: var(--red-bright); border: 1px solid var(--red); }
.btn-danger:hover { background: rgba(192,57,43,.15); }
.btn-sm { padding: 6px 14px; font-size: .75rem; }
.btn-icon { padding: 8px; min-width: 36px; justify-content: center; }

/* ── Cards ── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}
.card:hover { border-color: var(--border-h); background: var(--card-hover); }
.card h3 { margin-bottom: 8px; }
.card p { color: var(--text2); font-size: .95rem; }

.card-grid { display: grid; gap: 16px; }
@media (min-width: 600px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }

/* ── Sections (collapsible, like DnD ref) ── */
.sec {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 12px;
  box-shadow: var(--shadow); transition: all var(--transition);
  overflow: visible;
}
.sec:hover { border-color: var(--border-h); }
.sec-hd {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; cursor: pointer;
  user-select: none; -webkit-user-select: none;
}
.sec-hd h3 { flex: 1; margin: 0; font-size: 1rem; }
.sec-grip {
  color: var(--muted); font-size: .9rem; cursor: grab;
  opacity: .4; transition: opacity var(--transition);
  touch-action: none;
}
.sec-grip:hover { opacity: 1; }
.sec-chevron {
  color: var(--muted); font-size: .8rem;
  transition: transform var(--transition);
}
.sec.collapsed .sec-chevron { transform: rotate(-90deg); }
.sec-bd { padding: 0 16px 16px; overflow: visible; }
.sec.collapsed .sec-bd { display: none; }

/* ── Drag & Drop ── */
.sec.dragging { opacity: .25; transform: scale(.97); }
.drag-ghost {
  position: fixed; pointer-events: none; z-index: 999;
  opacity: .85; transform: rotate(1.5deg); max-width: 320px;
  box-shadow: var(--shadow-lg);
  background: var(--card); border: 2px solid var(--gold);
  border-radius: var(--radius); overflow: hidden;
}
.drag-ghost .sec-hd {
  padding: 10px 14px; display: flex; align-items: center; gap: 8px;
}
.drag-ghost .sec-hd h3 { font-size: .9rem; margin: 0; }
.drop-indicator {
  position: fixed; z-index: 998; pointer-events: none;
  height: 4px; border-radius: 2px;
  background: var(--gold);
  box-shadow: 0 0 12px var(--gold-glow), 0 0 4px var(--gold);
  display: none;
  transition: top .12s ease, left .12s ease, width .12s ease;
}
.drop-indicator::before, .drop-indicator::after {
  content: ''; position: absolute; top: -4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 8px var(--gold-glow);
}
.drop-indicator::before { left: -6px; }
.drop-indicator::after { right: -6px; }

/* ── Two Column Layout ── */
.sheet-grid { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 768px) {
  .sheet-grid { flex-direction: row; }
  .sheet-col { flex: 1; min-width: 0; }
}

/* ── Inputs ── */
.ip, .sl, .ta {
  background: rgba(0,0,0,.3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  color: var(--text); width: 100%;
  transition: all var(--transition);
}
.ip:focus, .sl:focus, .ta:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
}
.ta { resize: vertical; min-height: 80px; }
.sl { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23c9a84c' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.ip-num { width: 60px; text-align: center; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.form-row { display: flex; gap: 8px; align-items: end; margin-bottom: 8px; flex-wrap: wrap; }
.form-group { flex: 1; min-width: 100px; }

/* ── Stat Boxes ── */
.stat-box {
  background: rgba(0,0,0,.25); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 6px;
  text-align: center; overflow: visible;
}
.stat-val { font-family: var(--font-head); font-size: 1.6rem; color: var(--gold); line-height: 1; }
.stat-mod { font-size: .85rem; color: var(--text2); margin-top: 2px; word-break: break-word; }
.stat-label { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }
/* Default: 3 columns (safe for all narrow containers) */
.attr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 360px) { .attr-grid { grid-template-columns: repeat(2, 1fr); } }
/* Only 5 cols on very wide screens where each sheet-col has 650px+ */
@media (min-width: 1400px) { .attr-grid { grid-template-columns: repeat(5, 1fr); } }
.combat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 1400px) { .combat-grid { grid-template-columns: repeat(4, 1fr); } }

/* ── Skill Rows ── */
.skill-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.skill-row:hover { background: rgba(201,168,76,.05); }
.skill-name { flex: 1; font-size: .9rem; }
.skill-attr { font-size: .7rem; color: var(--muted); text-transform: uppercase; width: 28px; }
.skill-dots { display: flex; gap: 4px; }
.skill-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--gold-dim); cursor: pointer;
  transition: all var(--transition);
}
.skill-dot.filled { background: var(--gold); border-color: var(--gold); }
.skill-dot:hover { border-color: var(--gold); transform: scale(1.15); }
.skill-bonus { font-family: var(--font-head); font-size: .85rem; color: var(--gold); width: 28px; text-align: right; }

/* ── Talent Chips ── */
.talent-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(201,168,76,.1); border: 1px solid var(--gold-dim);
  border-radius: 20px; padding: 6px 14px; margin: 3px;
  font-size: .85rem; color: var(--text2); cursor: pointer;
  transition: all var(--transition);
}
.talent-chip.active { background: rgba(201,168,76,.2); border-color: var(--gold); color: var(--gold); }
.talent-chip:hover { border-color: var(--gold); background: rgba(201,168,76,.15); }
.talent-chip .remove { color: var(--red-bright); font-weight: 700; margin-left: 4px; }

/* ── Weapon / Armor Rows ── */
.item-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); margin-bottom: 6px;
  transition: background var(--transition);
}
.item-row:hover { background: rgba(201,168,76,.05); }
.item-name { font-weight: 600; flex: 1; }
.item-detail { font-size: .85rem; color: var(--text2); }
.item-dmg { font-family: var(--font-head); color: var(--gold); font-size: .9rem; }

/* ── HP Bar ── */
.hp-bar-wrap {
  background: rgba(0,0,0,.3); border-radius: var(--radius-sm);
  height: 32px; position: relative; overflow: hidden;
  border: 1px solid var(--border);
}
.hp-bar {
  height: 100%; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--red), var(--green));
  transition: width .4s ease;
}
.hp-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-size: .9rem; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.7);
}

/* ── Rum Points ── */
.rum-dots { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }
.rum-dot {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--gold-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: all var(--transition);
}
.rum-dot.filled { background: var(--gold); border-color: var(--gold); }
.rum-dot:hover { transform: scale(1.15); border-color: var(--gold); }

/* ── Popup / Modal ── */
.popup-ov {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; animation: fadeIn .15s ease;
}
.popup-box {
  background: var(--bg2); border: 1px solid var(--border-h);
  border-radius: var(--radius); padding: 24px;
  max-width: 600px; width: 100%; max-height: 85vh;
  overflow-y: auto; animation: popIn .15s ease;
  box-shadow: var(--shadow-lg);
}
.popup-box h3 { margin-bottom: 12px; }
.popup-close {
  position: absolute; top: 12px; right: 16px;
  background: none; border: none; color: var(--muted);
  font-size: 1.5rem; cursor: pointer; line-height: 1;
}
.popup-close:hover { color: var(--text); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

/* ── Dice Roller ── */
.dice-area { text-align: center; padding: 20px 0; }
.dice-display {
  width: 120px; height: 120px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--red), #6b1515);
  border-radius: 16px; border: 3px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-size: 3rem; color: #fff;
  box-shadow: 0 4px 20px rgba(139,32,32,.4);
  cursor: pointer; user-select: none;
  transition: transform .1s;
  position: relative;
}
.dice-display:active { transform: scale(.92); }
.dice-display.rolling {
  animation: diceShake .1s infinite;
}
.dice-display.crit { border-color: #ffd700; box-shadow: 0 0 30px rgba(255,215,0,.6); }
.dice-display.fail { border-color: var(--red-bright); box-shadow: 0 0 30px rgba(192,57,43,.6); }
@keyframes diceShake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-8deg) scale(1.05); }
  75% { transform: rotate(8deg) scale(1.05); }
}

.dice-history {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  margin-top: 12px; max-height: 120px; overflow-y: auto;
}
.dice-hist-item {
  background: rgba(0,0,0,.3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px 10px;
  font-family: var(--font-head); font-size: .8rem; color: var(--text2);
}
.dice-hist-item.crit { color: #ffd700; border-color: rgba(255,215,0,.3); }
.dice-hist-item.fail { color: var(--red-bright); border-color: rgba(192,57,43,.3); }

.dice-mod-row { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 12px 0; flex-wrap: wrap; }
.dice-result-detail { font-size: .9rem; color: var(--text2); margin-top: 8px; }

/* ── Regelwerk Styles ── */
.rule-section { margin-bottom: 32px; scroll-margin-top: calc(var(--header-h) + 16px); }
.rule-section h2 { border-bottom: 2px solid var(--border); padding-bottom: 8px; margin-bottom: 16px; }
.rule-table {
  width: 100%; border-collapse: collapse; margin: 12px 0;
  font-size: .9rem;
}
.rule-table th {
  background: rgba(201,168,76,.15); color: var(--gold);
  padding: 8px 12px; text-align: left; font-family: var(--font-head);
  font-size: .8rem; text-transform: uppercase; letter-spacing: .5px;
}
.rule-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.rule-table tr:hover td { background: rgba(201,168,76,.03); }
/* ── Regelwerk Sticky Bar (TOC + Search) ── */
.rw-bar {
  position: sticky; top: var(--header-h); z-index: 30;
  background: rgba(17,14,10,.96); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 8px 0; margin: 0 -16px 16px;
  display: flex; align-items: center; gap: 8px;
  padding-left: 16px; padding-right: 16px;
}
.rw-bar-left { position: relative; }
.rw-toc-toggle {
  background: rgba(201,168,76,.1); border: 1px solid var(--gold-dim);
  border-radius: var(--radius-sm); padding: 7px 14px;
  color: var(--gold); font-family: var(--font-head); font-size: .8rem;
  cursor: pointer; transition: all var(--transition);
  white-space: nowrap;
}
.rw-toc-toggle:hover { background: rgba(201,168,76,.2); border-color: var(--gold); }
.rw-toc-dropdown {
  display: none; position: absolute; top: 100%; left: 0; margin-top: 4px;
  background: var(--bg2); border: 1px solid var(--border-h);
  border-radius: var(--radius); padding: 6px;
  min-width: 240px; box-shadow: var(--shadow-lg);
  max-height: 60vh; overflow-y: auto; z-index: 40;
}
.rw-bar.toc-open .rw-toc-dropdown { display: block; animation: fadeIn .12s ease; }
.rw-toc-dropdown a {
  display: block; padding: 7px 12px; border-radius: var(--radius-sm);
  font-size: .85rem; color: var(--text2); transition: all var(--transition);
}
.rw-toc-dropdown a:hover { color: var(--gold); background: rgba(201,168,76,.08); }
.rw-search-wrap { flex: 1; max-width: 300px; }
.rw-search { font-size: .85rem; padding: 7px 12px; }
.rw-search-results {
  display: none; position: sticky; top: calc(var(--header-h) + 48px); z-index: 29;
  background: var(--bg2); border: 1px solid var(--border-h);
  border-radius: var(--radius); margin: -8px 0 12px;
  box-shadow: var(--shadow-lg); max-height: 50vh; overflow-y: auto;
}
.rw-search-item {
  display: block; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text); transition: background var(--transition);
  text-decoration: none;
}
.rw-search-item:hover { background: rgba(201,168,76,.06); }
.rw-search-item:last-child { border-bottom: none; }
.rw-search-item mark { background: rgba(201,168,76,.3); color: var(--gold); border-radius: 2px; padding: 0 2px; }
@media (max-width: 600px) {
  .rw-bar { margin: 0 -16px 12px; }
  .rw-toc-label { display: none; }
  .rw-search-wrap { max-width: none; }
}

.rule-example {
  background: rgba(201,168,76,.05); border-left: 3px solid var(--gold-dim);
  padding: 12px 16px; margin: 12px 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic; color: var(--text2);
}

/* ── Char Sheet Header Bar ── */
.char-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 12px; padding: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.char-bar .sl { width: auto; flex: 1; min-width: 140px; }
.char-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* ── Notizen ── */
.notes-area .ta { min-height: 120px; font-size: .95rem; }

/* ── Footer ── */
.site-footer {
  text-align: center; padding: 24px 16px;
  color: var(--muted); font-size: .85rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ── Utility ── */
.text-gold { color: var(--gold); }
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none !important; }

/* ── Responsive ── */
@media (min-width: 600px) {
  h1 { font-size: 2.5rem; }
  .hero h1 { font-size: 3rem; }
  .main { padding: 24px; }
}
@media (min-width: 768px) {
  .hero { padding: 60px 24px; }
  .hero-logo { max-width: 400px; }
}
@media (min-width: 1024px) {
  .main { padding: 32px; }
}

/* ── iPad / Tablet optimizations ── */
@media (min-width: 768px) and (max-width: 1024px) {
  .skill-dot { width: 20px; height: 20px; }
  .sec-hd { padding: 14px 16px; }
}

/* ── Print ── */
@media print {
  .site-header, .site-footer, .char-bar, .nav-toggle, .btn, .dice-area { display: none; }
  body { background: #fff; color: #000; }
  .sec { break-inside: avoid; border-color: #ccc; background: #fff; }
  .gold, h1, h2, h3 { color: #333; }
}
