:root {
  --panel: #f4f0e6;
  --panel-strong: #fffaf0;
  --ink: #211b16;
  --muted: #6b6258;
  --line: #c9bda8;
  --accent: #b82f3d;
  --accent-ink: #fff7f0;
  --table: #27705d;
  --table-dark: #16463d;
  --monster: #b37b3e;
  --spell: #3a987f;
  --trap: #a34b85;
  --table-card-width: 120px;
  --hand-zone-height: 170px;
  --table-base-width: 1576px;
  --table-base-height: 912px;
  --table-scale: 1;
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto 1fr;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 30% 18%, rgba(214, 180, 98, 0.18), transparent 32rem),
    linear-gradient(135deg, #191c18, #2e2922 45%, #161a17);
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.import-button {
  border: 1px solid #171411;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  box-shadow: 0 2px 0 #15110f;
}

button:hover,
.import-button:hover {
  filter: brightness(1.06);
}

button:active,
.import-button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #15110f;
}

.app-header {
  grid-column: 2;
  grid-row: 1;
  display: none;
  justify-content: end;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem 0.75rem 0;
  color: #fff7ea;
}

body.admin-mode .app-header {
  display: flex;
}

.app-header > div:first-child {
  display: none;
}

.app-header h1,
.app-header p,
h2,
h3 {
  margin: 0;
}

.app-header h1 {
  font-size: clamp(1.7rem, 3vw, 2.6rem);
  letter-spacing: 0;
}

.app-header p {
  color: #decfb7;
  margin-top: 0.25rem;
}

.header-actions,
.form-actions,
.pool-actions,
.table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.header-actions {
  min-height: 2.65rem;
}

.sync-status {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  color: #231d16;
  background: #e8d6af;
  padding: 0.4rem 0.65rem;
  font-weight: 800;
}

.sync-status.online {
  background: #a9dfbe;
}

.sync-status.offline {
  background: #e9b0a6;
}

.import-button {
  display: inline-flex;
  align-items: center;
}

.import-button input {
  display: none;
}

.app-tabs {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 4.15rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.card-filters {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.8rem;
}

body.cards-mode .card-filters {
  display: flex;
}

.card-filters select,
.card-filters input {
  min-width: 9.5rem;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  color: #231d16;
  background: #fff8e9;
  padding: 0.5rem 0.65rem;
  font-weight: 800;
}

.current-player {
  align-self: center;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #231d16;
  background: #fff8e9;
  font-weight: 800;
}

.app-version {
  align-self: center;
  margin-left: auto;
  color: rgba(255, 247, 234, 0.82);
  font-weight: 800;
  white-space: nowrap;
}

main {
  grid-column: 1 / 3;
  grid-row: 2;
}

.tab-button {
  color: #fff7ea;
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.24);
  box-shadow: none;
}

.tab-button.active {
  color: var(--ink);
  background: var(--panel);
}

.view {
  display: none;
  padding: 1rem;
}

.view.active {
  display: block;
}

[hidden] {
  display: none !important;
}

#tableView.active {
  height: calc(100vh - 8.6rem);
  min-height: 34rem;
}

#cardsView.active {
  height: calc(100vh - 4.15rem);
  min-height: 0;
  overflow: hidden;
}

#decksView.active {
  height: calc(100vh - 4.15rem);
  min-height: 0;
  overflow: hidden;
}

#adminView.active {
  height: calc(100vh - 4.15rem);
  min-height: 0;
  overflow: hidden;
}

body.table-mode {
  display: grid;
  grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

body.table-mode .app-header {
  display: none;
}

body.table-mode .app-tabs {
  grid-column: 1;
  grid-row: 1;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 0.75rem;
  border-bottom: 0;
  background: var(--panel-strong);
}

body.table-mode .current-player {
  order: -3;
  grid-column: 1 / 3;
  margin: 0 0 0.5rem;
  text-align: center;
}

body.table-mode .app-version {
  order: -2;
  display: block;
  grid-column: 3;
  margin: 0 0 0.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #231d16;
  background: #fff8e9;
  font-weight: 900;
  text-align: center;
}

body.table-mode::before {
  content: "";
  position: fixed;
  inset: 0 auto 0 0;
  width: min(21rem, 100vw);
  background: var(--panel-strong);
  z-index: 0;
}

body.table-mode .tab-button {
  color: #231d16;
  background: #eadfc8;
  border-color: var(--line);
}

body.table-mode .tab-button.active {
  background: #fff8e9;
  border-color: var(--accent);
}

body.table-mode main {
  display: contents;
}

body.table-mode #tableView.active {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
  height: 100vh;
  min-height: 0;
  padding: 0;
  z-index: 1;
}

body.table-mode #cardsView,
body.table-mode #decksView,
body.table-mode #homeView,
body.table-mode #adminView {
  display: none;
}

body.table-mode .table-panel {
  grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr);
  grid-template-rows: 1fr;
  grid-template-areas:
    "controls board";
  height: 100vh;
  padding: 0;
  gap: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

body.table-mode .table-surface {
  border-radius: 0;
  border-width: 0 0 0 8px;
}

body.table-mode .table-toolbar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  align-content: stretch;
  gap: 0.5rem;
  margin-top: 10rem;
  height: calc(100vh - 10rem);
  max-height: calc(100vh - 10rem);
  overflow: hidden;
  padding-top: 0.5rem;
  border-radius: 0;
  border-width: 0;
  background: var(--panel-strong);
  box-shadow: none;
}

body.table-mode .table-title-block {
  display: none;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(19rem, 24rem) minmax(22rem, 1fr);
  gap: 1rem;
}

.card-register-layout {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.card-register-layout .editor-panel,
.card-register-layout .pool-panel {
  min-height: 0;
}

.card-register-layout .pool-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.two-column.wide-left {
  grid-template-columns: minmax(26rem, 34rem) minmax(24rem, 1fr);
}

.deck-build-layout {
  height: 100%;
  min-height: 0;
}

.deck-build-layout > .panel {
  min-height: 0;
  overflow: auto;
}

.panel,
.table-panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.26);
}

.panel {
  padding: 1rem;
  overflow: auto;
}

.panel-heading,
.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-form,
.deck-form {
  display: grid;
  gap: 0.8rem;
  margin-top: 1rem;
}

.deck-name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.deck-card-filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 1rem;
}

.card-basic-row {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(8rem, 10rem) minmax(5.5rem, 7rem);
  gap: 0.65rem;
  align-items: end;
}

.home-panel {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1.1rem;
}

.home-player {
  display: grid;
  gap: 0.85rem;
  margin-top: 1rem;
}

.player-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  margin-top: 1rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fffdf7;
  padding: 0.55rem 0.65rem;
}

textarea {
  resize: vertical;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.tag-edit-row {
  display: grid;
  grid-template-columns: auto minmax(8rem, 14rem) minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-weight: 700;
}

.tag-chip-list {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
}

.tag-chip {
  flex: 0 0 auto;
  border-color: rgba(0, 0, 0, 0.18);
  background: #eadfc8;
  color: #231d16;
  padding: 0.38rem 0.55rem;
  box-shadow: none;
}

.tag-filter-popup {
  position: absolute;
  z-index: 3000;
  display: grid;
  gap: 0.15rem;
  max-height: 13rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffdf7;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
  padding: 0.25rem;
}

.tag-filter-popup[hidden] {
  display: none;
}

.tag-filter-popup button {
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
  padding: 0.38rem 0.5rem;
  text-align: left;
}

.tag-filter-popup button:hover {
  background: #eadfc8;
  filter: none;
}

.inline-field {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
}

.image-file-field {
  grid-template-columns: 3.5rem minmax(0, 1fr);
}

.image-paste-box {
  display: grid;
  gap: 0.4rem;
  border: 1px dashed #8f806c;
  border-radius: 8px;
  background: #fff8e9;
  padding: 0.55rem;
  cursor: text;
}

.paste-image-button {
  color: #231d16;
  background: #eadfc8;
}

.image-paste-box:focus {
  outline: 3px solid rgba(184, 47, 61, 0.25);
  border-color: var(--accent);
}

.image-paste-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.image-preview {
  display: grid;
  place-items: center;
  min-height: 6.5rem;
  border-radius: 6px;
  background: #eee4d2;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  overflow: hidden;
}

.image-preview.has-image {
  background: #1f1b17;
}

.image-preview img {
  width: 100%;
  max-height: 12rem;
  object-fit: contain;
}

.counter {
  color: #fff8e9;
  background: #4a3c2f;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  white-space: nowrap;
}

.card-pool,
.deck-list,
.hand-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
}

.pool-panel .card-pool {
  min-height: 0;
  overflow: auto;
  padding-right: 0.25rem;
}

.card-pool.compact {
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
}

.pool-card,
.deck-card,
.hand-card {
  display: grid;
  grid-template-columns: 6.3rem 1fr;
  gap: 0.75rem;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.deck-card,
.hand-card {
  grid-template-columns: 1fr;
}

.deck-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(184, 47, 61, 0.18);
}

.pool-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0.35rem 0 0.45rem;
}

.pool-tag {
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 999px;
  background: #eadfc8;
  color: #382c20;
  padding: 0.16rem 0.45rem;
  font-size: 0.78rem;
  font-weight: 800;
}

.deck-card-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.75rem;
}

.deck-card-heading p {
  margin: 0;
  text-align: right;
  white-space: nowrap;
}

.deck-section {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.deck-section h4 {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.deck-lines {
  display: grid;
  gap: 0.45rem;
}

.deck-line {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem;
  border-radius: 6px;
  background: #efe5d1;
}

.deck-line button {
  padding: 0.25rem 0.45rem;
  color: #231d16;
  background: #fff8e9;
}

.pool-info {
  min-width: 0;
}

.pool-info h3,
.deck-card h3 {
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.pool-info p,
.deck-card p,
.empty-note {
  color: var(--muted);
  line-height: 1.45;
  margin: 0.35rem 0 0.7rem;
  overflow-wrap: anywhere;
}

.pool-actions button,
.table-actions button,
#resetButton,
#resetDeckButton {
  color: #231d16;
  background: #eadfc8;
}

.mini-card,
.table-card-face {
  aspect-ratio: 59 / 86;
  border-radius: 6px;
  border: 3px solid #14100d;
  background: var(--monster);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.38);
  overflow: hidden;
}

.table-panel {
  display: grid;
  grid-template-columns: minmax(14rem, 1fr) minmax(15rem, 18rem);
  grid-template-rows: 1fr;
  grid-template-areas:
    "board controls";
  gap: 1rem;
  height: 100%;
  min-height: 0;
  padding: 1rem;
}

.table-toolbar {
  grid-area: controls;
  display: grid;
  align-content: start;
  justify-content: stretch;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.table-toolbar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.table-chat-panel {
  display: none;
}

body.table-mode .table-chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.5rem;
  height: 100%;
  min-height: 0;
  margin-top: 0;
  overflow: hidden;
}

.table-chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.chat-message {
  flex: 0 0 auto;
  display: grid;
  gap: 0.18rem;
  padding: 0.48rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff8e9;
  cursor: pointer;
}

.chat-message.own {
  background: #eadfc8;
}

.chat-message:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-meta {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.chat-text {
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
}

.seat-panel {
  display: grid;
  gap: 0.5rem;
  margin-top: 0;
}

.seat-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.5rem;
}

.seat-status {
  justify-self: end;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.side-player-panel {
  display: grid;
  gap: 0.35rem;
}

.side-version {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff8e9;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

body.table-mode .side-version {
  display: none;
}

body.table-mode .side-player-panel {
  display: none;
}

.side-player-name {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff8e9;
  font-weight: 900;
}

.debug-panel {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.debug-panel label {
  gap: 0.25rem;
}

.debug-panel label span {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.debug-panel output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.debug-panel input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
}

.seat-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
}

body.table-mode .seat-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.seat-actions button {
  color: #231d16;
  background: #eadfc8;
}

.seat-actions button.active {
  background: #fff8e9;
  border-color: var(--accent);
}

.seat-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) minmax(14rem, 0.85fr) minmax(22rem, 1.35fr);
  gap: 1rem;
  align-items: stretch;
  height: 100%;
  min-height: 0;
}

.admin-layout > .panel {
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.admin-seat-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 1rem;
  height: 100%;
  min-height: 0;
}

.admin-seat-stack > .panel {
  min-height: 0;
  overflow: auto;
}

.admin-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.admin-log-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.admin-log-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 0.5rem;
}

.admin-log-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 1rem;
  min-height: 0;
  overflow: auto;
  padding-right: 0.25rem;
}

.log-row {
  display: grid;
  gap: 0.2rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff8e9;
}

.log-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.log-summary {
  overflow-wrap: anywhere;
  font-weight: 800;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff8e9;
}

.admin-row span:first-child {
  font-weight: 900;
  overflow-wrap: anywhere;
}

.table-actions select {
  width: 100%;
}

.table-play-area {
  display: contents;
}

.play-table {
  grid-area: board;
  position: relative;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  border-radius: 8px;
  background: #102b26;
}

.table-surface {
  position: absolute;
  left: 50%;
  top: 50%;
  box-sizing: content-box;
  width: var(--table-base-width);
  height: var(--table-base-height);
  overflow: hidden;
  transform: translate(-50%, -50%) scale(var(--table-scale));
  transform-origin: center;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(255, 255, 255, 0.12), transparent 28rem),
    linear-gradient(135deg, var(--table), var(--table-dark));
  background-size: 2rem 2rem, 2rem 2rem, auto, auto;
  border: 8px solid #463324;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18);
}

.field-layer {
  position: absolute;
  inset: 0;
  transform-origin: center;
  z-index: 5;
  pointer-events: none;
}

body.table-mode.far-seat .field-layer,
body.table-mode.far-seat .board-hand-zone,
body.table-mode.far-seat .pile-stack {
  transform: rotate(180deg);
}

.near-pile-stack {
  right: 1rem;
  bottom: calc(var(--hand-zone-height) + 1rem);
}

.far-pile-stack {
  left: 1rem;
  top: calc(var(--hand-zone-height) + 1rem);
}

.far-pile-stack .graveyard-zone {
  order: 2;
}

.far-pile-stack .extra-deck-zone {
  order: 3;
}

.far-pile-stack .deck-pile {
  order: 1;
}

body.table-mode.far-seat .near-pile-stack {
  right: auto;
  bottom: auto;
  left: 1rem;
  top: calc(var(--hand-zone-height) + 1rem);
}

body.table-mode.far-seat .far-pile-stack {
  right: 1rem;
  bottom: calc(var(--hand-zone-height) + 1rem);
  left: auto;
  top: auto;
}

body.table-mode.far-seat .zone-title {
  transform: rotate(180deg);
}

.board-hand-zone {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.65rem;
  min-height: var(--hand-zone-height);
  padding: 0.55rem 0.7rem;
  background: rgba(16, 43, 38, 0.82);
  border-color: rgba(255, 255, 255, 0.18);
  pointer-events: none;
  transform-origin: center;
}

.pile-stack {
  position: absolute;
  z-index: 4;
  display: grid;
  gap: 0.75rem;
  width: 8rem;
  pointer-events: auto;
  transform-origin: center;
}

.graveyard-zone,
.extra-deck-zone {
  display: grid;
  place-items: center;
  min-height: 7rem;
  width: 8rem;
  justify-self: end;
  border: 2px dashed rgba(255, 255, 255, 0.56);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.82);
  background: rgba(30, 28, 25, 0.48);
  font-weight: 900;
  cursor: pointer;
  pointer-events: auto;
}

.graveyard-zone {
  min-height: 10.4rem;
}

.far-pile-stack .graveyard-zone span,
.far-pile-stack .extra-deck-zone span,
.far-pile-stack .deck-pile span,
.far-pile-stack .deck-pile strong {
  display: block;
  transform: rotate(180deg);
}

.opponent-zone {
  top: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.own-zone {
  bottom: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
}

body.table-mode.far-seat .opponent-zone {
  top: auto;
  bottom: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom: 0;
}

body.table-mode.far-seat .own-zone {
  top: 0;
  bottom: auto;
  border-top: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.zone-title {
  color: rgba(255, 255, 255, 0.82);
  font-weight: 900;
  writing-mode: vertical-rl;
}

.zone-cards {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  overflow-x: auto;
  padding: 0.2rem 0;
}

.zone-hand-card {
  position: relative;
  flex: 0 0 5.2rem;
}

.zone-hand-card .table-card-face,
.zone-hand-card .card-back {
  width: 5.2rem;
  min-height: auto;
}

.zone-hand-card .card-name {
  min-height: 1rem;
  padding: 0.08rem 0.16rem;
  font-size: 0.55rem;
}

.zone-hand-card .card-level,
.zone-hand-card .card-stats {
  font-size: 0.48rem;
  min-height: 0.6rem;
}

.zone-hand-card .card-art {
  margin: 0.16rem 0;
  border-width: 2px;
}

.zone-hand-card .card-text {
  display: none;
}

.zone-hand-card:hover .zone-controls,
.zone-hand-card:focus-within .zone-controls {
  opacity: 1;
}

.zone-controls {
  flex-wrap: wrap;
}

.table-empty {
  position: absolute;
  inset: var(--hand-zone-height) 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
  text-align: center;
  pointer-events: none;
}

.table-empty[hidden] {
  display: none;
}

.table-card {
  position: absolute;
  width: var(--table-card-width);
  aspect-ratio: 59 / 86;
  touch-action: none;
  user-select: none;
  pointer-events: auto;
  outline: 0;
}

.table-card.selected .table-card-inner {
  filter: drop-shadow(0 0 0.7rem rgba(255, 241, 155, 0.95));
}

.card-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(18, 24, 21, 0.42);
}

.card-preview-overlay[hidden] {
  display: none;
}

.card-preview-panel {
  width: min(28rem, calc(100vw - 3rem));
  max-height: calc(100vh - 3rem);
  overflow: auto;
  filter: drop-shadow(0 1.4rem 2.2rem rgba(0, 0, 0, 0.46));
}

.graveyard-panel {
  width: min(46rem, calc(100vw - 3rem));
  max-height: calc(100vh - 3rem);
  overflow: auto;
  padding: 1rem;
  border: 3px solid #1d1713;
  border-radius: 8px;
  background: #f6efdf;
  box-shadow: 0 1.4rem 2.2rem rgba(0, 0, 0, 0.42);
}

.graveyard-panel h2 {
  margin: 0 0 0.85rem;
  font-size: 1.15rem;
}

.graveyard-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.8rem;
}

.graveyard-card {
  display: grid;
  gap: 0.55rem;
  align-content: start;
}

.graveyard-card-actions {
  display: grid;
  gap: 0.45rem;
}

.graveyard-card-actions strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-viewer-panel {
  width: min(54rem, calc(100vw - 3rem));
  max-height: calc(100vh - 3rem);
  overflow: auto;
  padding: 1rem;
  border: 3px solid #1d1713;
  border-radius: 8px;
  background: #f6efdf;
  box-shadow: 0 1.4rem 2.2rem rgba(0, 0, 0, 0.42);
}

.deck-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.85rem;
}

.deck-viewer-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.deck-viewer-title-block {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
}

.deck-viewer-guide {
  color: #6a5540;
  font-size: 0.86rem;
  font-weight: 800;
}

.deck-viewer-header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.deck-viewer-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.8rem;
}

.deck-viewer-card {
  display: grid;
  gap: 0.55rem;
  align-content: start;
}

.deck-viewer-visual {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.deck-viewer-visual .card-back,
.deck-viewer-visual .mini-card {
  width: 100%;
}

.deck-viewer-visual .mini-card,
.deck-viewer-visual .mini-card .card-name,
.deck-viewer-visual .mini-card .card-text,
.deck-viewer-visual .mini-card .card-stats {
  color: #18130f;
}

.deck-viewer-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.deck-viewer-controls strong,
.deck-viewer-controls span {
  grid-column: 1 / -1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-viewer-play-button {
  grid-column: 1 / -1;
}

.pile-card-visual {
  position: relative;
  cursor: zoom-in;
}

.pile-card-count {
  position: absolute;
  top: 0.22rem;
  right: 0.22rem;
  z-index: 2;
  display: block;
  color: #17120e;
  font-size: 1rem;
  font-weight: 900;
  text-shadow:
    0 1px 0 #fff2c7,
    1px 0 0 #fff2c7,
    0 -1px 0 #fff2c7,
    -1px 0 0 #fff2c7;
}

.nested-card-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 3200;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.18);
  padding: 1.5rem;
}

.preview-card-face {
  display: grid;
  grid-template-rows: auto auto minmax(12rem, 3fr) minmax(8rem, 2fr) auto;
  width: 100%;
  aspect-ratio: 59 / 86;
  padding: 0.8rem;
  border-radius: 9px;
  border: 4px solid #14100d;
  background: var(--monster);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.38);
  overflow: hidden;
}

.preview-card-face[data-type="spell"] {
  background: var(--spell);
}

.preview-card-face[data-type="trap"] {
  background: var(--trap);
}

.preview-card-face .card-text {
  font-size: 1.2rem;
  min-height: 0;
  white-space: pre-wrap;
}

.preview-card-face .card-art {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  min-height: 0;
  height: auto;
}

.preview-card-face .card-art img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.deck-pile {
  width: 7.2rem;
  min-height: 10.4rem;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.35rem;
  padding: 0.7rem;
  border: 3px solid #19120f;
  border-radius: 7px;
  color: #f9edd1;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 34%),
    repeating-linear-gradient(135deg, #36241c 0 0.55rem, #251914 0.55rem 1.1rem);
  box-shadow:
    0.28rem 0.28rem 0 rgba(0, 0, 0, 0.26),
    inset 0 0 0 2px rgba(255, 255, 255, 0.18);
  font-weight: 900;
  text-align: center;
  cursor: pointer;
  pointer-events: auto;
}

.deck-pile-title {
  font-size: 1rem;
}

.deck-pile-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  min-width: 0;
  font-size: 0.72rem;
  line-height: 1;
  color: #f7e4bc;
}

.mouse-icon {
  position: relative;
  display: inline-block;
  width: 0.82rem;
  height: 1.08rem;
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-radius: 0.42rem 0.42rem 0.5rem 0.5rem;
}

.mouse-icon::before {
  content: "";
  position: absolute;
  top: 0.08rem;
  bottom: 0.43rem;
  width: 50%;
  background: currentColor;
}

.mouse-icon::after {
  content: "";
  position: absolute;
  top: 0.08rem;
  bottom: 0.43rem;
  left: 50%;
  border-left: 1px solid currentColor;
}

.mouse-icon.left-button::before {
  left: 0;
  border-radius: 0.28rem 0 0 0;
}

.mouse-icon.right-button::before {
  right: 0;
  border-radius: 0 0.28rem 0 0;
}

.deck-pile:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.deck-pile:active {
  transform: none;
}

.table-card-inner {
  transform-origin: center;
  width: 100%;
  height: 100%;
}

.table-card-face {
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  padding: 0.42rem;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.table-card-compact {
  grid-template-rows: auto auto minmax(3rem, 1fr) auto;
}

.table-card-compact .card-text {
  display: none;
}

.table-card-compact .card-art {
  min-height: 0;
}

.table-card[data-type="spell"] .table-card-face,
.mini-card[data-type="spell"] {
  background: var(--spell);
}

.table-card[data-type="trap"] .table-card-face,
.mini-card[data-type="trap"] {
  background: var(--trap);
}

.card-name {
  background: rgba(255, 244, 208, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.35);
  padding: 0.2rem 0.35rem;
  font-weight: 800;
  min-height: 1.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-art {
  display: grid;
  place-items: center;
  margin: 0.38rem 0;
  border: 3px solid rgba(37, 26, 18, 0.75);
  background: linear-gradient(135deg, #d8c293, #584538);
  color: rgba(255, 255, 255, 0.85);
  overflow: hidden;
}

.card-level {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.06rem;
  min-height: 1.15rem;
  color: #c42f24;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-align: right;
  text-shadow:
    0 1px 0 #ffe9a8,
    1px 0 0 #ffe9a8,
    0 -1px 0 #4b1d14,
    -1px 0 0 #4b1d14;
}

.card-level-star,
.card-level-count {
  flex: 0 0 auto;
}

.card-level-count {
  color: #3f1d14;
  text-shadow:
    0 1px 0 #ffe9a8,
    1px 0 0 #ffe9a8,
    0 -1px 0 #ffe9a8,
    -1px 0 0 #ffe9a8;
}

.card-art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.preview-click-target {
  cursor: zoom-in;
}

.preview-click-target:hover {
  outline: 2px solid rgba(255, 235, 150, 0.9);
  outline-offset: 1px;
}

.card-text {
  min-height: 4.6rem;
  background: rgba(255, 246, 226, 0.94);
  border: 1px solid rgba(0, 0, 0, 0.34);
  padding: 0.28rem;
  font-size: 0.68rem;
  line-height: 1.25;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.card-stats {
  margin-top: 0.25rem;
  padding-top: 0.2rem;
  border-top: 1px solid rgba(0, 0, 0, 0.38);
  font-size: 0.72rem;
  text-align: right;
  font-weight: 800;
  color: #1b1612;
}

.card-back {
  display: grid;
  place-items: center;
  aspect-ratio: 59 / 86;
  min-height: 0;
  border-radius: 6px;
  border: 3px solid #14100d;
  color: #f8df9d;
  background:
    radial-gradient(circle, #36251c 0 18%, transparent 19%),
    repeating-conic-gradient(from 0deg, #6b2d20 0 12deg, #1f1917 12deg 24deg);
  box-shadow: inset 0 0 0 6px #2d1f19, inset 0 0 0 10px #a96930;
  font-weight: 900;
}

.table-card .card-back {
  width: 100%;
  height: 100%;
}

.mini-card {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding: 0.28rem;
}

.mini-card .card-name {
  font-size: 0.68rem;
  min-height: 1.25rem;
  padding: 0.1rem 0.2rem;
}

.mini-card .card-art {
  margin: 0.24rem 0;
  border-width: 2px;
}

.mini-card .card-level {
  min-height: 0.8rem;
  font-size: 0.52rem;
  line-height: 1;
}

.mini-card .card-text {
  display: none;
}

.mini-card .card-stats {
  font-size: 0.6rem;
}

@media (max-width: 1040px) {
  #cardsView.active {
    height: auto;
    overflow: visible;
  }

  #decksView.active {
    height: auto;
    overflow: visible;
  }

  #adminView.active {
    height: auto;
    overflow: visible;
  }

  .card-register-layout {
    height: auto;
  }

  .deck-build-layout {
    height: auto;
  }

  .admin-layout {
    height: auto;
  }

  .admin-seat-stack {
    height: auto;
    grid-template-rows: auto auto;
  }

  .deck-build-layout > .panel {
    overflow: auto;
  }

  .admin-layout > .panel,
  .admin-seat-stack > .panel {
    height: auto;
  }

  .card-register-layout .pool-panel {
    overflow: auto;
  }

  .pool-panel .card-pool {
    overflow: visible;
  }

  .two-column,
  .two-column.wide-left,
  .admin-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .card-basic-row {
    grid-template-columns: 1fr;
  }

  #tableView.active {
    height: auto;
    min-height: 0;
  }

  .table-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(32rem, 70vh);
    grid-template-areas:
      "controls"
      "board";
    height: auto;
  }
}

@media (max-width: 760px) {
  .app-header {
    display: grid;
  }

  .pool-card {
    grid-template-columns: 5.2rem 1fr;
  }

  .table-card {
    width: var(--table-card-width);
  }
}
