:root {
  --bg: #0d0f14;
  --panel: #141822;
  --panel2: #1a2030;
  --ink: #e8e3d5;
  --dim: #9aa0b4;
  --accent: #c9a45c;
  --accent2: #7b5ea7;
  --danger: #c0392b;
  --ok: #4e9a6d;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 800px at 70% -10%, #1c2233 0%, var(--bg) 55%);
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ---- setup ---- */
#setup { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.setup-card {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid #262d3f;
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
h1 { font-size: 34px; letter-spacing: .5px; margin-bottom: 6px; }
h1 span { color: var(--accent); }
.tagline { color: var(--dim); margin-bottom: 22px; }
.badge {
  display: inline-block; font-size: 12px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--accent2); color: #cdb7f0; margin-bottom: 18px;
}
.badge.off { border-color: var(--danger); color: #e89a92; }

.field { display: block; margin-bottom: 16px; }
.field span, .field-label { display: block; font-size: 13px; color: var(--dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; }
input {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid #2c3448; background: var(--panel2); color: var(--ink);
  font-family: inherit; font-size: 15px; outline: none;
}
input:focus { border-color: var(--accent); }

.genre-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 10px 0 24px; }
.genre {
  padding: 14px 10px; text-align: center; border-radius: 10px; cursor: pointer;
  border: 1px solid #2c3448; background: var(--panel2); color: var(--dim);
  transition: all .15s; font-size: 14px;
}
.genre:hover { border-color: var(--accent2); color: var(--ink); }
.genre.sel { border-color: var(--accent); color: var(--accent); background: #211d14; }

.primary {
  width: 100%; padding: 13px; border: 0; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #a37f3c); color: #16130a;
  font-size: 16px; font-weight: bold; font-family: inherit; letter-spacing: .5px;
}
.primary:disabled { opacity: .5; cursor: wait; }
.ghost {
  background: none; border: 1px solid #39415a; color: var(--dim);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-family: inherit;
}
.ghost:hover { color: var(--ink); border-color: var(--accent); }

/* ---- game ---- */
#game { max-width: 1100px; margin: 0 auto; padding: 20px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding-bottom: 14px; border-bottom: 1px solid #232a3b; }
.topbar h2 { font-size: 20px; color: var(--accent); }
.char-name { color: var(--dim); font-size: 14px; font-style: italic; }

.layout { display: grid; grid-template-columns: 1fr 260px; gap: 22px; flex: 1; padding-top: 18px; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } }

.story { display: flex; flex-direction: column; min-height: 60vh; }
.log { flex: 1; overflow-y: auto; max-height: 62vh; padding-right: 6px; }
.entry { margin-bottom: 18px; line-height: 1.65; font-size: 16px; animation: fade .5s; }
.entry.narrator { color: var(--ink); }
.entry.player { color: #8fb8d9; font-style: italic; }
.entry.player::before { content: "» "; color: var(--accent); }
.entry.whitespace { white-space: pre-wrap; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

#auth-box {
  position: fixed; top: 12px; right: 14px; z-index: 50;
  display: flex; gap: 8px; align-items: center;
}
#auth-box #user-label { font-size: 13px; color: var(--dim); }
#auth-box .ghost { padding: 6px 12px; font-size: 13px; }

.choices-row { display: flex; gap: 8px; align-items: stretch; margin: 14px 0; }
.choices-row .choices { flex: 1; margin: 0; }
.choices-row .choices:empty { display: none; }
.refresh-choices {
  align-self: flex-end; padding: 6px 11px; border-radius: 10px; cursor: pointer;
  border: 1px dashed #2c3448; background: transparent; color: var(--dim);
  font-size: 18px; line-height: 1; transition: all .12s;
}
.refresh-choices:hover { border-color: var(--accent); color: var(--accent); }
.refresh-choices:disabled { opacity: .5; cursor: wait; }
.choices { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.choice {
  text-align: left; padding: 11px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid #2c3448; background: var(--panel2); color: var(--ink);
  font-family: inherit; font-size: 15px; transition: all .12s;
}
.choice:hover { border-color: var(--accent); background: #221f18; transform: translateX(4px); }
.choice:disabled { opacity: .5; cursor: wait; }

.free-form { display: flex; gap: 10px; }
.free-form input { flex: 1; }
.free-form .primary { width: auto; padding: 0 22px; }
.thinking { color: var(--dim); font-style: italic; margin-top: 10px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.gameover { border: 1px solid var(--danger); background: #1e1414; padding: 18px; border-radius: var(--radius); margin: 14px 0; }
.gameover h3 { color: var(--danger); margin-bottom: 8px; }
.gameover p { margin-bottom: 14px; color: var(--dim); }

.sheet { background: var(--panel); border: 1px solid #262d3f; border-radius: var(--radius); padding: 18px; height: fit-content; }
.sheet h3 { color: var(--accent); margin-bottom: 14px; font-size: 17px; }
.sheet h4 { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; margin: 16px 0 6px; }
.hp-row { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 5px 0; }
.hp-bar { flex: 1; height: 10px; background: #232a3b; border-radius: 999px; overflow: hidden; }
#hp-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--danger), #e67e22); transition: width .4s; }
#hp-fill.healthy { background: linear-gradient(90deg, var(--ok), #7cc79b); }
.need-fill { height: 100%; width: 100%; transition: width .4s; }
.need-fill.hunger { background: linear-gradient(90deg, #c98a3d, #e0b36a); }
.need-fill.thirst { background: linear-gradient(90deg, #3d7fc9, #6aa8e0); }
.need-fill.low { background: linear-gradient(90deg, var(--danger), #e67e22); }
.hp-row > span { min-width: 48px; }
.inv, .flags { list-style: none; font-size: 14px; color: var(--dim); }
.inv li, .flags li { padding: 4px 0; border-bottom: 1px dashed #232a3b; }
.inv li::before { content: "✦ "; color: var(--accent); }
.flags li { font-size: 12px; color: #6d7590; }

/* reloj */
.clock { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); }
.clock-bar { width: 90px; height: 6px; border-radius: 999px; overflow: hidden; background: #232a3b; }
#clock-fill { height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); transition: width .5s; }
body.night .topbar { border-bottom-color: #2a2440; }

/* inventario en cuadrícula */
.inv-count { color: var(--accent); }
.inv-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.slot {
  aspect-ratio: 1; border: 1px solid #2c3448; border-radius: 8px; background: #10141d;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3px; overflow: hidden;
}
.slot.filled { border-color: #4a3f22; background: #1a1c10; }
.slot-icon { font-size: 20px; line-height: 1; }
.slot-name { font-size: 9px; color: var(--dim); text-align: center; line-height: 1.1; margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.restored { text-align: center; color: #5d6579; font-style: italic; font-size: 13px; }

/* accesos rápidos de verbo */
.verb-chips { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.verb-chip {
  background: #1a1626; color: var(--dim); border: 1px solid #2c2547;
  border-radius: 20px; padding: 4px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: all .15s;
}
.verb-chip:hover { border-color: var(--accent); color: var(--ink); }
.verb-chip.active { background: var(--accent); color: #1a1408; border-color: var(--accent); font-weight: 600; }
.verb-chip.continue { margin-left: auto; border-style: dashed; color: var(--dim); }
.verb-chip.continue:hover { color: var(--accent); }

/* estado de mundo */
.ghost {
  width: 100%; margin-top: 8px; padding: 9px 12px; font-family: inherit; font-size: 14px;
  background: transparent; color: var(--accent); border: 1px solid var(--accent2);
  border-radius: var(--radius); cursor: pointer; transition: all .15s;
}
.ghost:hover { background: rgba(201,164,92,.12); border-color: var(--accent); }
.world-panel { max-height: 80vh; overflow: auto; text-align: left; }
.world-title { margin: 0 0 6px; color: var(--accent); font-size: 19px; text-align: center; }
.world-time { color: var(--dim); font-size: 13px; text-align: center; margin-bottom: 12px; }
.world-flags { margin-bottom: 16px; }
.world-flags li { padding: 5px 0; }
.world-panel .primary { display: block; margin: 0 auto; }

/* popup del dado */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 5, 12, .78); backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }

/* dados */
.dice { border: 1px solid var(--accent2); background: #191527; border-radius: var(--radius);
  padding: 20px; text-align: center; width: min(520px, 92vw);
  box-shadow: 0 18px 60px rgba(0,0,0,.6); }
.dice-info { color: var(--dim); margin-bottom: 8px; font-size: 15px; }
.dice-info b { color: var(--accent); }
.dice-arena {
  position: relative; height: 150px; overflow: hidden; border-radius: 10px;
  background: radial-gradient(ellipse at 50% 120%, #241d3a, #141020);
  border: 1px dashed #3a3155;
}
.dice-hint { color: var(--dim); font-size: 12px; margin-top: 8px; }
.die {
  position: absolute; left: 0; top: 0;
  width: 76px; height: 76px; font-size: 30px; font-family: inherit;
  background: linear-gradient(145deg, #2a2440, #1a1626); color: var(--ink);
  border: 2px solid var(--accent2); border-radius: 14px;
  cursor: grab; touch-action: none; user-select: none;
  transition: border-color .15s, color .15s, box-shadow .15s;
  box-shadow: 0 6px 14px rgba(0,0,0,.45);
}
.die.held { cursor: grabbing; border-color: var(--accent); }
.die:disabled { cursor: default; }
.die.success { border-color: var(--ok); color: #9be2b6; box-shadow: 0 0 18px rgba(78,154,109,.5); }
.die.fail { border-color: var(--danger); color: #f0a79c; box-shadow: 0 0 18px rgba(192,57,43,.5); }
