:root {
  --pj-ink: #f4ead2;
  --pj-panel: rgba(22, 27, 28, .94);
  --pj-line: #594f3e;
  --pj-gold: #e2ba5d;
  --pj-red: #b13d32;
}

* { box-sizing: border-box; }

.pj-game {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 360px;
  overflow: hidden;
  isolation: isolate;
  color: var(--pj-ink);
  background: #11191d;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

.pj-game button { font: inherit; }

.pj-game__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  outline: none;
  image-rendering: pixelated;
  touch-action: none;
}

.pj-game__canvas:active { cursor: grabbing; }

.pj-hud {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  min-height: 68px;
  display: grid;
  grid-template-columns: auto auto minmax(120px, 1fr) auto;
  gap: 7px 18px;
  align-items: center;
  padding: 9px 16px;
  border-bottom: 2px solid var(--pj-line);
  background: linear-gradient(180deg, rgba(15, 19, 20, .98), rgba(20, 26, 27, .88));
  box-shadow: 0 5px 18px rgba(0, 0, 0, .35);
}

.pj-hud__identity {
  padding-left: 10px;
  border-left: 6px solid var(--clan-color, #aaa);
  font-size: 1.03rem;
  font-weight: 800;
  letter-spacing: .02em;
}

.pj-hud__stats { color: #d8ccb3; font-size: .9rem; }
.pj-hud__turn { justify-self: end; color: #8ce0b9; font-weight: 800; }
.pj-hud__turn.is-waiting { color: #e4bf71; }
.pj-button--menu { min-height: 34px; padding: 5px 10px; font-size: .82rem; }

.pj-hud__objective {
  grid-column: 1 / 3;
  grid-row: 2;
  padding: 5px 9px;
  border-left: 3px solid #c39a4d;
  color: #dfd2b7;
  background: rgba(10, 14, 15, .48);
  font-size: .78rem;
}

.pj-hud__objective[hidden] { display: none; }

.pj-players {
  grid-column: 3 / -1;
  grid-row: 2;
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.pj-player {
  flex: 0 0 auto;
  font-size: .76rem;
  color: #d8ccb3;
}

.pj-player::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border: 1px solid rgba(255,255,255,.45);
  background: var(--player-color);
}

.pj-player.is-eliminated { opacity: .48; text-decoration: line-through; }

.pj-toolbar {
  position: absolute;
  z-index: 4;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 9px;
}

.pj-button {
  min-height: 42px;
  padding: 9px 14px;
  border: 2px solid #765f39;
  border-radius: 3px;
  color: #fff3d5;
  background: #3c3428;
  box-shadow: 0 4px 0 #171512, 0 7px 16px rgba(0,0,0,.28);
  font-weight: 800;
  cursor: pointer;
}

.pj-button:hover:not(:disabled) { filter: brightness(1.13); transform: translateY(-1px); }
.pj-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #171512; }
.pj-button:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.5); }
.pj-button--primary { border-color: #d39a43; background: #9c382e; }
.pj-button--secondary { border-color: #6c7658; background: #344335; }
.pj-button--danger { border-color: #d76958; background: #632923; }

.pj-panel {
  position: absolute;
  z-index: 4;
  top: 92px;
  right: 14px;
  width: min(290px, calc(100% - 28px));
  max-height: calc(100% - 175px);
  padding: 15px;
  overflow-y: auto;
  border: 2px solid var(--pj-line);
  border-radius: 4px;
  background: var(--pj-panel);
  box-shadow: 7px 8px 0 rgba(0, 0, 0, .25);
}

.pj-panel h2, .pj-panel h3 { margin: 0 0 7px; }
.pj-panel h2 { color: #f2cf7c; font-size: 1.05rem; }
.pj-panel h3 { margin-top: 13px; color: #d4c6aa; font-size: .82rem; text-transform: uppercase; letter-spacing: .1em; }
.pj-panel__meta { margin: 0 0 10px; color: #bdb099; font-size: .85rem; }
.pj-action-panel .pj-button { width: 100%; margin-top: 8px; text-align: left; }
.pj-button small { display: block; margin-top: 3px; color: #cbbfa9; font-size: .72rem; font-weight: 400; }

.pj-log {
  position: absolute;
  z-index: 3;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  width: min(390px, calc(100% - 28px));
  margin: 0;
  padding: 10px 12px 10px 28px;
  border-left: 3px solid #9d7c45;
  color: #d4c8b1;
  background: rgba(12, 16, 17, .78);
  font-size: .78rem;
  line-height: 1.45;
  pointer-events: none;
}

.pj-modal-layer, .pj-result {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(5, 8, 9, .76);
  backdrop-filter: blur(3px);
}

.pj-modal-layer[hidden], .pj-result[hidden], .pj-action-panel[hidden], .pj-toast[hidden] { display: none; }

.pj-modal {
  width: min(680px, 100%);
  max-height: min(680px, 90vh);
  padding: 18px;
  overflow-y: auto;
  border: 3px double #8b7043;
  background: #1c2424;
  box-shadow: 12px 14px 0 rgba(0,0,0,.35);
}

.pj-modal__heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.pj-modal h2 { margin: 0; color: #efcb76; }
.pj-icon-button { padding: 8px; border: 0; color: #d8cbb0; background: transparent; cursor: pointer; }
.pj-tech-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 18px; }
.pj-tech-grid .pj-button { text-align: left; }
.pj-empty { color: #b7aa93; }

.pj-modal--menu { width: min(430px, 100%); }
.pj-menu { display: grid; gap: 10px; margin-top: 18px; }
.pj-menu__button { width: 100%; text-align: left; }
.pj-help { margin-top: 18px; color: #d8ccb3; line-height: 1.55; }
.pj-help p { margin: 0 0 12px; }
.pj-help strong { color: #f1d389; }

.pj-modal--clans { width: min(940px, 100%); }
.pj-clans-help { margin-top: 18px; color: #d8ccb3; }
.pj-clans-help h3 { margin: 24px 0 10px; color: #efcb76; font-size: .9rem; letter-spacing: .08em; text-transform: uppercase; }
.pj-clans-help h3:first-child { margin-top: 0; }
.pj-clan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pj-clan-card { padding: 12px; border-left: 5px solid var(--clan-color); background: #141b1b; }
.pj-clan-card p { margin: 7px 0 0; font-size: .82rem; line-height: 1.42; }
.pj-clan-card__title, .pj-help-unit { display: flex; align-items: center; gap: 8px; }
.pj-clan-card__title strong { color: var(--clan-color); }
.pj-clan-card__advantage { color: #bfb39c; }
.pj-help-sprite { width: 32px; height: 32px; flex: 0 0 auto; image-rendering: pixelated; }
.pj-help-table-wrap { overflow-x: auto; border: 1px solid #4e493c; }
.pj-help-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.pj-help-table th, .pj-help-table td { padding: 8px 9px; border-bottom: 1px solid #3d3c34; text-align: center; white-space: nowrap; }
.pj-help-table th { color: #f1d389; background: #111818; }
.pj-help-table th:first-child, .pj-help-table td:first-child { text-align: left; }
.pj-help-table tbody tr:last-child td { border-bottom: 0; }
.pj-help-players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.pj-help-player { padding: 10px 12px; border-left: 4px solid var(--clan-color); background: #141b1b; }
.pj-help-player p { margin: 5px 0 0; color: #bfb39c; font-size: .78rem; }
.pj-help-player__clan { color: var(--clan-color); }
.pj-help-player.is-eliminated { opacity: .58; }
.pj-bot-levels { margin: 0; padding-left: 22px; line-height: 1.55; }

.pj-modal--briefing { width: min(620px, 100%); text-align: center; }
.pj-briefing__eyebrow { margin: 0 0 8px; color: #d8b462; font-size: .75rem; font-weight: 900; letter-spacing: .2em; text-transform: uppercase; }
.pj-briefing__text { margin: 20px 0; color: #ded1b7; line-height: 1.65; white-space: pre-line; }
.pj-briefing__objective { padding: 12px; border: 1px solid #6f5a36; color: #f1d389; background: #131a1a; font-weight: 800; }
.pj-modal--briefing .pj-button { margin-top: 8px; min-width: 180px; }

.pj-sound-settings { display: grid; gap: 16px; margin-top: 22px; }
.pj-toggle, .pj-volume {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 2px solid #4e493c;
  background: #141b1b;
  color: #e8dcc2;
  font-weight: 800;
}
.pj-toggle input { width: 20px; height: 20px; accent-color: #b74739; }
.pj-volume { align-items: stretch; flex-direction: column; }
.pj-volume input { width: 100%; accent-color: #c69b4c; }

.pj-modal--confirm {
  width: min(460px, 100%);
  border: 4px solid #8d6542;
  outline: 3px solid #211512;
  text-align: center;
  image-rendering: pixelated;
  box-shadow: 8px 8px 0 #0a0d0d, inset 0 0 0 3px #3d3127;
}
.pj-confirm__mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border: 3px solid #e0b55d;
  color: #ffe09b;
  background: #6a2b24;
  font: 900 30px/1 monospace;
}
.pj-confirm__text { margin: 15px auto 20px; color: #d7c9ad; line-height: 1.5; }
.pj-confirm__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.pj-result {
  z-index: 20;
  align-content: center;
  text-align: center;
  background: radial-gradient(circle, rgba(47, 48, 35, .9), rgba(5, 8, 9, .96));
}

.pj-result__eyebrow { margin: 0; color: #e0b55d; font-size: .8rem; font-weight: 900; letter-spacing: .28em; text-transform: uppercase; }
.pj-result h1 { max-width: 640px; margin: 10px auto 20px; font-family: Georgia, serif; font-size: clamp(2rem, 7vw, 4.8rem); line-height: .98; }
.pj-result__narrative { max-width: 680px; margin: 0 auto 24px; color: #ded1b7; font-size: clamp(.95rem, 2vw, 1.15rem); line-height: 1.6; white-space: pre-line; }
.pj-result__actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

.pj-toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  top: 92px;
  transform: translateX(-50%);
  max-width: calc(100% - 30px);
  padding: 10px 15px;
  border: 2px solid #c05c4d;
  background: #3e1f1c;
  color: #ffe6d4;
  font-weight: 700;
}

@media (max-width: 700px) {
  .pj-hud {
    min-height: 92px;
    grid-template-columns: 1fr auto auto;
    gap: 5px 9px;
    padding: 7px 9px;
  }
  .pj-hud__stats { grid-column: 1 / -1; font-size: .78rem; }
  .pj-hud__turn { grid-column: 2; grid-row: 1; font-size: .82rem; }
  .pj-button--menu { grid-column: 3; grid-row: 1; }
  .pj-hud__objective { grid-row: 3; font-size: .72rem; }
  .pj-hud__objective, .pj-players { grid-column: 1 / -1; }
  .pj-players { grid-row: 4; }
  .pj-panel { top: 132px; right: 8px; width: min(250px, calc(100% - 16px)); max-height: calc(100% - 236px); padding: 11px; }
  .pj-toolbar { right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); flex-direction: column; align-items: stretch; }
  .pj-toolbar .pj-button { min-height: 38px; padding: 7px 10px; font-size: .8rem; }
  .pj-log { left: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: min(48vw, 270px); max-height: 104px; overflow: hidden; font-size: .68rem; }
}

@media (max-width: 430px) {
  .pj-hud__identity { max-width: 58vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .pj-action-panel { width: calc(100% - 16px); max-height: 42vh; }
  .pj-log { display: none; }
  .pj-toolbar { max-width: 44vw; }
  .pj-button { min-height: 44px; }
  .pj-hud .pj-button--menu { min-height: 34px; padding: 5px 7px; }
  .pj-confirm__actions { grid-template-columns: 1fr; }
  .pj-clan-grid, .pj-help-players { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .pj-button { transition: none; }
}
