/* Escape the Dark Castle — companion app styles.
   Mobile-first, stark black & white to match the game's woodcut art. */

:root {
  --bg:        #050505;
  --bg-panel:  #0d0d0d;
  --card:      #161616;
  --card-edge: #3a3a3a;
  --ink:       #f4f4f4;
  --ink-dim:   #a8a8a8;
  --ink-faint: #6e6e6e;
  --accent:    #ffffff;   /* headings, stat values, active state */
  --field-bg:  #0b0b0b;
  --tap:       48px;
  --radius:    10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: 0.02em; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px calc(12px);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: #000;
  border-bottom: 2px solid var(--accent);
}
.app-title {
  font-size: 1rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
}

/* ---------- Main / panels ---------- */
#app {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(88px + var(--safe-bottom));
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.tab-panel[hidden] { display: none; }
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head h2 {
  font-size: 1.4rem; color: var(--ink);
  text-transform: uppercase; letter-spacing: 0.1em;
}

.hint { color: var(--ink-faint); font-size: 0.8rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.card-list { display: flex; flex-direction: column; gap: 12px; }
.card-subhead {
  color: var(--accent); font-size: 0.95rem; margin-bottom: 10px;
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* ---------- Buttons ---------- */
button { font-family: inherit; cursor: pointer; }
.primary-btn, .secondary-btn, .ghost-btn, .step-btn {
  min-height: var(--tap);
  border-radius: 8px;
  font-size: 1rem;
  padding: 0 16px;
  border: 1px solid transparent;
  transition: filter 0.12s ease, transform 0.05s ease;
}
.primary-btn:active, .secondary-btn:active, .ghost-btn:active, .step-btn:active,
.hp-btn:active, .tab-btn:active { transform: scale(0.97); }
.primary-btn, .step-btn.primary-btn {
  background: var(--accent);
  color: #000;
  font-weight: 700;
  border-color: var(--accent);
}
.secondary-btn, .step-btn {
  background: #222;
  color: var(--ink);
  border-color: var(--card-edge);
}
.ghost-btn {
  background: transparent;
  color: var(--ink-dim);
  border-color: var(--card-edge);
}
.ghost-btn.full, .primary-btn.full { width: 100%; margin-top: 10px; }
.add-row { display: flex; gap: 10px; margin-top: 16px; }
.add-row .primary-btn { flex: 2; }
.add-row .secondary-btn { flex: 1; }

/* ---------- Player count ---------- */
.player-count { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.player-count label { color: var(--ink-dim); font-size: 0.9rem; }
select, .text-input {
  background: var(--field-bg);
  color: var(--ink);
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  min-height: var(--tap);
  padding: 0 12px;
  font-size: 1rem;
  font-family: inherit;
}
select { min-width: 64px; }

/* ---------- Character card ---------- */
.char-card { position: relative; }
.char-card.fallen { opacity: 0.55; }
.char-card.fallen .char-name { text-decoration: line-through; }
.char-card.fallen .char-name::after {
  content: " — fallen"; color: var(--ink-dim); font-size: 0.85rem;
  text-decoration: none; text-transform: uppercase; letter-spacing: 0.06em;
}
.char-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.char-name { font-size: 1.2rem; color: var(--ink); }
.char-tools { display: flex; gap: 4px; }
.icon-btn {
  background: transparent; border: none; color: var(--ink-faint);
  font-size: 1.1rem; min-width: 40px; min-height: 40px; border-radius: 8px;
}
.char-stats { display: flex; gap: 8px; margin-bottom: 12px; }
.stat-chip {
  flex: 1; text-align: center; background: var(--field-bg);
  border: 1px solid var(--card-edge); border-radius: 8px; padding: 8px 4px;
}
.stat-chip .stat-ico { font-size: 1.1rem; display: block; filter: grayscale(1) contrast(1.4); }
.stat-chip .stat-val { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.stat-chip .stat-lbl { font-size: 0.65rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- HP control ---------- */
.hp-control { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.hp-control.large { margin: 8px 0; }
.hp-btn {
  width: var(--tap); height: var(--tap); min-width: var(--tap);
  border-radius: 50%; font-size: 1.6rem; line-height: 1;
  border: 1px solid var(--card-edge); background: var(--field-bg); color: var(--ink);
}
.hp-btn.plus { border-color: var(--ink); }
.hp-btn.minus { color: var(--ink-dim); }
.hp-readout { font-size: 1.5rem; font-weight: 700; letter-spacing: 0.02em; }
.hp-sep { color: var(--ink-faint); margin: 0 2px; }
.hp-bar {
  height: 10px; background: var(--field-bg); border-radius: 6px; overflow: hidden;
  margin-top: 10px; border: 1px solid var(--card-edge);
}
.hp-bar-fill {
  height: 100%; width: 100%;
  background: var(--ink);
  transition: width 0.2s ease;
}
.hp-bar-fill.low { background: #8a8a8a; }
/* Hatched = danger, without relying on colour. */
.hp-bar-fill.critical,
.hp-bar-fill.enemy {
  background: repeating-linear-gradient(45deg, #f4f4f4 0 5px, #454545 5px 10px);
}

/* ---------- Chapter ---------- */
.chapter-tracker { text-align: center; }
.chapter-big {
  display: flex; align-items: baseline; justify-content: center; gap: 10px;
  font-size: 3rem; font-weight: 700; color: var(--accent); margin-bottom: 6px;
}
.chapter-of { font-size: 1.1rem; color: var(--ink-faint); }
.chapter-total-input {
  width: 74px; font-size: 2rem; text-align: center; color: var(--ink);
  padding: 0 4px; min-height: 52px;
  background: var(--field-bg); border: 1px solid var(--card-edge); border-radius: 8px;
}
.chapter-label { width: 100%; margin: 8px 0 14px; text-align: center; }
.chapter-progress {
  height: 12px; background: var(--field-bg); border-radius: 6px; overflow: hidden;
  border: 1px solid var(--card-edge); margin-bottom: 14px;
}
.chapter-bar-fill {
  height: 100%; background: var(--ink);
  transition: width 0.2s ease;
}
.boss-flag {
  color: #000; background: var(--accent); font-weight: 700; margin-bottom: 12px;
  letter-spacing: 0.06em; text-transform: uppercase; padding: 8px 10px;
  border-radius: 6px;
}
.chapter-controls { display: flex; gap: 10px; }
.chapter-controls .step-btn { flex: 1; }

/* ---------- Enemy ---------- */
.enemy-form { display: flex; gap: 8px; align-items: center; }
.enemy-form .text-input { flex: 1; min-width: 0; }
.enemy-form .hp-num { flex: 0 0 72px; text-align: center; }
.enemy-name {
  font-size: 1.3rem; color: var(--ink); text-align: center; margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.06em;
}
.defeated-flag {
  color: #000; background: var(--accent); font-weight: 700; text-align: center;
  margin-top: 10px; padding: 6px 10px; border-radius: 6px;
  text-transform: uppercase; letter-spacing: 0.06em;
}

/* ---------- Dice ---------- */
.dice-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.dice-buttons button { flex: 1 1 auto; filter: grayscale(1); }
.dice-empty { color: var(--ink-faint); font-size: 0.9rem; }
.dice-result { display: flex; flex-direction: column; gap: 8px; }
.roll-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--field-bg); border: 1px solid var(--card-edge);
  border-radius: 8px; padding: 10px 14px;
}
.roll-name { flex: 1; color: var(--ink-dim); }
.roll-face { font-size: 1.8rem; filter: grayscale(1) contrast(1.4); }
.roll-face .block-ico { margin-left: 8px; font-size: 1.4rem; vertical-align: middle; }

/* ---------- Notes ---------- */
.notes-area {
  width: 100%; min-height: 55vh; resize: vertical;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--card-edge); border-radius: var(--radius);
  padding: 14px; font-size: 1rem; font-family: inherit; line-height: 1.5;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center; color: var(--ink-faint); padding: 32px 16px;
  border: 1px dashed var(--card-edge); border-radius: var(--radius);
}

/* ---------- Tab bar ---------- */
.tab-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex;
  background: #000;
  border-top: 2px solid var(--accent);
  padding-bottom: var(--safe-bottom);
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: none; color: var(--ink-faint);
  padding: 8px 0 10px; font-size: 0.72rem; letter-spacing: 0.06em;
  text-transform: uppercase;
  min-height: var(--tap);
  border-top: 2px solid transparent; margin-top: -2px;
}
.tab-btn .tab-icon { font-size: 1.35rem; line-height: 1; filter: grayscale(1) contrast(1.3); }
.tab-btn.active { color: var(--accent); border-top-color: var(--accent); }

/* ---------- Dialog ---------- */
.dialog {
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: var(--bg-panel); color: var(--ink);
  padding: 0; width: min(92vw, 420px); max-width: 92vw;
}
.dialog::backdrop { background: rgba(0,0,0,0.82); }
.dialog form { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.dialog h3 { color: var(--accent); font-size: 1.2rem; text-transform: uppercase; letter-spacing: 0.06em; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.85rem; color: var(--ink-dim); }
.field.small { flex: 1; }
.stat-fields { display: flex; gap: 8px; }
.stat-fields .text-input { text-align: center; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.dialog-actions .ghost-btn, .dialog-actions .primary-btn { flex: 1; }

@media (min-width: 480px) {
  .app-title { font-size: 1.15rem; }
}
