/* Base component geometry. Shared ink theme is defined in system.css. */
* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app {
  width: min(1420px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar,
.player-zone,
.hand-panel,
.test-panel,
.actions-panel,
.log-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--card-shadow);
}

.topbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  overflow-x: auto;
}

.game-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 0 170px;
  min-width: 0;
}

.game-heading h1 {
  flex: none;
  font-size: 16px;
  white-space: nowrap;
}

.game-heading #statusLine {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.game-heading .room-share-line {
  flex: none;
  margin-top: 0;
  white-space: nowrap;
}

.game-heading:has(.room-share-line:not([hidden])) {
  flex-basis: max-content;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 600;
}

h2 {
  font-size: 17px;
  font-weight: 600;
}

h3 {
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 500;
}

#statusLine,
.zone-head span,
.panel-head span,
.label,
.empty,
.character-title,
.character-meta,
.character-state,
.hand-card span,
.log-list span {
  color: var(--text-soft);
}

.room-share-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--text-soft);
  font-size: 13px;
  user-select: text;
}

.room-share-line .action-button {
  width: auto;
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.new-game {
  display: flex;
  flex: none;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}

.new-game label {
  display: flex;
  align-items: center;
  flex: none;
  gap: 4px;
  color: var(--text-soft);
  font-size: 12px;
  white-space: nowrap;
}

.new-game input,
.new-game select,
.test-tools-body select,
.deck-list-panel input,
.deck-list-panel select,
.catalog-filters select {
  width: 112px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface-2);
  color: inherit;
}

.new-game select {
  width: 120px;
}

.new-game input,
.new-game select,
.new-game button {
  height: 30px;
  min-height: 30px;
  font-size: 12px;
  line-height: 18px;
  padding: 4px 8px;
}

.new-game #seedInput {
  width: 64px;
}

.new-game #modeSelect {
  width: 132px;
}

.new-game #roomAddressInput {
  width: 160px;
}

.new-game #hostOrderSelect {
  width: 64px;
}

.new-game button,
.action-button {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  background: var(--primary);
  color: white;
  font-weight: 600;
}

.new-game button {
  width: auto;
  min-width: 48px;
  padding: 4px 10px;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: center;
  border-radius: 5px;
}

.new-game button:hover,
.action-button:hover {
  background: var(--primary-strong);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}

.field-column,
.side-column {
  display: grid;
  min-width: 0;
  gap: 14px;
}

.side-column {
  position: sticky;
  top: 16px;
  height: calc(100vh - 32px);
  max-height: calc(100vh - 32px);
  min-height: 0;
  grid-template-rows: auto minmax(160px, 0.95fr) minmax(180px, 1.05fr);
}

.player-zone {
  padding: 16px;
}

.test-panel,
.actions-panel,
.log-panel,
.hand-panel {
  padding: 14px;
}

.test-controls,
.test-tools-body {
  display: grid;
  gap: 10px;
}

.rest-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
  font-size: 13px;
}

.toggle-row input {
  width: 16px;
  height: 16px;
}

.test-tools-body label {
  display: grid;
  gap: 5px;
  color: var(--text-soft);
  font-size: 13px;
}

.test-tools-body select {
  width: 100%;
}

.actions-panel .panel-head h2 {
  flex: none;
}

.self-rest-draw-setting {
  flex-shrink: 0;
}

.action-settings {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.surrender-button {
  color: var(--danger);
  padding: 4px 12px;
  min-height: 28px;
}

.actions-panel #actionHint {
  min-width: 0;
  overflow-wrap: anywhere;
}

.zone-head,
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: baseline;
  margin-bottom: 12px;
}

.areas {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 2.2fr;
  gap: 16px;
  align-items: start;
}

.self-areas {
  grid-template-columns: 2.2fr 1fr 1fr;
}

.opponent-areas {
  grid-template-columns: minmax(270px, 1.3fr) minmax(70px, 0.45fr) minmax(132px, 0.8fr);
}

.opponent-areas > .battlefield-zone {
  grid-column: 1 / -1;
}

.field-column {
  container-type: inline-size;
}

.areas > div {
  min-width: 0;
}

@container (max-width: 540px) {
  .opponent-areas {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .opponent-areas > div:first-child {
    grid-column: 1 / -1;
  }
}

.battlefield,
.hand,
.actions,
.pile {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.battlefield {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(138px, 100%), 1fr));
  align-content: start;
  max-height: min(360px, 50vh);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 4px;
}

.battlefield .character-card {
  width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

.character-card,
.hand-card,
.mini-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  transition: border-color 120ms ease, box-shadow 120ms ease, opacity 120ms ease, transform 120ms ease;
}

.equipment-card {
  min-width: 132px;
}

.character-card {
  overflow: hidden;
  display: grid;
  gap: 7px;
  width: 138px;
  min-height: 134px;
  padding: 32px 10px 10px;
}

.character-card strong {
  font-size: 18px;
  font-weight: 600;
}

.character-card.tapped {
  opacity: 0.62;
  transform: rotate(-1deg);
}

.character-card.lebu-locked {
  opacity: 0.48;
  filter: none;
}

.character-card.cannot-act::before {
  content: "×";
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  color: var(--danger);
  font-size: 76px;
  line-height: 1;
  font-weight: 800;
  pointer-events: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75), 0 0 10px rgba(36, 36, 34, 0.2);
}

.character-card.face-down::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(92, 92, 90, 0.32);
  pointer-events: none;
}

.character-card.face-down .character-state {
  color: var(--text-soft);
  font-weight: 700;
}

.character-card.unknown strong,
.character-card.unknown .character-title,
.character-card.unknown .character-meta {
  color: var(--text-soft);
}

.character-card.lebu-locked .character-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-height: 28px;
  border: 1px solid var(--danger);
  border-radius: 50%;
  color: var(--danger);
  font-weight: 600;
}

.character-state {
  align-self: end;
  font-size: 12px;
}

.character-meta {
  font-size: 12px;
  font-weight: 600;
}

.character-tooltip {
  position: fixed;
  z-index: 1000;
  display: none;
  width: min(360px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  pointer-events: none;
}

.character-tooltip.visible {
  display: grid;
  gap: 6px;
}

.character-tooltip strong {
  font-size: 14px;
  font-weight: 700;
}

.character-tooltip p {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.mini-card {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 9px;
  color: var(--danger);
  font-weight: 600;
}

.center-line {
  padding: 0;
}

.info-strip {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 10px;
}

.info-strip > div {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--surface);
}

.label {
  font-size: 12px;
}

.hand-panel,
.test-panel,
.actions-panel,
.log-panel {
  padding: 16px;
}

.hand-panel {
  overflow: hidden;
}

.actions-panel,
.log-panel {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.actions-panel {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.hand-card {
  display: grid;
  gap: 10px;
  width: 112px;
  min-height: 86px;
  padding: 10px;
}

.compact-hand .hand-card,
.compact-card {
  width: 82px;
  min-height: 70px;
  gap: 6px;
}

.hand-panel > .hand {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
}

.hand-panel > .hand .hand-card {
  flex: 0 0 112px;
}

.compact-hand {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 82px));
  grid-auto-rows: 104px;
  align-content: start;
  max-height: 216px;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
}

.compact-hand .hand-card {
  flex: 0 0 82px;
  width: 100%;
  min-width: 0;
  height: 104px;
  min-height: 104px;
  padding: 26px 6px 6px;
  gap: 2px;
  grid-template-rows: 16px 34px 16px;
}

.card-back {
  color: var(--text-soft);
}

.compact-hand .hand-card strong {
  font-size: 14px;
  line-height: 17px;
  overflow-wrap: anywhere;
}

.compact-hand .hand-card > span {
  font-size: 12px;
  line-height: 16px;
}

.is-disabled {
  opacity: 0.42;
}

.is-clickable {
  cursor: pointer;
}

.is-clickable:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 36, 34, 0.14);
}

.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 36, 34, 0.26);
}

.is-selected[data-choice-hint]::before,
.is-targetable[data-choice-hint]::before {
  content: attr(data-choice-hint);
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 4;
  max-width: calc(100% - 12px);
  border-radius: 6px;
  padding: 3px 6px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  pointer-events: none;
}

.is-breakthrough-target {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 36, 34, 0.22);
}

.character-card.is-selected[data-choice-hint]::before,
.character-card.is-targetable[data-choice-hint]::before {
  bottom: auto;
  left: auto;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-card[data-choice-hint] {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: 132px;
  min-width: 0;
  max-width: 100%;
  min-height: 84px;
  overflow-wrap: anywhere;
}

.mini-card.is-selected[data-choice-hint]::before,
.mini-card.is-targetable[data-choice-hint]::before {
  position: static;
  box-sizing: border-box;
  flex: 0 0 34px;
  width: 100%;
  max-width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
}

.mini-card.is-selected[data-choice-hint]::before {
  content: "已选";
}

.is-breakthrough-target[data-choice-hint]::before {
  background: var(--primary);
}

.is-rest-cost[data-choice-hint]::before {
  background: var(--primary);
}

.is-targetable {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 36, 34, 0.18);
  transform: translateY(-1px);
}

.hand-card.card-red,
.mini-card.card-red {
  color: var(--card-red);
}

.hand-card.card-black,
.mini-card.card-black {
  color: var(--card-black);
}

.hand-card strong {
  font-size: 17px;
}

.card-meta {
  align-self: end;
  font-size: 13px;
  font-weight: 700;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: max-content;
  align-items: stretch;
  align-content: start;
  min-height: 0;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 4px;
}

.subset-selection-controls {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.subset-selection-controls button {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.arrangement-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  width: 100%;
}

.arrangement-modes label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.arrangement-zone {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.arrangement-card {
  text-align: left;
  font-size: 13px;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.pending-choice-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.pending-choice-panel > strong {
  font-size: 13px;
  font-weight: 700;
}

.pending-card-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pending-card {
  display: grid;
  gap: 4px;
  min-width: 92px;
  min-height: 108px;
  padding-top: 32px;
  align-items: start;
  color: var(--text);
}

.pending-card strong {
  font-size: 15px;
  font-weight: 700;
}

.pending-character-card {
  width: 148px;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.action-button {
  width: 100%;
  min-height: 42px;
  text-align: left;
}

.action-button.secondary {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: inherit;
}

.action-button.secondary:hover {
  background: var(--line);
}

.empty {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  font-size: 14px;
}

.log-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  overflow-y: auto;
  list-style: none;
  user-select: text;
}

.log-list li {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.log-list span {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
}

.log-list p {
  line-height: 1.45;
}

.log-list time {
  display: block;
  margin-top: 3px;
  color: var(--text-soft);
  font-size: 11px;
  line-height: 1.3;
}

#copyGameLog {
  flex: 0 0 auto;
  width: 88px;
  height: 30px;
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
  text-align: center;
}

.log-panel .panel-head {
  flex-direction: row;
  align-items: center;
}

.copy-log-status {
  color: var(--text-soft);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  z-index: 900;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(22, 22, 20, 0.38);
}

.modal-panel {
  width: min(760px, 100%);
  max-height: min(720px, calc(100vh - 40px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.modal-panel .panel-head button {
  width: auto;
}

.rest-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  max-height: calc(100vh - 150px);
  overflow: auto;
}

.deck-modal-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, calc(100vw - 32px));
  max-height: min(860px, calc(100vh - 32px));
}

.deck-builder {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}

.deck-list-panel,
.catalog-panel {
  min-height: 0;
  min-width: 0;
}

.deck-list-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
}

.deck-list-panel label,
.catalog-filters label {
  display: grid;
  gap: 5px;
  color: var(--text-soft);
  font-size: 13px;
}

.deck-list-panel input,
.deck-list-panel textarea,
.deck-list-panel select,
.catalog-filters select {
  width: 100%;
}

.deck-list-panel textarea {
  min-height: 84px;
  resize: vertical;
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.35;
}

.deck-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.deck-summary {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 13px;
}

.catalog-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.catalog-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  align-items: end;
  gap: 10px;
}

#catalogViewToggle {
  width: 104px;
  height: 36px;
  min-height: 36px;
  padding: 0 10px;
}

@media (max-width: 600px) {
  .catalog-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #catalogViewToggle { grid-column: 1 / -1; }
}

.character-catalog {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
  align-content: start;
  gap: 8px;
  max-height: 640px;
  overflow: auto;
  padding-right: 4px;
}

.deck-catalog-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 42px minmax(34px, auto) 28px;
  gap: 4px 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.deck-catalog-heading {
  display: grid;
  grid-template-rows: repeat(2, 21px);
  min-width: 0;
  line-height: 21px;
  font-weight: 600;
}

.deck-catalog-title,
.deck-catalog-name {
  display: block;
  white-space: nowrap;
  letter-spacing: 0;
}

.deck-catalog-title {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 400;
}

.deck-catalog-name {
  font-size: 15px;
}

.deck-catalog-meta {
  color: var(--text-soft);
  font-size: 12px;
  line-height: 17px;
}

.deck-count-controls {
  justify-self: end;
  display: grid;
  grid-template-columns: 28px 30px 28px;
  align-items: center;
  gap: 4px;
}

.deck-count-controls button {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: inherit;
  font-weight: 700;
}

.deck-count-controls span {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: inherit;
}

.rest-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--surface-2);
}

.rest-card span,
.rest-card p {
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 980px) {
  .app {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-column {
    position: static;
    height: auto;
    max-height: none;
    grid-template-rows: none;
  }

  .actions,
  .log-list {
    max-height: 52vh;
  }

  .zone-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .areas,
  .self-areas,
  .opponent-areas,
  .info-strip {
    grid-template-columns: 1fr;
  }

  .character-card,
  .hand-card {
    width: calc(50% - 4px);
  }

  .action-button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .battlefield {
    grid-template-columns: repeat(auto-fill, minmax(min(112px, 100%), 1fr));
  }

  .character-card,
  .hand-card {
    width: 100%;
  }
}

@media (max-width: 680px) {
  .deck-builder {
    display: block;
    overflow: auto;
  }

  .deck-list-panel {
    overflow: visible;
  }

  .deck-builder .catalog-panel {
    margin-top: 14px;
  }

  .deck-modal-panel .panel-head {
    flex-direction: row;
    align-items: center;
  }
}
