:root {
  --bg: #17202a;
  --panel: #f3ecdd;
  --panel-2: #fff9ee;
  --ink: #23211f;
  --muted: #6d6f75;
  --line: rgba(38, 47, 58, .18);
  --wood: #6b4a35;
  --red: #9d4038;
  --blue: #2f5774;
  --gold: #a77b34;
  --green: #477260;
  --shadow: 0 18px 45px rgba(10, 16, 22, .24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background:
    linear-gradient(115deg, rgba(69, 104, 125, .22), transparent 42%),
    linear-gradient(180deg, #1d2833 0%, #17202a 46%, #20201d 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 5px;
  padding: 0 14px;
  color: #fff9ec;
  font-weight: 900;
  background: var(--blue);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

button.ghost {
  color: var(--ink);
  border: 1px solid rgba(255, 244, 223, .48);
  background: rgba(255, 244, 223, .72);
}

button.danger,
.danger {
  color: #fff9ec;
  background: var(--red);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8ad83;
  border-radius: 5px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fffaf0;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.app {
  width: min(1520px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  color: #fff4df;
}

.kicker {
  color: #d9b56c;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin: 2px 0 4px;
  font-size: 34px;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: 19px;
}

.topbar p {
  margin-bottom: 0;
  color: #cbd7df;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.entry-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.entry-switch a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 10px;
  color: #f5ead4;
  border: 1px solid rgba(255, 244, 223, .28);
  border-radius: 5px;
  text-decoration: none;
  background: rgba(255, 244, 223, .08);
}

.entry-switch span {
  color: #b8c7d1;
  font-size: 12px;
}

.join-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 16px;
}

.entry-card,
.panel,
.table-panel {
  border: 1px solid rgba(255, 244, 223, .35);
  border-radius: 8px;
  background: rgba(244, 234, 215, .95);
  box-shadow: var(--shadow);
}

.entry-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.room-panel {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(320px, 380px);
  gap: 16px;
}

.table-panel {
  display: grid;
  grid-template-rows: auto auto minmax(360px, 1fr) auto;
  min-height: calc(100vh - 126px);
  overflow: hidden;
}

.room-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  color: #f7efe0;
  background: #273441;
}

.room-strip div {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.room-strip strong {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 30px;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 5px;
  font-size: 18px;
  letter-spacing: 0;
}

.room-strip span {
  overflow: hidden;
  color: #d6e0e8;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 248, 234, .92);
}

.scene-card span,
.panel-head span,
.player-card span,
.message header span {
  color: var(--muted);
  font-size: 12px;
}

.scene-card h2 {
  margin-bottom: 4px;
  font-size: 24px;
}

.scene-card p {
  margin-bottom: 0;
  color: #4d4237;
  line-height: 1.55;
}

.message-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 16px;
  background:
    linear-gradient(rgba(255, 255, 255, .32), transparent 22%),
    #e5d8bf;
}

.message {
  max-width: 86%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 250, 240, .9);
}

.message.player {
  justify-self: end;
  background: #fffaf0;
}

.message.gm {
  max-width: 96%;
  border-left: 5px solid var(--blue);
  background: #fffdf7;
}

.message.roll {
  max-width: 96%;
  border-left: 5px solid var(--gold);
  background: #fff2d1;
}

.message.system {
  justify-self: center;
  max-width: 70%;
  color: var(--muted);
  background: rgba(255, 255, 255, .5);
}

.message header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
}

.message p {
  margin-bottom: 0;
  line-height: 1.6;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 248, 234, .88);
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.side-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
  gap: 0;
  min-height: calc(100vh - 126px);
  border: 1px solid rgba(255, 244, 223, .28);
  border-radius: 8px;
  background: rgba(15, 23, 30, .32);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.side-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 6px;
  border-bottom: 1px solid rgba(255, 244, 223, .18);
  background: rgba(15, 23, 30, .46);
}

.side-tabs button {
  min-height: 36px;
  padding: 0 8px;
  color: #d9e2e8;
  border: 1px solid transparent;
  background: transparent;
}

.side-tabs button.is-active {
  color: var(--ink);
  border-color: rgba(255, 244, 223, .52);
  background: var(--panel-2);
}

.side-tabs button.has-content::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 5px;
  border-radius: 50%;
  background: var(--gold);
  vertical-align: middle;
}

.panel {
  min-height: 0;
  overflow: auto;
  border: 0;
  border-radius: 0;
  padding: 14px;
  box-shadow: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin-bottom: 0;
}

.player-list {
  display: grid;
  gap: 8px;
}

.asset-list {
  display: grid;
  gap: 10px;
}

.asset-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, .45);
}

.asset-card.revealed {
  background: rgba(232, 241, 248, .62);
}

.asset-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.asset-card-head span,
.asset-card p {
  color: var(--muted);
  font-size: 12px;
}

.asset-card p {
  margin-bottom: 0;
  line-height: 1.5;
}

.asset-card a {
  display: block;
  overflow: hidden;
  border: 1px solid rgba(64, 42, 24, .22);
  border-radius: 5px;
  background: #fffaf0;
}

.asset-card img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.empty-panel {
  margin: 0;
  padding: 18px 12px;
  color: var(--muted);
  border: 1px dashed rgba(64, 42, 24, .24);
  border-radius: 6px;
  text-align: center;
  background: rgba(255, 255, 255, .34);
}

.player-card {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, .45);
}

.player-card.self {
  border-color: rgba(41, 71, 99, .42);
  background: rgba(232, 241, 248, .62);
}

.dice-panel,
.character-panel {
  display: grid;
  gap: 10px;
}

.quick-rolls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.quick-rolls button {
  color: var(--ink);
  border: 1px solid #c8ad83;
  background: rgba(255, 255, 255, .5);
}

.character-sheet {
  display: grid;
  gap: 10px;
}

.character-grid,
.dynamic-character {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.character-grid label:first-child {
  grid-column: span 2;
}

.dynamic-character {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.character-field {
  min-width: 0;
}

.character-field.wide {
  grid-column: 1 / -1;
}

.character-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

@media (max-width: 980px) {
  .join-panel,
  .room-panel {
    grid-template-columns: 1fr;
  }

  .table-panel {
    min-height: 70vh;
  }

  .topbar,
  .scene-card {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 12px;
  }

  h1 {
    font-size: 28px;
  }

  .message {
    max-width: 100%;
  }

  .character-grid {
    grid-template-columns: 1fr;
  }

  .dynamic-character {
    grid-template-columns: 1fr;
  }

  .character-grid label:first-child {
    grid-column: auto;
  }
}
