:root {
  --bg: #f4f0e8;
  --ink: #202326;
  --muted: #68717b;
  --panel: #fffdf8;
  --line: #d7d0c4;
  --blue: #2563a7;
  --red: #b33a32;
  --gold: #b9892b;
  --green: #3f7d58;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: auto;
}

body {
  margin: 0;
  -webkit-overflow-scrolling: touch;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #e7edf0 0%, var(--bg) 46%, #ece4d6 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid #1f2933;
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  background: #26313b;
  color: #fff;
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  background: #fff;
}

.app-shell {
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-columns: 21rem minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  height: 100vh;
  min-height: 0;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.96);
  overflow-x: hidden;
  overflow-y: auto;
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 0 minmax(0, 1fr);
}

body.sidebar-collapsed .sidebar {
  padding: 0;
  overflow: hidden;
  border: 0;
}

.panel {
  margin-bottom: 0.8rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(31, 41, 51, 0.08);
}

.panel h1,
.panel h2,
.panel p {
  margin-top: 0;
}

.title-row,
.button-row,
.board-head,
.hand-head,
.legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.stack {
  display: grid;
  gap: 0.45rem;
}

.icon-button {
  min-width: 2.25rem;
  padding: 0.4rem 0.55rem;
}

.meta-block {
  display: grid;
  gap: 0.2rem;
  margin-bottom: 0.65rem;
}

#status {
  white-space: pre-line;
  color: var(--muted);
}

.players {
  display: grid;
  gap: 0.45rem;
}

.player {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.65rem;
  padding: 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.player.active {
  outline: 2px solid var(--green);
}

.player.blue {
  border-left: 5px solid var(--blue);
}

.player.red {
  border-left: 5px solid var(--red);
}

.log-list {
  max-height: 18rem;
  overflow: auto;
  display: grid;
  gap: 0.35rem;
}

.log-entry {
  padding: 0.45rem 0.55rem;
  border: 1px solid #ece5da;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 0.92rem;
}

.table {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  padding: 1rem;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(10rem, 13.5rem);
  gap: 1rem;
  overflow: hidden;
}

.show-panel-button {
  position: fixed;
  left: 0.3rem;
  top: 50%;
  z-index: 5;
}

.hidden {
  display: none;
}

.board-wrap,
.hand-panel {
  min-width: 0;
  min-height: 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
}

.board-wrap {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.overline {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.board-head h2,
.hand-head h2 {
  margin: 0.1rem 0 0;
}

.legend {
  justify-content: flex-end;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.dot,
.memristor {
  display: inline-block;
  width: 0.8rem;
  height: 0.8rem;
  margin-right: 0.25rem;
  border-radius: 99px;
  vertical-align: -0.1rem;
}

.dot.blue {
  background: var(--blue);
}

.dot.red {
  background: var(--red);
}

.memristor {
  background: conic-gradient(from 0deg, var(--gold), #f5d37a, var(--gold));
}

.board {
  margin-top: 1rem;
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: clamp(0.25rem, 0.75vw, 0.6rem);
}

.timeline {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: clamp(0.35rem, 0.8vw, 0.65rem);
  border: 2px solid #c8c1b5;
  border-radius: 8px;
  background: #fbf9f3;
  color: var(--ink);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(0.18rem, 0.45vw, 0.35rem);
  text-align: left;
  overflow: hidden;
  z-index: 0;
}

.timeline.legal {
  border-color: var(--green);
  box-shadow: inset 0 0 0 2px rgba(63, 125, 88, 0.18);
}

.timeline.selected {
  outline: 3px solid #1f6feb;
}

.timeline-heading {
  display: flex;
  align-items: baseline;
  min-width: 0;
  white-space: nowrap;
}

.timeline-number {
  font-size: clamp(1.25rem, 3.1vw, 2.35rem);
  font-weight: 800;
  line-height: 1;
}

.wormhole {
  color: var(--gold);
  font-size: clamp(0.68rem, 1vw, 0.88rem);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(0.2rem, 0.6vw, 0.45rem);
  align-items: stretch;
  min-height: 0;
  position: relative;
  z-index: 1;
}

.slot {
  min-height: 0;
  height: 100%;
  max-height: 100%;
  border-radius: 8px;
  display: grid;
  place-items: center;
  border: 2px dashed #d8d0c4;
  background: rgba(255, 255, 255, 0.68);
  font-weight: 800;
  font-size: clamp(1rem, 2vw, 1.3rem);
  line-height: 1;
  overflow: hidden;
}

.slot.blue {
  border-color: rgba(37, 99, 167, 0.42);
}

.slot.red {
  border-color: rgba(179, 58, 50, 0.42);
}

.slot.token {
  color: #fff;
  border-style: solid;
}

.slot.token.blue {
  background: var(--blue);
}

.slot.token.red {
  background: var(--red);
}

.slot.rock {
  border-radius: 999px 999px 8px 8px;
}

.slot.paper {
  border-radius: 8px;
}

.slot.scissors {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  border-radius: 0;
}

.hand-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.wormhole-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
}

.wormhole-toggle input {
  width: auto;
}

.hand {
  margin-top: 0.8rem;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(6.8rem, 1fr));
  align-content: start;
  gap: 0.65rem;
}

.card {
  min-height: 7.4rem;
  display: grid;
  place-items: center;
  gap: 0.4rem;
  background: #fff;
  color: var(--ink);
  border: 2px solid #cfc6b8;
}

.card.selected {
  border-color: #1f6feb;
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.18);
}

.card-art {
  width: 4.2rem;
  height: 4.2rem;
  display: grid;
  place-items: center;
  background: #26313b;
  color: #fff;
  font-weight: 800;
  font-size: 1.8rem;
}

.card.rock .card-art {
  border-radius: 999px 999px 12px 12px;
  background: #68717b;
}

.card.paper .card-art {
  border-radius: 8px;
  background: #e8dfcf;
  color: var(--ink);
  border: 2px solid #b8ad9c;
}

.card.scissors .card-art {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: #4e667a;
}

@media (max-width: 780px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .table {
    height: auto;
    grid-template-rows: auto auto;
    overflow: visible;
  }

  .board {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: none;
  }

  .timeline {
    min-height: 9rem;
  }

  .board-head,
  .hand-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
