:root {
  --bg: #071b1a;
  --mat: #0f3d3a;
  --line: #2b736f;
  --ink: #f3f7f6;
  --muted: #bfcdca;
  --accent: #f5aa42;
  --main-card-width: clamp(84px, min(12.5vw, 11.8dvh), 156px);
  --small-card-width: clamp(56px, min(8.8vw, 8.2dvh), 108px);
  --play-card-width: clamp(102px, min(16vw, 14dvh), 220px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 5%, #12433f 0%, transparent 34%),
    radial-gradient(circle at 90% 15%, #0a2a28 0%, transparent 38%),
    var(--bg);
}

/* Game table is only usable in fullscreen mode. */
body:not(.fullscreen-mode) .table-wrap {
  visibility: hidden;
}

body.pregame {
  overflow: hidden;
}

body.pregame .table-wrap {
  visibility: hidden;
}

.start-screen {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    radial-gradient(circle at 20% 10%, rgb(18 67 63 / 55%), transparent 42%),
    radial-gradient(circle at 80% 25%, rgb(10 42 40 / 50%), transparent 46%),
    rgb(5 18 17 / 92%);
}

.start-screen[hidden] {
  display: none;
}

.start-screen-panel {
  width: min(94vw, 520px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #0f3d3a;
  padding: 1rem;
  display: grid;
  gap: 0.75rem;
}

.start-screen-panel h2 {
  margin: 0;
}

.start-screen-panel p {
  color: var(--muted);
}

.room-panel {
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 12px;
  background: rgb(5 23 22 / 28%);
  padding: 0.75rem;
  display: grid;
  gap: 0.65rem;
}

.room-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.room-panel-head h3 {
  margin: 0;
  font-size: 0.98rem;
}

.room-status-badge,
.room-live-badge {
  border: 1px solid rgb(255 255 255 / 16%);
  border-radius: 999px;
  background: rgb(255 255 255 / 8%);
  color: var(--ink);
  padding: 0.22rem 0.58rem;
  font-size: 0.75rem;
  line-height: 1.2;
}

.room-help-text {
  font-size: 0.9rem;
  line-height: 1.35;
}

.room-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.room-row-secondary {
  justify-content: space-between;
}

.room-id-input {
  min-width: 0;
  flex: 1 1 140px;
  text-transform: uppercase;
}

.room-code-label {
  color: var(--ink);
  font-size: 0.88rem;
  word-break: break-word;
}

.room-leave-btn {
  background: #4d1b1b;
}

.room-live-badge {
  position: absolute;
  left: 0.9rem;
  top: 0.9rem;
  z-index: 32;
  backdrop-filter: blur(6px);
}

.zone-counter {
  border: 1px solid rgb(255 255 255 / 16%);
  border-radius: 999px;
  background: rgb(4 22 21 / 58%);
  color: var(--ink);
  padding: 0.16rem 0.44rem;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.2;
  backdrop-filter: blur(4px);
  white-space: nowrap;
}

.zone-counter-opponent {
  border-color: rgb(245 170 66 / 34%);
  background: rgb(22 17 6 / 56%);
}

.start-screen-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  padding: 1.1rem 1.1rem 0.6rem;
}

/* Hide legacy page header: keep only table + start modal flow. */
.topbar {
  display: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.game-select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0b3330;
  color: var(--ink);
  padding: 0.43rem 0.52rem;
  font: inherit;
  min-width: 180px;
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.1vw, 1.8rem);
}

p,
h2 {
  margin: 0;
}

.topbar p {
  margin-top: 0.3rem;
  color: var(--muted);
}

.catalog-link {
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  background: #0b3330;
  border-radius: 10px;
  padding: 0.46rem 0.65rem;
}

.fullscreen-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #174846;
  color: var(--ink);
  padding: 0.46rem 0.65rem;
  font: inherit;
  cursor: pointer;
}

.table-wrap {
  padding: 0;
  min-height: 100dvh;
}

.playmat {
  position: relative;
  --controls-lane: calc(var(--main-card-width) + 1.2rem);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.9rem 0.9rem 6.9rem;
  background: linear-gradient(160deg, #14514d, #103e3a);
  box-shadow: 0 10px 30px rgb(0 0 0 / 25%);
  display: grid;
  gap: 0.9rem;
  min-height: 100dvh;
  height: 100dvh;
  overflow: clip;
  border-radius: 0;
  border: 0;
  box-shadow: none;
}

.board-cards-layer {
  position: absolute;
  left: 0.9rem;
  right: calc(0.9rem + var(--controls-lane));
  top: calc(30% + 1.3rem);
  bottom: 0.9rem;
  z-index: 15;
  --grid-cols: 30;
  --grid-rows: 18;
  --grid-cell: 24px;
  --grid-offset-x: 0px;
  --grid-offset-y: 0px;
  background:
    linear-gradient(to right, rgb(255 255 255 / 8%) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(255 255 255 / 8%) 1px, transparent 1px);
  background-size: var(--grid-cell) var(--grid-cell), var(--grid-cell) var(--grid-cell);
  background-position: var(--grid-offset-x) var(--grid-offset-y), var(--grid-offset-x) var(--grid-offset-y);
  border: 1px dashed rgb(255 255 255 / 14%);
  border-radius: 10px;
}

.opponent-field {
  position: absolute;
  left: 0.9rem;
  right: calc(0.9rem + var(--controls-lane));
  top: 0.9rem;
  height: 28%;
  min-height: 130px;
  z-index: 14;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 12px;
  background: rgb(4 22 21 / 42%);
  overflow: hidden;
}

.field-header {
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  top: 0.45rem;
  z-index: 2;
  color: var(--muted);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
}

.opponent-board-layer,
.opponent-marker-layer {
  position: absolute;
  left: 0.4rem;
  right: 0.4rem;
  top: 1.6rem;
  bottom: 0.4rem;
  border-radius: 10px;
}

.opponent-board-layer {
  background:
    linear-gradient(to right, rgb(255 255 255 / 6%) 1px, transparent 1px),
    linear-gradient(to bottom, rgb(255 255 255 / 6%) 1px, transparent 1px);
  background-size: var(--grid-cell) var(--grid-cell), var(--grid-cell) var(--grid-cell);
  background-position: var(--grid-offset-x) var(--grid-offset-y), var(--grid-offset-x) var(--grid-offset-y);
  border: 1px dashed rgb(255 255 255 / 10%);
}

.opponent-marker-layer {
  pointer-events: none;
}

.field-guide {
  position: absolute;
  z-index: 12;
  pointer-events: none;
}

.field-guide .guide-active,
.field-guide .guide-bench {
  position: absolute;
  border: 1px dashed rgb(255 255 255 / 26%);
  border-radius: 10px;
  color: rgb(255 255 255 / 72%);
  font-size: 0.72rem;
  display: grid;
  place-items: center;
  backdrop-filter: blur(1px);
}

.self-guide {
  left: 0.9rem;
  right: calc(0.9rem + var(--controls-lane));
  top: calc(30% + 1.3rem);
  bottom: 0.9rem;
}

.self-guide .guide-active {
  width: var(--grid-card-width, var(--play-card-width));
  aspect-ratio: 5 / 7;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  height: auto;
}

.self-guide .guide-bench {
  left: 12%;
  right: 12%;
  top: 58%;
  height: calc(var(--grid-card-width, var(--play-card-width)) * 7 / 5);
}

.opponent-guide {
  left: 0.4rem;
  right: 0.4rem;
  top: 1.6rem;
  bottom: 0.4rem;
}

.opponent-guide .guide-active {
  width: var(--opponent-card-width, var(--grid-card-width, var(--play-card-width)));
  aspect-ratio: 5 / 7;
  left: 50%;
  top: 70%;
  transform: translate(-50%, -50%);
  height: auto;
}

.opponent-guide .guide-bench {
  left: 18%;
  right: 18%;
  top: 11%;
  height: calc(var(--opponent-card-width, var(--grid-card-width, var(--play-card-width))) * 7 / 5);
}

.table-controls {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  z-index: 30;
  display: grid;
  width: var(--controls-lane);
  gap: 0.32rem;
  justify-items: center;
}

.board-card {
  position: absolute;
  width: var(--grid-card-width, var(--play-card-width));
  height: auto !important;
  aspect-ratio: 5 / 7;
  transform: none;
  cursor: grab;
  border-radius: 11px;
  overflow: hidden;
}

.opponent-board-layer .board-card {
  cursor: default;
}

.board-card.drag-source {
  opacity: 0.35;
}

.locked-shared-item {
  outline: 2px solid rgb(255 255 255 / 18%);
  outline-offset: 1px;
}

.board-card.locked-shared-item,
.marker-item.locked-shared-item {
  cursor: not-allowed;
}

.board-snap-preview {
  position: absolute;
  width: var(--grid-card-width, var(--play-card-width));
  aspect-ratio: 5 / 7;
  border: 2px dashed rgb(245 170 66 / 90%);
  border-radius: 11px;
  background: rgb(245 170 66 / 16%);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 35%);
  pointer-events: none;
  z-index: 28;
}

.marker-layer {
  position: absolute;
  inset: 0;
  z-index: 18;
  pointer-events: none;
}

.marker-item {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgb(255 255 255 / 70%);
  color: #fff;
  font: inherit;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 10px rgb(0 0 0 / 35%);
  cursor: grab;
  pointer-events: auto;
  padding: 0;
  touch-action: none;
  user-select: none;
}

.marker-item.drag-hidden {
  opacity: 0;
}

.marker-burn {
  background: #cf4f2e;
}

.marker-poison {
  background: #6b4fc7;
}

.marker-dmg10 {
  background: #8f8f8f;
}

.marker-dmg50 {
  background: #5f6f7a;
}

.marker-dmg100 {
  background: #33414d;
}

.marker-bag-wrap {
  display: grid;
  justify-items: center;
  align-items: start;
}

.prize-wrap {
  display: grid;
  justify-items: center;
  align-items: start;
}

.marker-bag-btn {
  position: relative;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #174846;
  color: var(--ink);
  font-size: 1.08rem;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.prize-draw-btn {
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 11px;
  background:
    radial-gradient(circle at 28% 24%, rgb(255 255 255 / 22%) 0%, transparent 38%),
    linear-gradient(145deg, #1b5f5c, #103f3c);
  color: var(--ink);
  font: inherit;
  font-size: 0.66rem;
  font-weight: 600;
  width: min(100%, var(--main-card-width));
  aspect-ratio: 5 / 7;
  min-height: 0;
  padding: 0.35rem;
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.15;
  cursor: pointer;
  box-shadow: 0 4px 14px rgb(0 0 0 / 24%);
}

.prize-draw-btn:disabled {
  opacity: 0.65;
  cursor: default;
}

.marker-bag-modal-panel {
  width: min(94vw, 520px);
}

.marker-catalog {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.marker-catalog-item {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 1px solid rgb(255 255 255 / 70%);
  color: #fff;
  font: inherit;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1.05;
  display: grid;
  place-items: center;
  text-align: center;
  cursor: grab;
  padding: 0.24rem;
  touch-action: none;
  user-select: none;
}

.marker-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgb(255 255 255 / 80%);
  color: #fff;
  font: inherit;
  font-size: 0.62rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 14000;
  box-shadow: 0 3px 10px rgb(0 0 0 / 35%);
}

body.fullscreen-mode .topbar {
  display: none;
}

body.fullscreen-mode .table-wrap {
  padding: 0;
  height: 100dvh;
  min-height: 100dvh;
}

body.fullscreen-mode .playmat {
  min-height: 100dvh;
  height: 100dvh;
  --controls-lane: calc(var(--main-card-width) + 1rem);
  border-radius: 0;
  border: 0;
  box-shadow: none;
  padding: 0.7rem 0.7rem 6.6rem;
}

body.fullscreen-mode .board-cards-layer {
  left: 0.7rem;
  right: calc(0.7rem + var(--controls-lane));
  top: calc(30% + 1.1rem);
  bottom: 0.7rem;
}

body.fullscreen-mode .opponent-field {
  left: 0.7rem;
  right: calc(0.7rem + var(--controls-lane));
  top: 0.7rem;
}

body.fullscreen-mode .self-guide {
  left: 0.7rem;
  right: calc(0.7rem + var(--controls-lane));
  top: calc(30% + 1.1rem);
  bottom: 0.7rem;
}

body.fullscreen-mode .table-controls {
  top: 0.7rem;
  right: 0.7rem;
}

body.fullscreen-mode {
  overflow: hidden;
}

.zone {
  border: 1px dashed var(--line);
  border-radius: 5px;
  background: rgb(11 41 39 / 45%);
  padding: 0.65rem;
}

.active.card-zone,
.slot.card-zone,
.side-slot.card-zone,
.discard-zone,
.deck-zone {
  padding: 0;
}

.zone h2 {
  font-size: 0.95rem;
}

.zone p {
  color: var(--muted);
  margin-top: 0.28rem;
  font-size: 0.9rem;
}

.deck-zone {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.deck-main-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #174846;
  color: var(--ink);
  width: min(92%, 110px);
  height: min(84%, 148px);
  font: inherit;
  font-size: clamp(0.7rem, 1.4vw, 0.95rem);
  cursor: pointer;
  margin: auto;
  display: grid;
  place-items: center;
  text-align: center;
  line-height: 1.1;
  appearance: none;
  -webkit-appearance: none;
}

.deck-actions {
  display: grid;
  gap: 0.25rem;
  width: 100%;
  max-width: 100%;
  justify-items: center;
  align-content: center;
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.deck-actions-modal-list {
  display: grid;
  gap: 0.36rem;
}

.deck-actions-modal-list .draw-btn {
  width: 100%;
  min-width: 0;
  margin-top: 0;
}

.draw-btn {
  margin-top: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #174846;
  color: var(--ink);
  padding: clamp(0.18rem, 0.8vw, 0.32rem) clamp(0.24rem, 1.1vw, 0.52rem);
  font: inherit;
  font-size: clamp(0.58rem, 1.2vw, 0.84rem);
  line-height: 1.1;
  cursor: pointer;
  width: auto;
  min-width: max-content;
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
}

.discard-top-card {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.discard-wrap {
  display: grid;
  gap: 0.22rem;
  justify-items: center;
}

.deck-wrap {
  display: grid;
  gap: 0.22rem;
  justify-items: center;
}

.deck-label-outside {
  font-size: 0.86rem;
  color: var(--muted);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}

#statPlayerDeck {
  border-color: rgb(95 180 165 / 45%);
}

.discard-label-outside {
  font-size: 0.86rem;
  color: var(--muted);
}

.discard-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.board-layout {
  display: grid;
  grid-template-columns: calc(var(--small-card-width) + 18px) 1fr calc(var(--main-card-width) + 28px);
  gap: 0.8rem;
  height: 100%;
  align-content: start;
}

.prizes-column,
.right-column {
  display: grid;
  align-content: start;
  gap: 0.35rem;
}

.prizes-column h2,
.right-column h2,
.hand-row h2 {
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.prize-column-grid {
  display: grid;
  gap: 0.45rem;
}

.center-play {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  gap: 0.55rem;
  justify-content: space-between;
}

.active-line {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(2.8rem, 9vw, 10rem);
}

.active-line .card-zone {
  position: relative;
}

.active-line .slot-label {
  position: absolute;
  left: -1.35rem;
  top: 0.2rem;
  margin: 0;
  writing-mode: vertical-rl;
  text-orientation: upright;
  white-space: normal;
}

.active {
  justify-self: center;
}

.bench-slots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.bench-row {
  margin-top: 0;
}

.bench-wrap {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
}

.bench-side-label {
  position: absolute;
  left: calc(50% - (2.5 * var(--play-card-width)) - 2.2rem);
  top: 0.2rem;
  color: var(--muted);
  font-size: 0.86rem;
  writing-mode: vertical-rl;
  text-orientation: upright;
  transform: none;
  letter-spacing: 0.02em;
}

.slot {
  display: grid;
  place-items: center;
}

.prize span {
  color: var(--muted);
}

.prize-facedown {
  width: 86%;
  max-width: 100%;
  aspect-ratio: 5 / 7;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1a4f4d;
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 0.56rem;
  text-align: center;
  padding: 0.2rem;
  justify-self: center;
  align-self: center;
  margin: auto;
}

.prize .slot-content {
  display: grid;
  place-items: center;
  justify-items: center;
  align-items: center;
  width: 100%;
  height: 100%;
  position: relative;
}

.prize .slot-content > * {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.slot-label {
  position: static;
  display: block;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.15;
  color: var(--muted);
  margin-bottom: 0.22rem;
  white-space: nowrap;
}

.slot-content {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
}

.active.card-zone,
.slot.card-zone,
.side-slot.card-zone {
  display: flex;
  flex-direction: column;
}

.drop-target {
  transition: box-shadow 120ms ease, border-color 120ms ease;
}

.drop-target.drop-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(245 170 66 / 55%);
}

.drop-target.has-card .slot-label {
  color: #9eb8af;
}

.right-column {
  gap: 0.7rem;
}

/* All card zones keep the same trading-card ratio. */
.card-zone {
  width: var(--main-card-width);
  aspect-ratio: 5 / 7;
  min-height: 0;
  flex: 0 0 auto;
}

.active.card-zone {
  width: var(--play-card-width);
}

.right-column .card-zone {
  width: var(--main-card-width);
}

.prize-column-grid .card-zone {
  width: var(--small-card-width);
}

.side-slot.card-zone {
  width: var(--play-card-width);
  margin-top: calc(var(--play-card-width) * 7 / 5);
}

.bench-slots .card-zone {
  width: var(--play-card-width);
}

.hand-row {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  border: 1px solid var(--accent);
  border-radius: 14px;
  min-height: 118px;
  max-height: none;
  height: auto;
  overflow: visible;
  padding: 0.65rem 0.65rem 1rem;
  background: linear-gradient(180deg, rgb(245 170 66 / 14%), rgb(245 170 66 / 6%));
}

.hand-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.6rem;
}

#statPlayerHand {
  border-color: rgb(95 180 165 / 45%);
}

.hand-toggle-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #174846;
  color: var(--ink);
  padding: 0.36rem 0.55rem;
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  margin-left: auto;
}

.zone-counter-opponent-deck {
  position: absolute;
  right: 0.6rem;
  top: 0.45rem;
  z-index: 3;
}

.zone-counter-opponent-hand {
  position: absolute;
  left: 0.6rem;
  top: 2rem;
  z-index: 3;
}

.hand-row p {
  margin-top: 0.35rem;
  color: var(--muted);
}

.hand-cards {
  margin-top: 0.55rem;
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 0.3rem;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-gutter: stable both-edges;
  width: 100%;
  padding-bottom: 0.35rem;
}

.hand-card {
  flex: 0 0 auto;
  width: var(--hand-card-width, 92px);
  aspect-ratio: 5 / 7;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #154746;
  padding: 0;
  display: block;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.hand-card.drag-source {
  opacity: 0.35;
}

.card-image {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: contain;
  border: 0;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}

.card-facedown {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background:
    radial-gradient(circle at 28% 24%, rgb(255 255 255 / 22%) 0%, transparent 38%),
    linear-gradient(145deg, #1b5f5c, #103f3c);
  border: 1px solid rgb(255 255 255 / 24%);
}

.hand-card .card-image {
  object-fit: cover;
}

.card-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.7rem;
}

.discard-card-btn {
  justify-self: end;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #4d1b1b;
  color: var(--ink);
  padding: 0.16rem 0.28rem;
  font: inherit;
  font-size: 0.55rem;
  cursor: pointer;
}

.placed-card {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  padding: 0;
  display: block;
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

/* Keep placed cards absolutely positioned on the board layer.
   This must override the generic .placed-card rule above. */
.placed-card.board-card {
  position: absolute;
  width: var(--grid-card-width, var(--play-card-width));
  height: auto;
  aspect-ratio: 5 / 7;
}

.placed-card .card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.attached-slots {
  position: absolute;
  left: 0.26rem;
  bottom: 0.26rem;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.attachment-drop {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgb(10 35 34 / 85%);
  color: var(--ink);
  width: 2.05rem;
  height: 2.05rem;
  padding: 0;
  line-height: 1.05;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-items: center;
  text-align: center;
}

.drag-action-hint {
  position: fixed;
  left: 0;
  top: 0;
  transform: none;
  z-index: 13000;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgb(10 35 34 / 92%);
  color: var(--ink);
  padding: 0.32rem 0.58rem;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: 0 6px 16px rgb(0 0 0 / 35%);
  pointer-events: none;
}

.drag-action-hint[hidden] {
  display: none;
}

.attachment-energy {
  border-color: #bf8546;
}

.attachment-item {
  border-color: #5b88c9;
}

.attachment-drop.drop-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(245 170 66 / 55%);
}

.active-attach-row.drop-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(245 170 66 / 55%);
}

.active-card-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}

.active-attachments-preview-outside {
  position: absolute;
  left: calc(100% + 0.38rem);
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  max-width: min(22vw, 240px);
}

.active-attach-row {
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 0.14rem;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  overflow-x: auto;
  overflow-y: hidden;
}

.active-attach-row.energy-row {
  border-color: transparent;
}

.active-attach-row.item-row {
  border-color: transparent;
}

.attachment-mini-card-btn {
  flex: 0 0 auto;
  width: 2.5rem;
  aspect-ratio: 5 / 7;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.attachment-mini-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 2px;
}

.attachment-mini-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 0.42rem;
  color: var(--muted);
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  width: 70px;
  aspect-ratio: 5 / 7;
  opacity: 0.72;
  pointer-events: none;
  z-index: 9999;
}

.card-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
}

#discardModal {
  z-index: 10000;
}

#cardModal {
  z-index: 11000;
}

.card-modal[hidden] {
  display: none;
}

.card-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 56%);
}

.card-modal-panel {
  position: relative;
  z-index: 2;
  width: min(92vw, 390px);
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #103a38;
}

.card-modal-close {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #174846;
  color: var(--ink);
  padding: 0.34rem 0.54rem;
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  margin-bottom: 0.6rem;
}

.discard-modal-panel {
  width: min(94vw, 980px);
  max-height: min(90vh, 760px);
  display: flex;
  flex-direction: column;
}

.discard-modal-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.deck-close-prompt-actions {
  display: grid;
  gap: 0.4rem;
}

.deck-close-prompt-text {
  margin: 0 0 0.7rem;
  color: var(--muted);
}

.deck-close-prompt-actions .draw-btn {
  width: 100%;
}

.discard-list {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 0.35rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.2rem 0.1rem 0.6rem;
}

.discard-list-card {
  cursor: pointer;
  width: 118px;
  flex: 0 0 auto;
  position: relative;
}

#attachmentsModal .discard-list-card {
  width: 148px;
}

.discard-list-card:hover {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.discard-list-card .hand-card-name {
  display: none;
}

.discard-list-card .hand-card-meta {
  display: none;
}

.discard-item-btn {
  position: absolute;
  right: 0.26rem;
  bottom: 0.26rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #174846;
  color: var(--ink);
  padding: 0.18rem 0.32rem;
  font: inherit;
  font-size: 0.55rem;
  cursor: pointer;
}

.deck-item-btn {
  position: absolute;
  right: 0.26rem;
  bottom: 0.26rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #174846;
  color: var(--ink);
  padding: 0.18rem 0.32rem;
  font: inherit;
  font-size: 0.55rem;
  cursor: pointer;
}

.attachment-main-btn,
.attachment-discard-btn {
  position: absolute;
  right: 0.26rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  padding: 0.16rem 0.3rem;
  font: inherit;
  font-size: 0.55rem;
  cursor: pointer;
}

.attachment-main-btn {
  bottom: 1.55rem;
  background: #174846;
}

.attachment-discard-btn {
  bottom: 0.26rem;
  background: #4d1b1b;
}

.deck-list-card {
  cursor: pointer;
  width: 118px;
  flex: 0 0 auto;
  position: relative;
}

.deck-list-card:hover {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.discard-list-empty {
  color: var(--muted);
  margin: 0;
}

.discard-top-card .placed-card {
  width: 100%;
  height: 100%;
}

@media (max-width: 700px) {
  .discard-modal-panel {
    width: 95vw;
    max-height: 90vh;
  }

  .discard-list-card {
    width: 90px;
  }
}

.card-preview {
  margin-inline: auto;
  width: min(75vw, 300px);
  aspect-ratio: 5 / 7;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  display: block;
  overflow: hidden;
}

.card-preview .modal-card {
  width: 100%;
  height: 100%;
}

.card-preview .modal-card .card-image {
  object-fit: cover;
}

.card-preview .hand-card-name {
  display: none;
}

.card-preview .hand-card-meta {
  display: none;
}

body.hand-hidden .hand-row {
  display: none;
}

body.hand-hidden .playmat {
  padding-bottom: 1rem;
}

.show-hand-btn {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 25;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #174846;
  color: var(--ink);
  padding: 0.48rem 0.65rem;
  font: inherit;
  cursor: pointer;
}

body.hand-hidden .show-hand-btn {
  display: inline-block;
}

.show-hand-btn[hidden] {
  display: none;
}

.show-hand-btn.drop-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(245 170 66 / 55%);
}

.deck-zone.drop-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(245 170 66 / 55%);
}

.marker-bag-btn.drop-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgb(245 170 66 / 55%);
}

.marker-bag-btn.delete-ready {
  border-color: #c93f3f;
  background: #5a1d1d;
  box-shadow: 0 0 0 2px rgb(201 63 63 / 55%);
}

.action-toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 12000;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #174846;
  color: var(--ink);
  padding: 0.48rem 0.75rem;
  font-size: 0.88rem;
  box-shadow: 0 6px 18px rgb(0 0 0 / 30%);
}

.action-toast[hidden] {
  display: none;
}

@media (max-width: 980px) {
  :root {
    --main-card-width: clamp(64px, min(11.6vw, 8.6dvh), 98px);
    --small-card-width: clamp(40px, min(7.2vw, 5.4dvh), 62px);
    --play-card-width: clamp(78px, min(13.8vw, 10.4dvh), 126px);
  }

  .board-layout {
    grid-template-columns: calc(var(--small-card-width) + 10px) 1fr calc(var(--main-card-width) + 16px);
    gap: 0.45rem;
    height: auto;
  }

  .active-line {
    gap: clamp(0.5rem, 2.4vw, 1.2rem);
  }

  .side-slot.card-zone {
    margin-top: calc(var(--play-card-width) * 0.75);
  }

  .active-attachments-preview-outside {
    max-width: min(18vw, 128px);
  }

  .attachment-mini-card-btn {
    width: 1.8rem;
  }

  .right-column {
    gap: 0.45rem;
  }

  .right-column .card-zone {
    width: var(--main-card-width);
  }

  .deck-zone {
    padding: 0.16rem;
    align-items: center;
    justify-content: center;
    overflow: visible;
  }

  .deck-actions {
    gap: 0.16rem;
    justify-items: stretch;
    align-content: start;
    max-height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.08rem;
  }

  .draw-btn {
    margin-top: 0.14rem;
    width: 100%;
    min-width: 0;
    font-size: clamp(0.52rem, 1.6vw, 0.64rem);
    padding: 0.16rem 0.22rem;
    border-radius: 6px;
  }

  .prize-facedown {
    width: 70%;
    font-size: 0.44rem;
    padding: 0.08rem;
  }

  .bench-wrap {
    width: 100%;
  }

  .hand-row {
    left: 0.8rem;
    right: 0.8rem;
    bottom: 0.8rem;
  }

  .show-hand-btn {
    right: 0.8rem;
    bottom: 0.8rem;
  }
}

@media (max-width: 640px) {
  :root {
    --main-card-width: clamp(56px, min(11vw, 7.6dvh), 82px);
    --small-card-width: clamp(36px, min(6.8vw, 4.8dvh), 54px);
    --play-card-width: clamp(68px, min(12.6vw, 8.8dvh), 102px);
  }

  .active-line {
    gap: 0.35rem;
  }

  .active-line .slot-label {
    left: -1.15rem;
    top: 0.1rem;
    font-size: 0.62rem;
  }

  .bench-side-label {
    display: none;
  }

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

  .room-row-secondary {
    align-items: stretch;
  }

  .room-live-badge {
    left: 0.5rem;
    top: 0.5rem;
    max-width: calc(100vw - 1rem);
  }

  .top-actions {
    width: 100%;
  }

  .prizes-column h2 {
    font-size: 0.76rem;
    margin-bottom: 0.24rem;
  }

  .prize-column-grid {
    gap: 0.22rem;
  }

  .prize-facedown {
    width: 58%;
    font-size: 0.36rem;
    padding: 0.06rem;
  }

  .table-wrap {
    padding: 0.35rem 0.45rem 0.55rem;
  }

  .playmat {
    --controls-lane: calc(var(--main-card-width) + 0.85rem);
    padding: 0.5rem 0.5rem 8.2rem;
    gap: 0.45rem;
  }

  .board-cards-layer {
    left: 0.5rem;
    right: calc(0.5rem + var(--controls-lane));
    top: 0.5rem;
    bottom: 0.5rem;
  }

  .table-controls {
    top: 0.5rem;
    right: 0.5rem;
    gap: 0.22rem;
  }

  .side-slot.card-zone {
    margin-top: calc(var(--play-card-width) * 0.2);
  }

  .active-attachments-preview-outside {
    left: 0;
    right: auto;
    top: calc(100% + 0.18rem);
    flex-direction: row;
    gap: 0.18rem;
    max-width: calc(100% - 0.2rem);
  }

  .active-attach-row {
    max-width: 48%;
    overflow-x: auto;
  }

  .attachment-mini-card-btn {
    width: 1.55rem;
  }

  .attachment-drop {
    width: 1.65rem;
    height: 1.65rem;
    font-size: 0.62rem;
  }

  .bench-slots {
    gap: 0.28rem;
  }

  .hand-cards {
    gap: 0.2rem;
    padding-bottom: 0.25rem;
  }

  .deck-actions {
    gap: 0.14rem;
  }

  .draw-btn {
    margin-top: 0.14rem;
    font-size: 0.56rem;
    padding: 0.14rem 0.2rem;
    border-radius: 6px;
    width: 100%;
    min-width: 0;
  }

  .deck-zone {
    padding: 0.16rem;
    align-items: center;
    justify-content: center;
    overflow: visible;
  }
}

@media (max-width: 980px) {
  body.fullscreen-mode {
    --main-card-width: clamp(52px, min(10vw, 7.2dvh), 74px);
    --small-card-width: clamp(32px, min(6.2vw, 4.5dvh), 48px);
    --play-card-width: clamp(62px, min(11.4vw, 8dvh), 92px);
  }

  body.fullscreen-mode .playmat {
    padding: 0.42rem 0.42rem 7.6rem;
    gap: 0.35rem;
  }

  body.fullscreen-mode .active-line {
    gap: clamp(1.4rem, 9vw, 3.4rem);
    margin-top: 2.5rem;
  }

  body.fullscreen-mode .board-layout {
    height: auto;
  }

  body.fullscreen-mode .side-slot.card-zone {
    margin-top: calc(var(--play-card-width) * 0.5);
  }

  body.fullscreen-mode .bench-slots {
    gap: 0.22rem;
  }

  body.fullscreen-mode .active-line .slot-label {
    left: -1.05rem;
    font-size: 0.58rem;
  }

  body.fullscreen-mode .attachment-drop {
    width: 1.32rem;
    height: 1.32rem;
    font-size: 0.52rem;
    border-radius: 6px;
  }

  body.fullscreen-mode #cardModal .card-modal-panel {
    width: min(94vw, 440px);
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 0.8rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0.62rem;
  }

  body.fullscreen-mode #cardModal .card-preview {
    width: 100%;
    flex: 1;
    min-height: 0;
    height: auto;
    max-width: 100%;
    max-height: none;
    margin-inline: auto;
    display: grid;
    place-items: center;
    aspect-ratio: auto;
  }

  body.fullscreen-mode #cardModal .card-preview .modal-card {
    width: auto;
    height: min(82dvh, calc(100dvh - 6.4rem));
    max-width: 92vw;
    max-height: 100%;
    aspect-ratio: 5 / 7;
  }
}

@media (min-width: 1500px) and (min-height: 860px) {
  :root {
    --main-card-width: clamp(118px, min(13.8vw, 15.5dvh), 196px);
    --small-card-width: clamp(78px, min(9.8vw, 10.5dvh), 132px);
    --play-card-width: clamp(136px, min(16.5vw, 18.5dvh), 250px);
  }

  .playmat {
    padding-bottom: 7.4rem;
  }

}
