:root {
  --bg: #0e0f0c;
  --bg-2: #171914;
  --panel: #1c1f18;
  --border: #33382b;
  --text: #d8d6c8;
  --muted: #8c8b7c;
  --accent: #b5c42b;
  --danger: #c8372d;
  --warn: #d9902a;
  --ok: #5fa35a;
  --info: #4f8fb8;
  --radius: 4px;
  --font: 'Roboto Mono', ui-monospace, monospace;
  --font-title: 'Special Elite', 'Courier New', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.08 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 80% 50% at 15% 0%, rgba(181, 196, 43, 0.08), transparent 70%),
    radial-gradient(ellipse 60% 60% at 100% 100%, rgba(120, 40, 25, 0.14), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 var(--font);
}

body.low-hp { box-shadow: inset 0 0 120px rgba(200, 55, 45, 0.35); }

h1, h2, h3 { font-family: var(--font-title); font-weight: normal; letter-spacing: 0.04em; margin: 0 0 0.6em; }
h2 { font-size: 1.15rem; color: var(--accent); }
h3 { font-size: 1rem; color: var(--muted); margin-top: 1em; }

a { color: var(--accent); }
code { background: var(--bg-2); padding: 0 4px; }

.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.error { color: var(--danger); }
.prewrap { white-space: pre-wrap; }
.nowrap { white-space: nowrap; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .brand { font-family: var(--font-title); font-size: 1.3rem; color: var(--accent); flex: 1; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px; }

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .panel { margin-bottom: 0; }
.grid-2 { margin-bottom: 16px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row.end { justify-content: flex-end; }
.row.end > * { flex: 0 0 auto; }

label { display: block; margin-bottom: 10px; color: var(--muted); font-size: 0.9em; }

input, select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
textarea { resize: vertical; }

.btn {
  display: inline-block;
  padding: 8px 14px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn-primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: bold; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger { border-color: var(--danger); color: #f2b3ad; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-small { padding: 5px 10px; font-size: 0.8em; }
.btn-tiny { padding: 2px 7px; font-size: 0.75em; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; }
.link-btn:hover { color: var(--danger); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.8rem;
  font-family: var(--font);
  text-transform: uppercase;
}
.badge-danger { border-color: var(--danger); color: var(--danger); animation: pulse 1.6s infinite; }

.alert { border: 1px solid var(--warn); color: var(--warn); padding: 10px; margin-bottom: 16px; border-radius: var(--radius); }

.login-page { display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 380px; }
.title { font-size: 3rem; color: var(--accent); text-align: center; margin: 0; text-shadow: 0 0 18px rgba(181, 196, 43, 0.35); }
.title-sm { font-size: 2rem; margin: 0; }
.subtitle { text-align: center; color: var(--muted); margin-bottom: 24px; }
.login-box .btn { width: 100%; margin-top: 6px; }

.stat { margin-bottom: 12px; }
.stat-head { display: flex; justify-content: space-between; font-size: 0.85em; color: var(--muted); }
.stat-val { color: var(--text); }
.bar { height: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 2px; overflow: hidden; }
.bar > div { height: 100%; transition: width 0.5s ease; }
.bar.mini { height: 6px; margin: 4px 0; }
.bar-hp > div { background: linear-gradient(90deg, #8c241d, var(--danger)); }
.bar-infection > div { background: linear-gradient(90deg, #4d6b1a, #8fbf2a); }
.bar-hunger > div { background: linear-gradient(90deg, #8a5a1c, var(--warn)); }
.bar-thirst > div { background: linear-gradient(90deg, #284f6c, var(--info)); }
.bar.critical { animation: pulse 1.2s infinite; border-color: var(--danger); }

@keyframes pulse { 50% { opacity: 0.55; } }

.identity { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.identity p { margin: 4px 0 0; }

.equipped-list { list-style: none; padding: 0; margin: 0; }
.equipped-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); }

.cat-tag { font-size: 0.7em; text-transform: uppercase; padding: 1px 6px; border: 1px solid var(--border); border-radius: 2px; color: var(--muted); margin-right: 6px; }
.cat-arme { border-color: var(--danger); color: #e0857d; }
.cat-soin { border-color: var(--ok); color: #9ad296; }
.cat-armure { border-color: var(--info); color: #8fc0e0; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: normal; color: var(--muted); font-size: 0.8em; text-transform: uppercase; border-bottom: 1px solid var(--border); padding: 6px; }
.table td { padding: 8px 6px; border-bottom: 1px solid #262a20; vertical-align: top; }
.table tr.is-equipped td:first-child { border-left: 3px solid var(--accent); }

.events { list-style: none; padding: 0; margin: 0; max-height: 360px; overflow-y: auto; }
.events.compact { max-height: 240px; }
.event { display: flex; gap: 10px; padding: 6px 8px; border-left: 3px solid var(--border); margin-bottom: 4px; background: var(--bg-2); }
.event time { color: var(--muted); font-size: 0.8em; white-space: nowrap; padding-top: 2px; }
.event span { flex: 1; }
.event-danger { border-color: var(--danger); }
.event-alerte { border-color: var(--warn); }
.event-soin { border-color: var(--ok); }
.event-loot { border-color: var(--info); }
.event-mj { border-color: var(--accent); }
.event-mj span { font-style: italic; }

#notes { margin-bottom: 8px; }

.mj-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.mj-layout aside { position: sticky; top: 70px; }

.roster { list-style: none; padding: 0; margin: 0; }
.roster-item { padding: 8px; border: 1px solid transparent; border-radius: var(--radius); cursor: pointer; margin-bottom: 4px; }
.roster-item:hover { background: var(--bg-2); }
.roster-item.active { border-color: var(--accent); background: var(--bg-2); }
.roster-name { font-weight: bold; }

.identity-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
.identity-form .full { grid-column: 1 / -1; }

.stat-control { display: flex; align-items: flex-end; gap: 8px; }
.stat-control .stat { flex: 1; }
.stat-control .quick { display: flex; gap: 3px; margin-bottom: 12px; }

.stat-form, .item-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.stat-form > *, .item-form > * { margin-top: 0; width: auto; }
.stat-form select { flex: 1 1 140px; }
.stat-form input[name=amount] { width: 70px; }
.stat-form input[name=reason] { flex: 2 1 180px; }
.item-form select, .item-form input[name=name] { flex: 1 1 160px; }
.item-form input[type=number] { width: 80px; }
.item-form .wide { flex: 1 1 100%; }

#message-form textarea { margin-bottom: 8px; }

dialog { background: transparent; border: 0; padding: 0; width: min(460px, 92vw); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }

#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { padding: 10px 14px; background: var(--panel); border: 1px solid var(--ok); border-radius: var(--radius); }
.toast-error { border-color: var(--danger); color: #f2b3ad; }

@media (max-width: 800px) {
  .grid-2, .mj-layout { grid-template-columns: 1fr; }
  .mj-layout aside { position: static; }
  .topbar { padding: 10px 16px; }
  .title { font-size: 2.3rem; }
  .table { font-size: 0.85em; }
}

.challenges { list-style: none; padding: 0; margin: 12px 0 0; }
.challenge { display: flex; align-items: center; gap: 10px; padding: 6px 8px; background: var(--bg-2); margin-bottom: 4px; border-radius: var(--radius); }
.challenge-name { flex: 1; }
.challenge-name .small { display: block; }
.challenge-status { font-size: 0.75em; text-transform: uppercase; padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; }
.status-pending { border-color: var(--warn); color: var(--warn); animation: pulse 1.6s infinite; }
.status-success { border-color: var(--ok); color: #9ad296; }
.status-failed { border-color: var(--danger); color: #f2b3ad; }
.status-cancelled { color: var(--muted); }

.game-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.85);
  animation: game-in 0.4s ease;
}
@keyframes game-in { from { opacity: 0; transform: scale(1.03); } }
.game-window {
  width: min(640px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 18px;
  background:
    repeating-linear-gradient(0deg, rgba(120, 255, 120, 0.03) 0 1px, transparent 1px 3px),
    #070a06;
  border: 1px solid #3f6b2a;
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(120, 220, 80, 0.15);
  color: #b8f5a0;
}
.game-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.game-title { font-family: var(--font-title); font-size: 1.3rem; color: #c9ff8a; }
.game-timer { font-size: 1.3rem; font-weight: bold; color: #c9ff8a; }
.game-timer.urgent { color: var(--danger); animation: pulse 0.8s infinite; }
.game-help { color: #87b878; font-size: 0.9em; }
.game-area { margin: 12px 0; }
.game-actions { display: flex; justify-content: flex-end; }
.game-result { text-align: center; padding: 24px 0; }
.game-result-title { font-family: var(--font-title); font-size: 2.6rem; letter-spacing: 0.1em; }
.game-result.ok .game-result-title { color: #9dff6a; text-shadow: 0 0 16px rgba(157, 255, 106, 0.5); }
.game-result.ko .game-result-title { color: var(--danger); text-shadow: 0 0 16px rgba(200, 55, 45, 0.5); }

.term-head { color: #c9ff8a; margin-bottom: 8px; font-size: 0.9em; letter-spacing: 0.05em; }
.term-attempts { margin-bottom: 10px; color: #c9ff8a; }
.term-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px 16px; }
.term-line { white-space: nowrap; overflow: hidden; }
.term-junk { color: #4f7a40; }
.term-word { background: none; border: 0; padding: 0 2px; color: #b8f5a0; font: inherit; cursor: pointer; }
.term-word:hover { background: #b8f5a0; color: #070a06; }
.term-word:disabled { color: #4f7a40; text-decoration: line-through; cursor: default; background: none; }
.term-log { margin-top: 12px; min-height: 60px; font-size: 0.9em; }
.term-log .ok { color: #9dff6a; }
.term-log .ko { color: var(--danger); }

.puzzle-grid { display: grid; gap: 6px; width: min(340px, 100%); margin: 0 auto 8px; }
.puzzle-tile {
  aspect-ratio: 1;
  background: #13200e; border: 1px solid #3f6b2a; border-radius: 4px;
  color: #c9ff8a; font: bold 1.4rem var(--font); cursor: pointer;
}
.puzzle-tile:hover { border-color: #9dff6a; }
.puzzle-tile.empty { background: transparent; border-style: dashed; cursor: default; }
.puzzle-grid.solved .puzzle-tile:not(.empty) { border-color: #9dff6a; box-shadow: 0 0 10px rgba(157, 255, 106, 0.4); }

.seq-grid { display: grid; gap: 10px; width: min(320px, 100%); margin: 0 auto; }
.seq-grid.locked { pointer-events: none; }
.seq-pad {
  aspect-ratio: 1;
  border: 2px solid hsl(var(--hue) 60% 35%);
  border-radius: 8px;
  background: hsl(var(--hue) 50% 12%);
  cursor: pointer;
  transition: background 0.1s, box-shadow 0.1s;
}
.seq-pad.lit { background: hsl(var(--hue) 90% 60%); box-shadow: 0 0 24px hsl(var(--hue) 90% 60%); }

.lock-pins { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.lock-pin { width: 14px; height: 30px; border: 1px solid #3f6b2a; border-radius: 3px; }
.lock-pin.set { background: #9dff6a; box-shadow: 0 0 8px #9dff6a; }
.lock-track { position: relative; height: 34px; background: #13200e; border: 1px solid #3f6b2a; border-radius: 4px; overflow: hidden; }
.lock-track.hit { border-color: #9dff6a; }
.lock-track.miss { border-color: var(--danger); background: #2a0f0c; }
.lock-zone { position: absolute; top: 0; bottom: 0; background: rgba(157, 255, 106, 0.35); border-left: 1px solid #9dff6a; border-right: 1px solid #9dff6a; }
.lock-cursor { position: absolute; top: -2px; bottom: -2px; width: 4px; margin-left: -2px; background: #fff; box-shadow: 0 0 8px #fff; }
.lock-btn { display: block; margin: 14px auto 0; }

.panel::before,
.panel::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: var(--accent);
  border-style: solid;
  opacity: 0.55;
  pointer-events: none;
}
.panel::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.panel::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

body::before,
body::after {
  content: '';
  position: fixed;
  top: 0;
  bottom: 0;
  width: 14px;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(-45deg, rgba(181, 196, 43, 0.16) 0 10px, transparent 10px 20px);
  opacity: 0.7;
}
body::before { left: 0; border-right: 1px solid rgba(181, 196, 43, 0.18); }
body::after { right: 0; border-left: 1px solid rgba(181, 196, 43, 0.18); }
.topbar, .container, .login-box { position: relative; z-index: 1; }
.topbar { position: sticky; }

.portrait {
  width: 120px;
  height: 120px;
  flex-shrink: 0;
  object-fit: cover;
  border: 1px solid var(--border);
  outline: 1px solid var(--accent-dim, #6f7a1c);
  outline-offset: 3px;
  background: var(--bg-2);
  filter: saturate(0.85) contrast(1.05);
}
.identity-main { display: flex; align-items: center; gap: 20px; }
.avatar {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.roster-top { display: flex; align-items: center; gap: 10px; }
.roster-top > div { flex: 1; min-width: 0; }
.image-field { display: flex; gap: 12px; align-items: flex-end; }
.image-field label { flex: 1; margin-bottom: 0; }
.image-field .portrait { width: 64px; height: 64px; outline-offset: 2px; }
.image-field .portrait.empty, .portrait.empty { display: none; }

@media (max-width: 800px) {
  body::before, body::after { display: none; }
  .portrait { width: 84px; height: 84px; }
}
.image-field { margin-bottom: 12px; }
form + h2 { margin-top: 18px; }

h2.spaced { margin-top: 18px; }
.char-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.char-stat { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--bg-2); border-left: 2px solid var(--accent); }
.char-stat strong { font-family: var(--font-title); font-size: 1.15rem; color: var(--accent); }

.dice-grid { margin: 0 0 8px; align-items: start; }
.stat-list { margin-bottom: 10px; }
.stat-row { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.stat-name { flex: 1; }
.stat-num { min-width: 34px; text-align: center; font-family: var(--font-title); color: var(--accent); }
.roll-form .row label { margin-bottom: 8px; }
.roll-form > input { margin-bottom: 10px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { margin: 0; }

.dice-window {
  width: min(420px, 100%);
  padding: 26px 22px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  position: relative;
}
.dice-title { font-family: var(--font-title); font-size: 1.6rem; color: var(--accent); }
.dice-sub { color: var(--muted); margin-top: 4px; }
.dice-die {
  display: grid; place-items: center;
  width: 130px; height: 130px;
  margin: 24px auto 10px;
  background: var(--bg-2);
  border: 2px solid var(--accent);
  color: var(--text);
  font: 2.6rem var(--font-title);
  border-radius: 22px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.2s;
}
.dice-die:hover:not(:disabled) { transform: scale(1.06); background: #262a1e; }
.dice-die:disabled { cursor: default; }
.dice-die.rolling { animation: dice-shake 0.25s infinite; }
.dice-die.ok { border-color: var(--ok); color: #a5e09a; }
.dice-die.ko { border-color: var(--danger); color: #f0a196; }
.dice-die.crit { box-shadow: 0 0 30px currentColor; }
@keyframes dice-shake {
  25% { transform: rotate(-12deg) scale(1.05); }
  75% { transform: rotate(12deg) scale(0.95); }
}
.dice-hint { color: var(--muted); min-height: 1.5em; }
.dice-detail { margin-top: 8px; font-size: 1.05rem; }
.dice-verdict { font-family: var(--font-title); font-size: 2rem; margin: 10px 0 16px; letter-spacing: 0.06em; }
.dice-verdict.ok { color: #9dff6a; }
.dice-verdict.ko { color: var(--danger); }
.dice-actions { display: flex; justify-content: center; }
