:root{
  --bg:#070814;
  --panel:#0c0f24;
  --panel2:#0a0c1c;
  --text:#e9e5d6;
  --muted:#bdb59a;
  --line:#2bd2ff;
  --line2:#ff4fd8;
  --danger:#ff3b3b;
  --good:#35ffb3;
  --shadow: 0 12px 40px rgba(0,0,0,.55);
  --radius: 14px;
  --serif: "Cinzel", "Playfair Display", serif;

  --collapsed-panel-width: 50px; /* For sidebar and action panels */
  --collapsed-panel-height: 50px; /* For story panel */
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(43,210,255,.16), transparent 55%),
    radial-gradient(900px 600px at 85% 30%, rgba(255,79,216,.13), transparent 55%),
    linear-gradient(180deg, #050612, #070814 55%, #050612);
  color:var(--text);
  font-family: var(--serif);
  letter-spacing:.2px;
}

.app-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 18px;
  border-bottom:1px solid rgba(43,210,255,.35);
  background:linear-gradient(180deg, rgba(12,15,36,.92), rgba(7,8,20,.72));
  position:sticky;
  top:0;
  z-index:20;
  backdrop-filter: blur(10px);
}

.brand__title{
  font-weight:700;
  font-size:20px;
  text-transform:uppercase;
  letter-spacing:2px;
}
.brand__subtitle{ font-size:12px; color:var(--muted); margin-top:2px; }

.header-actions{ display:flex; gap:10px; }

.app{
  display:grid;
  gap:14px;
  padding:14px;
  /* grid-template-columns will be set by JS for wide screens */
  transition: grid-template-columns 0.3s ease-in-out;
  align-items: start; /* Align items to the start of their grid area */
}

/* Default grid columns for wide screens (overridden by JS if panels collapse) */
@media (min-width: 1101px) {
  .app {
    grid-template-columns: 320px 1fr 420px;
  }
}

@media (max-width: 1100px){
  .app{ grid-template-columns: 280px 1fr; grid-template-rows:auto auto; }
  .action{ grid-column: 1 / -1; }
}

@media (max-width: 760px){
  .app{ grid-template-columns: 1fr; }
  .sidebar{ order:2; }
  .action{ order:3; }
}

.panel-title{
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:2px;
  color:rgba(233,229,214,.92);
  font-size:13px;
  margin-bottom:10px;
}

.sidebar, .story, .action{
  background:linear-gradient(180deg, rgba(12,15,36,.92), rgba(10,12,28,.84));
  border:1px solid rgba(43,210,255,.25);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden; /* Ensures content is clipped when collapsed */
  display: flex; /* Use flexbox for internal layout */
  flex-direction: column;
  transition: width 0.3s ease-in-out, height 0.3s ease-in-out, padding 0.3s ease-in-out;
}

/* Default height for story when not collapsed */
.story {
  height: calc(100vh - 140px); /* app-header height + app padding */
}
@media (max-width: 1100px){
  .story{ height: auto; min-height: 260px; max-height: 50vh; } /* For smaller screens */
}


.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(43,210,255,.2);
  cursor: pointer;
  flex-shrink: 0; /* Prevent header from shrinking */
}

.panel-header .panel-title {
  margin-bottom: 0; /* Override default margin */
  white-space: nowrap; /* Prevent title from wrapping */
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-toggle-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease-in-out;
}

.panel-toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* Rotations for icons */
.sidebar .panel-toggle-btn.collapsed svg { transform: rotate(-90deg); } /* Left arrow points down */
.story .panel-toggle-btn.collapsed svg { transform: rotate(180deg); } /* Up arrow points down */
.action .panel-toggle-btn.collapsed svg { transform: rotate(90deg); } /* Right arrow points down */

.panel-content {
  /* This will be toggled with display: none in JS */
  flex-grow: 1; /* Allow content to take remaining space in flex column */
  overflow: auto; /* Allow content to scroll if needed */
  padding: 12px; /* Default padding for content */
}

/* Collapsed state for panels */
.sidebar.panel--collapsed {
  width: var(--collapsed-panel-width);
  min-width: var(--collapsed-panel-width);
  padding: 0; /* Remove padding from the section itself */
}
.action.panel--collapsed {
  width: var(--collapsed-panel-width);
  min-width: var(--collapsed-panel-width);
  padding: 0; /* Remove padding from the section itself */
}
.story.panel--collapsed {
  height: var(--collapsed-panel-height);
  min-height: var(--collapsed-panel-height);
  padding: 0; /* Remove padding from the section itself */
}

/* Hide content and title text when collapsed */
.panel--collapsed .panel-content {
  display: none;
}
.sidebar.panel--collapsed .panel-title,
.action.panel--collapsed .panel-title {
  display: none; /* Hide title text for horizontal collapsed panels */
}

/* Adjustments for the panel-header when the panel is collapsed */
.panel--collapsed .panel-header {
  border-bottom: none; /* No border when collapsed */
}

/* Specific padding for story__top and story__log when story is not collapsed */
.story:not(.panel--collapsed) .story__top {
  padding: 12px 12px 10px;
  border-bottom:1px solid rgba(43,210,255,.2);
  flex-shrink: 0; /* Prevent story__top from shrinking */
}
.story:not(.panel--collapsed) .story__log {
  padding:12px;
  overflow:auto;
  flex-grow: 1; /* Allow log to take remaining vertical space */
}

.players{ display:flex; flex-direction:column; gap:12px; }

.player-card{
  padding:12px;
  border-radius:12px;
  border:1px solid rgba(255,79,216,.25);
  background:linear-gradient(180deg, rgba(7,8,20,.6), rgba(12,15,36,.3));
  position:relative;
}

.player-card--dead{
  opacity:.62;
  border-color: rgba(255,59,59,.4);
}

.player-card__top{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}

.player-card__name{ font-weight:700; font-size:16px; }
.player-card__sub{ color:var(--muted); font-size:12px; margin-top:2px; }

.skulls{
  font-size:12px;
  padding:6px 8px;
  border-radius:10px;
  border:1px solid rgba(43,210,255,.35);
  background: rgba(0,0,0,.25);
  white-space:nowrap;
}

.traits{ display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }

.trait-btn{
  appearance:none;
  border:1px solid rgba(43,210,255,.35);
  background: rgba(0,0,0,.18);
  color: var(--text);
  border-radius: 999px;
  padding:6px 10px;
  font-family: var(--serif);
  cursor:pointer;
  font-size:12px;
}
.trait-btn[aria-pressed="true"]{
  border-color: rgba(53,255,179,.8);
  box-shadow: 0 0 0 2px rgba(53,255,179,.15) inset;
}
.trait-btn--scarred{
  border-color: rgba(255,79,216,.55);
}

.story__top{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:12px;
  /* Padding and border moved to .story:not(.panel--collapsed) .story__top */
}

.dungeon-description{ /* New style for dungeon description */
  font-size:13px;
  color:rgba(233,229,214,.92);
  line-height:1.4;
  margin-top: 8px;
  margin-bottom: 10px;
  padding: 8px 0;
  border-top: 1px dashed rgba(43,210,255,.15);
  border-bottom: 1px dashed rgba(43,210,255,.15);
}

.status-line{ font-size:12px; color:var(--muted); margin-top:6px; }

.threat{
  min-width: 200px;
  border:1px solid rgba(255,79,216,.22);
  border-radius:12px;
  padding:10px 12px;
  background: rgba(0,0,0,.15);
}
.threat__label{ font-size:11px; text-transform:uppercase; letter-spacing:2px; color:rgba(255,79,216,.9); }
.threat__text{ margin-top:6px; font-size:13px; color:rgba(233,229,214,.9); }

.story__log{
  /* Padding, overflow, and flex-grow moved to .story:not(.panel--collapsed) .story__log */
  /* height: calc(100vh - 140px); */ /* Removed fixed height */
}

@media (max-width: 1100px){
  /* .story__log{ height: auto; min-height: 260px; max-height: 50vh; } */ /* Removed fixed height */
}

.log-entry{
  border-left: 2px solid rgba(43,210,255,.5);
  padding:10px 12px;
  margin:0 0 10px;
  background: rgba(0,0,0,.10);
  border-radius: 10px;
}

.log-entry__meta{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
  font-size:12px;
  color:var(--muted);
}

.log-entry__title{
  font-weight:700;
  font-size:13px;
  color: rgba(233,229,214,.95);
}

.log-entry__text{
  margin-top:6px;
  line-height:1.4;
  color: rgba(233,229,214,.92);
  white-space: pre-line;
}

.card{
  padding:12px;
  border-radius: 12px;
  border:1px solid rgba(43,210,255,.25);
  background: linear-gradient(180deg, rgba(0,0,0,.15), rgba(0,0,0,.05));
  box-shadow: 0 10px 28px rgba(0,0,0,.25);
}
.card--thin{ margin-top:12px; }

.card__title{ margin:0 0 6px; font-size:16px; }
.card__hint{ margin:0 0 12px; color: var(--muted); font-size:12px; }

.hidden{ display:none !important; }

.field{ display:flex; flex-direction:column; gap:6px; font-size:12px; color:var(--muted); }
.field > span{ letter-spacing:1px; }
.field--full{ width:100%; }

.input{
  width:100%;
  border:1px solid rgba(43,210,255,.35);
  border-radius: 12px;
  padding:10px 12px;
  background: rgba(0,0,0,.18);
  color: var(--text);
  font-family: var(--serif);
  outline:none;
}
.input:focus{ border-color: rgba(53,255,179,.85); box-shadow: 0 0 0 3px rgba(53,255,179,.12); }
.input--textarea{ resize:vertical; min-height: 90px; }

.setup{ display:flex; flex-direction:column; gap:12px; }
.setup__row{ display:flex; gap:10px; align-items:flex-end; }
.setup__row--end{ justify-content:flex-end; }
.setup__players{ display:flex; flex-direction:column; gap:10px; }

.player-form{
  display:grid;
  grid-template-columns: 1.2fr 1fr;
  gap:10px;
  padding:10px;
  border:1px dashed rgba(255,79,216,.35);
  border-radius: 12px;
  background: rgba(0,0,0,.12);
}
.player-form__traits{ grid-column: 1 / -1; display:grid; grid-template-columns: 1fr 1fr; gap:10px; }

.btn{
  border:1px solid rgba(43,210,255,.5);
  background: rgba(0,0,0,.20);
  color: var(--text);
  border-radius: 12px;
  padding:10px 12px;
  cursor:pointer;
  font-family: var(--serif);
  text-transform:uppercase;
  letter-spacing:1.5px;
  font-weight:700;
  font-size:12px;
}
.btn:hover{ border-color: rgba(53,255,179,.85); }
.btn:disabled{ opacity:.55; cursor:not-allowed; }

.btn--primary{
  border-color: rgba(53,255,179,.75);
  background: linear-gradient(180deg, rgba(53,255,179,.18), rgba(0,0,0,.18));
}

.btn--danger{
  border-color: rgba(255,59,59,.7);
}

.btn--ghost{
  border-color: rgba(255,79,216,.55);
}

.turn{ display:flex; flex-direction:column; gap:12px; }
.turn__row{ display:flex; gap:10px; align-items:flex-start; }
.turn__row--end{ justify-content:space-between; align-items:center; }

.cr-box{
  border:1px solid rgba(255,79,216,.30);
  border-radius: 12px;
  padding:10px 12px;
  background: rgba(0,0,0,.14);
  min-width: 170px;
  text-align:right;
}
.cr-box__phase{ font-size:11px; text-transform:uppercase; letter-spacing:2px; color:rgba(255,79,216,.92); }
.cr-box__cr{ margin-top:6px; font-size:16px; font-weight:700; }

.trait-picker{ display:flex; flex-wrap:wrap; gap:8px; margin-top:2px; }

.dice{ display:flex; flex-direction:column; gap:6px; }
.dice__label{ font-size:12px; color: var(--muted); text-transform:uppercase; letter-spacing:2px; }
.dice__readout{
  font-size:18px;
  font-weight:700;
  padding:10px 12px;
  border-radius: 12px;
  border:1px solid rgba(43,210,255,.35);
  background: rgba(0,0,0,.16);
  min-width: 160px;
}

.consequence{ font-size:12px; color: var(--muted); line-height:1.35; }

.mini-hint{ font-size:11px; color: rgba(189,181,154,.92); line-height:1.35; }

.dialog{
  width:min(560px, calc(100vw - 24px));
  border-radius: 16px;
  border:1px solid rgba(43,210,255,.35);
  background: linear-gradient(180deg, rgba(12,15,36,.96), rgba(7,8,20,.92));
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop{ background: rgba(0,0,0,.62); backdrop-filter: blur(3px); }

.dialog__form{ padding:14px; display:flex; flex-direction:column; gap:12px; }
.dialog__title{ margin:0; font-size:16px; text-transform:uppercase; letter-spacing:2px; }
.dialog__body{ color: rgba(233,229,214,.92); font-size:13px; line-height:1.4; }
.dialog__actions{ display:flex; justify-content:flex-end; gap:10px; }

.prompt-options{ display:flex; flex-direction:column; gap:10px; margin-top:6px; }
.option-row{ display:flex; align-items:center; gap:10px; }
.option-row input{ transform: translateY(1px); }

.badge{
  display:inline-flex;
  align-items:center;
  gap:8px;
  border:1px solid rgba(43,210,255,.35);
  border-radius:999px;
  padding:6px 10px;
  background: rgba(0,0,0,.15);
  font-size:12px;
  color: rgba(233,229,214,.92);
}

.badge--good{ border-color: rgba(53,255,179,.6); }
.badge--bad{ border-color: rgba(255,59,59,.6); }