.play-body {
  min-height: 100vh;
  background: #f5f0e5;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 14px clamp(14px, 3vw, 32px);
  color: var(--ivory);
  background: #101b19;
  border-bottom: 1px solid rgba(255, 250, 240, 0.12);
}

.app-brand {
  color: var(--ivory);
}

.app-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.app-tabs a,
.profile-button,
.segmented-control button,
.game-actions button,
.chat-form button {
  border: 1px solid rgba(255, 250, 240, 0.16);
  background: rgba(255, 250, 240, 0.08);
  color: var(--ivory);
  cursor: pointer;
}

.app-tabs a {
  padding: 10px 14px;
  font-weight: 800;
}

.app-tabs a.active,
.app-tabs a:hover {
  border-color: rgba(197, 145, 60, 0.58);
  color: #f5d28b;
}

.profile-button {
  display: grid;
  min-width: 150px;
  gap: 2px;
  padding: 8px 12px;
  text-align: left;
}

.profile-button span {
  color: rgba(255, 250, 240, 0.72);
  font-size: 0.78rem;
}

.profile-button strong {
  color: #f5d28b;
  font-size: 1rem;
}

.game-app {
  padding: 18px clamp(14px, 3vw, 32px) 54px;
}

.devotional-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  padding: 14px 18px;
  color: var(--ivory);
  background: var(--green-deep);
  border-left: 5px solid var(--gold);
}

.devotional-strip span {
  color: #f5d28b;
  font-weight: 900;
  white-space: nowrap;
}

.devotional-strip p {
  margin: 0;
  color: rgba(255, 250, 240, 0.86);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(420px, 1fr) minmax(280px, 360px);
  gap: 18px;
  align-items: start;
}

.game-layout > * {
  min-width: 0;
}

.left-rail,
.right-rail {
  display: grid;
  gap: 18px;
}

.control-panel,
.ranking-panel,
.status-panel,
.moves-panel,
.chat-panel,
.build-map article {
  background: #fffdf6;
  border: 1px solid var(--line);
  box-shadow: 0 14px 38px rgba(15, 53, 47, 0.08);
}

.control-panel,
.ranking-panel,
.status-panel,
.moves-panel,
.chat-panel {
  padding: 18px;
}

.panel-heading h1,
.panel-heading h2,
.status-panel h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0;
}

.panel-heading h1 {
  font-size: 2rem;
  line-height: 1;
}

.panel-heading.compact h2,
.status-panel h2 {
  font-size: 1.35rem;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 18px 0;
}

.segmented-control button {
  min-height: 44px;
  padding: 8px;
  color: var(--green-deep);
  background: #eee2cf;
  border-color: rgba(24, 32, 31, 0.12);
  font-weight: 850;
}

.segmented-control button.active {
  color: #24170c;
  background: var(--gold);
}

.field-label {
  display: block;
  margin: 16px 0 8px;
  color: var(--green-deep);
  font-weight: 850;
}

select,
.control-panel input[type="range"],
.profile-modal input {
  width: 100%;
}

select,
.profile-modal input,
.profile-modal textarea,
.chat-form input {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(24, 32, 31, 0.18);
  background: #fffaf0;
  color: var(--ink);
}

.profile-modal textarea {
  width: 100%;
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
}

.difficulty-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.difficulty-row strong {
  color: var(--green);
}

.match-card {
  margin: 18px 0;
  padding: 14px;
  background: #eef1e8;
  border: 1px solid rgba(28, 84, 70, 0.14);
}

.match-card span,
.build-map article span {
  color: var(--clay);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.match-card strong {
  display: block;
  margin-top: 6px;
}

.match-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.join-card {
  display: none;
  margin-bottom: 14px;
}

.join-card.open {
  display: block;
}

.join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.join-row input {
  min-width: 0;
}

.join-row button {
  border: 0;
  border-radius: 6px;
  background: var(--green-deep);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  padding: 0 14px;
}

.full-width {
  width: 100%;
}

.dark-outline {
  margin-top: 10px;
  border-color: rgba(28, 84, 70, 0.28);
  color: var(--green-deep);
  background: transparent;
}

.rating-grid {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.leaderboard-list,
.history-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.leaderboard-item,
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.leaderboard-item span,
.history-item span {
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-review {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--green-deep);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  padding: 4px 8px;
}

.history-review:hover {
  border-color: var(--gold);
}

.leaderboard-item strong,
.history-item strong {
  color: var(--green-deep);
}

.rating-item,
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.rating-item span,
.stat-row span {
  color: var(--muted);
}

.board-area {
  display: grid;
  gap: 10px;
}

.player-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  color: var(--ivory);
  background: #173d36;
  border: 1px solid rgba(255, 250, 240, 0.1);
}

.player-card.opponent {
  background: #281f19;
}

.player-card span {
  display: block;
  font-weight: 900;
}

.player-card strong {
  display: block;
  color: rgba(255, 250, 240, 0.72);
  font-size: 0.82rem;
}

.player-card time {
  min-width: 96px;
  color: #f5d28b;
  font-size: 1.8rem;
  font-weight: 950;
  text-align: right;
}

.play-board-shell {
  position: relative;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  padding: 14px;
  background: #fffdf6;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.play-board {
  display: grid;
  width: min(74vh, 100%);
  max-width: 720px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 8px solid var(--walnut);
  background: var(--walnut);
  touch-action: none;
}

.board-notice {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  display: none;
  min-width: min(280px, 85%);
  padding: 14px 18px;
  border: 2px solid rgba(245, 210, 139, 0.88);
  background: rgba(16, 27, 25, 0.9);
  color: #fffaf0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 2.8vw, 1.75rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  text-align: center;
  pointer-events: none;
}

.board-notice.show {
  display: block;
}

.play-square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 6vw, 4.25rem);
  line-height: 1;
  cursor: pointer;
  touch-action: none;
}

.play-square.drag-origin {
  outline: 4px solid #f5d28b;
  outline-offset: -4px;
}

.play-square.drag-target {
  box-shadow: inset 0 0 0 4px rgba(28, 84, 70, 0.75);
}

.play-square.light {
  background: #e8cf9f;
}

.play-square.dark {
  background: #815432;
}

.play-square.white-piece {
  color: #fffaf0;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.42);
}

.play-square.black-piece {
  color: #151515;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

.play-square.selected {
  outline: 4px solid #f5d28b;
  outline-offset: -4px;
}

.play-square.legal::after {
  content: "";
  position: absolute;
  width: 24%;
  height: 24%;
  border-radius: 999px;
  background: rgba(28, 84, 70, 0.45);
}

.play-square.capture::after {
  width: 76%;
  height: 76%;
  border: 4px solid rgba(197, 145, 60, 0.72);
  background: transparent;
}

.coordinate-ranks,
.coordinate-files {
  color: var(--green-deep);
  font-size: 0.84rem;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 250, 240, 0.3);
}

.coordinate-ranks {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  align-items: center;
}

.coordinate-files {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  max-width: 720px;
  width: min(74vh, 100%);
  margin: 0 auto;
  text-align: center;
}

.game-actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.game-actions button {
  min-height: 42px;
  color: var(--green-deep);
  background: #fffdf6;
  border-color: var(--line);
  font-weight: 850;
}

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

.moves-panel {
  max-height: 300px;
  overflow: auto;
}

.move-list {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  padding-left: 22px;
  color: var(--muted);
}

.move-list li::marker {
  color: var(--clay);
  font-weight: 900;
}

.chat-log {
  display: grid;
  min-height: 190px;
  max-height: 240px;
  gap: 10px;
  overflow: auto;
  padding: 12px;
  background: #eef1e8;
  border: 1px solid rgba(24, 32, 31, 0.1);
}

.room-message {
  padding: 10px;
  background: #fffdf6;
  border: 1px solid rgba(24, 32, 31, 0.1);
}

.room-message strong {
  display: block;
  color: var(--green);
  font-size: 0.82rem;
}

.room-message p {
  margin: 3px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.chat-form button {
  padding: 0 14px;
  color: #24170c;
  background: var(--gold);
  border-color: transparent;
  font-weight: 900;
}

.build-map {
  padding: 62px 0 0;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.build-map article {
  padding: 24px;
}

.build-map article h3 {
  margin: 10px 0 8px;
}

.build-map article p {
  margin: 0;
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(16, 27, 25, 0.72);
}

.modal-backdrop.open {
  display: flex;
}

.profile-modal {
  width: min(420px, 100%);
  max-height: min(90vh, 680px);
  overflow: auto;
  padding: 22px;
  background: #fffdf6;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.profile-modal h2 {
  margin: 0 0 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.7rem;
  line-height: 1;
}

.profile-modal p {
  color: var(--muted);
}

.profile-modal label {
  display: block;
  margin: 14px 0 8px;
  color: var(--green-deep);
  font-weight: 850;
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 18px 0 4px;
}

.auth-switch button {
  min-height: 42px;
  border: 1px solid rgba(24, 32, 31, 0.14);
  background: #eee2cf;
  color: var(--green-deep);
  font-weight: 850;
  cursor: pointer;
}

.auth-switch button.active {
  background: var(--gold);
  color: #24170c;
}

.auth-note {
  min-height: 22px;
  margin-bottom: 0;
  color: var(--clay);
  font-weight: 800;
}

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

@media (max-width: 1180px) {
  .game-layout {
    grid-template-columns: minmax(250px, 320px) minmax(420px, 1fr);
  }

  .right-rail {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 860px) {
  .app-header {
    position: static;
  }

  .app-header {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .app-header,
  .game-layout,
  .right-rail,
  .map-grid {
    grid-template-columns: 1fr;
  }

  .app-tabs {
    justify-content: flex-start;
    overflow-x: auto;
    white-space: nowrap;
  }

  .profile-button {
    width: 100%;
    min-width: 0;
  }

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

  .play-board,
  .coordinate-files {
    width: 100%;
  }
}

@media (max-width: 540px) {
  .game-app {
    padding-inline: 10px;
    padding-block: 10px 38px;
  }

  .segmented-control,
  .game-actions,
  .chat-form {
    grid-template-columns: 1fr;
  }

  .player-card time {
    min-width: 80px;
    font-size: 1.35rem;
  }

  .play-board-shell {
    padding: 8px;
    grid-template-columns: 16px minmax(0, 1fr);
  }

  .play-board {
    border-width: 5px;
  }

  .coordinate-ranks,
  .coordinate-files {
    font-size: 0.74rem;
  }
}
