:root {
  --bg: #14110f;
  --panel: #1e1a17;
  --panel2: #26211d;
  --ink: #e9e0d4;
  --muted: #a2968550;
  --muted2: #b8ab99;
  --accent: #c9822e;
  --accent2: #7fae7a;
  --danger: #c0503f;
  --line: #3a322b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}
.hidden { display: none !important; }
button {
  background: var(--accent); color: #1a1310; border: none; border-radius: 7px;
  padding: 8px 12px; font: inherit; font-size: 14px; cursor: pointer; font-weight: 600;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted2); border: 1px solid var(--line); }
input, textarea {
  background: #100d0b; color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 9px 11px; font: inherit; width: 100%;
}
textarea { resize: vertical; }
h1, h2, h3 { font-family: "Trajan Pro", Georgia, serif; letter-spacing: .5px; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.btnrow button { flex: 1; white-space: nowrap; }
hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
.err { color: var(--danger); min-height: 18px; }

/* Login */
.login { display: grid; place-items: center; height: 100%; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 30px; width: min(420px, 100%); text-align: center; }
.login-card h1 { font-size: 52px; margin: 0; color: var(--accent); }
.login-card .tag { color: var(--muted2); margin-top: 0; }
.login-card input { margin: 8px 0; }
.login-card button { width: 100%; margin-top: 6px; padding: 11px; }

/* App layout */
.app { display: grid; grid-template-columns: 300px 1fr 300px; height: 100vh; gap: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px; }
.sidebar.right { border-right: none; border-left: 1px solid var(--line); }
.panel { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.panel h2 { margin: 0 0 8px; font-size: 15px; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; }
.panel h3 { margin: 8px 0 4px; font-size: 13px; color: var(--muted2); }

.center { display: flex; flex-direction: column; min-width: 0; }
.scene { padding: 14px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(#241d17, #1a1512); }
.scene .title { font-family: Georgia, serif; font-size: 18px; color: var(--accent); }
.scene .loc { color: var(--muted2); font-size: 13px; }
.scene .desc { color: var(--ink); font-size: 14px; margin-top: 4px; }
.scene .combat { color: var(--danger); font-size: 13px; margin-top: 4px; font-weight: 600; }

.mapbar { display: flex; gap: 8px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: var(--panel); }
.mapbar button { padding: 5px 12px; font-size: 13px; }
.mappanel { padding: 12px 18px; border-bottom: 1px solid var(--line); background: #17130f; }
.mapframe { display: inline-block; background: radial-gradient(circle at 40% 30%, #2c2117, #191108); border: 3px double var(--accent); border-radius: 12px; padding: 10px; box-shadow: inset 0 0 30px #0008; }
.maptiles { display: grid; gap: 0; background: #0d0b08; border: 1px solid #4a3a28; border-radius: 6px; overflow: hidden; }
.maptile { width: 42px; height: 42px; display: grid; place-items: center; font-size: 26px; font-family: "Segoe UI Emoji", "Apple Color Emoji", sans-serif; box-shadow: inset 0 0 0 1px #ffffff08; }
.maplegend { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; max-width: 260px; }
.maplegend .lg { font-size: 12px; color: var(--muted2); background: #100d0b; border: 1px solid var(--line); border-radius: 12px; padding: 1px 8px; }
.maplocs { margin-top: 12px; }
.maplocs-h { font-size: 12px; color: var(--muted2); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.maploc { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; font-size: 13px; }
.maploc.here { color: var(--accent); font-weight: 700; }
.maploc .note { color: var(--muted2); font-size: 12px; }

.quest { padding: 4px 0; font-size: 13px; border-bottom: 1px solid var(--line); }
.quest:last-child { border-bottom: none; }
.quest .t { display: flex; gap: 6px; align-items: baseline; }
.quest .badge { font-size: 11px; padding: 0 6px; border-radius: 10px; border: 1px solid var(--line); }
.quest.done .t { text-decoration: line-through; color: var(--muted2); }
.quest.done .badge { color: var(--accent2); border-color: var(--accent2); }
.quest.failed .t { color: var(--danger); }
.quest .d { color: var(--muted2); font-size: 12px; margin-top: 1px; }

.npc { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; border-bottom: 1px solid var(--line); }
.npc:last-child { border-bottom: none; }
.npc .disp { font-size: 11px; padding: 0 7px; border-radius: 10px; border: 1px solid var(--line); }
.npc .disp.friendly { color: var(--accent2); border-color: var(--accent2); }
.npc .disp.hostile { color: var(--danger); border-color: var(--danger); }

.shop-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.shop-item .info { flex: 1; }
.shop-item .price { color: var(--accent); font-weight: 700; white-space: nowrap; }
.shop-item button { padding: 4px 12px; font-size: 13px; flex: none; }

.feed { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 90%; }
.msg .who { font-size: 12px; color: var(--muted2); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; }
.msg.dm .body { background: #241d16; border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 8px; }
.msg.player { align-self: flex-end; text-align: right; }
.msg.player .body { background: #1d2620; border-right: 3px solid var(--accent2); padding: 8px 12px; border-radius: 8px; display: inline-block; text-align: left; }
.msg.dice .body { color: var(--accent2); font-family: ui-monospace, monospace; font-size: 13px; }
.msg.sheet .body { color: var(--muted2); font-style: italic; font-size: 13px; }
.msg.system { align-self: center; color: var(--muted2); font-size: 12px; font-style: italic; }
.msg .body b, .msg .body strong { color: var(--accent); }

.composer { border-top: 1px solid var(--line); padding: 12px 18px; display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--panel); }
.composer textarea { flex: 1; min-width: 200px; }
.composer button { padding: 11px 20px; }
.access-note { flex-basis: 100%; color: var(--accent); font-size: 13px; margin-bottom: 6px; }
.dicetray { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.dicetray button { padding: 8px 0; font-size: 14px; font-weight: 700; background: #100d0b; color: var(--ink); border: 1px solid var(--line); }
.dicetray button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: #241d16; }
.dicetray button:active:not(:disabled) { transform: translateY(1px); }
.dicetray button:disabled { opacity: 0.32; cursor: not-allowed; }
.dicetray button.req { border-color: var(--accent); color: var(--accent); background: #2e2213; box-shadow: 0 0 0 2px var(--accent), 0 0 12px #c9822e88; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 2px var(--accent), 0 0 6px #c9822e55; } 50% { box-shadow: 0 0 0 2px var(--accent), 0 0 16px #c9822eaa; } }
.dice-note { font-size: 12px; color: var(--muted2); margin-top: 8px; text-align: center; }
.tone-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.tone-row label { font-size: 12px; color: var(--muted2); text-transform: uppercase; letter-spacing: 1px; }
.tone-row select { flex: 1; background: #100d0b; color: var(--ink); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; font: inherit; font-size: 13px; }
.os-item { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); }
.os-item:last-child { border-bottom: none; }
.os-info { flex: 1; }
.os-actions { display: flex; gap: 6px; flex: none; }
.os-actions button { padding: 4px 10px; font-size: 12px; }

/* Sheet */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0; }
.stat { background: #100d0b; border: 1px solid var(--line); border-radius: 7px; text-align: center; padding: 5px; }
.stat .k { font-size: 11px; color: var(--muted2); }
.stat .v { font-size: 18px; font-weight: 700; }
.stat .m { font-size: 11px; color: var(--accent2); }
.bar { height: 8px; background: #100d0b; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: var(--danger); }
.kv { display: flex; justify-content: space-between; font-size: 13px; margin: 2px 0; }
.kv .muted { color: var(--muted2); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { background: #100d0b; border: 1px solid var(--line); border-radius: 20px; padding: 1px 9px; font-size: 12px; }
.chip.cond { border-color: var(--danger); color: var(--danger); }
.chip.away { border-color: var(--accent); color: var(--accent); }

.member { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.member:last-child { border-bottom: none; }
.member .hp { color: var(--muted2); font-size: 12px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: var(--muted); }
.dot.on { background: var(--accent2); }
.dot.away { background: var(--accent); }
.dm-status { margin-top: 8px; font-size: 13px; color: var(--muted2); }
.pending .req { display: flex; gap: 5px; align-items: center; margin: 5px 0; font-size: 13px; }
.pending .req span { flex: 1; }
.pending .req button { padding: 3px 8px; font-size: 12px; flex: none; }

/* Modal */
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.modal-card label { display: block; font-size: 12px; color: var(--muted2); margin: 8px 0 2px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .sidebar { max-height: 30vh; }
}
