/*--------------------------------------------------------------
# Tigers vs Goats in the browser (/bagchal/play/)
# Colors and shapes come from the Windows game's Styles/GameTheme.xaml,
# and the board from its Classes/DrawGraphics.cs. Board coordinates are
# the game's own 900 x 900 canvas: points every 150 units from 150 to 750.
--------------------------------------------------------------*/
:root {
  --bc-night: #14211d;
  --bc-toolbar: #1e2e28;
  --bc-teal: #2f8f7e;
  --bc-wood: #8b5a2b;
  --bc-wood-light: #9c6833;
  --bc-wood-dark: #4a2e14;
  --bc-parchment: #f3e3c3;
  --bc-parchment-dark: #e4ce9e;
  --bc-gold: #d9a441;
  --bc-gold-light: #e8b65a;
  /* Gold that stays readable on parchment, for the winner's name. */
  --bc-gold-text: #8f6114;
  --bc-ink-soft: #6b5a44;
  --bc-danger: #a6442c;
  --bc-danger-light: #b8533a;
  --focus: var(--bc-parchment);
  --font-body: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --font-title: "Kavoon", "Segoe UI", system-ui, sans-serif;
  --side-width: 320px;
  --chat-width: 280px;
  --gap: 28px;
  --card-chrome: 28px; /* board card padding and border, both sides */
  --track-dir: to right;
}

[dir="rtl"] {
  --track-dir: to left;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bc-night);
  color: var(--bc-parchment);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
}

img {
  -webkit-user-drag: none;
  user-select: none;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.play-shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px 24px 12px;
}

/*--------------------------------------------------------------
# Header: title and toolbar
--------------------------------------------------------------*/
.play-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 24px;
  margin-bottom: 16px;
}

.play-title {
  flex: 1 1 420px;
  text-align: center;
}

.play-title h1 {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: clamp(34px, 4.4vw, 64px);
  line-height: 1.1;
  color: var(--bc-gold);
  letter-spacing: 0.01em;
}

.play-title p {
  margin: 2px 0 0;
  font-size: clamp(14px, 1.4vw, 20px);
  font-style: italic;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bc-toolbar);
  border: 1.5px solid var(--bc-wood);
  border-radius: 14px;
}

.sound-panel {
  display: grid;
  gap: 2px;
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.19);
  border-radius: 8px;
}

.sound-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sound-row label {
  min-width: 38px;
  font-size: 12px;
}

.sound-row input[type="range"] {
  width: 90px;
  margin: 0;
  accent-color: var(--bc-gold);
}

.icon-btn {
  width: 30px;
  padding: 4px 0;
  background: transparent;
  color: var(--bc-parchment);
  border: 0;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(243, 227, 195, 0.12);
}

.language-select {
  width: 150px;
  padding: 6px 8px;
  background: var(--bc-parchment);
  color: var(--bc-wood-dark);
  border: 0;
  border-radius: 9px;
  font: 600 14px/1.2 var(--font-body);
  cursor: pointer;
}

.tool-btn {
  display: inline-block;
  padding: 7px 12px;
  background: var(--bc-wood);
  color: var(--bc-parchment);
  border: 0;
  border-radius: 9px;
  font: 600 14px/1.2 var(--font-body);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.tool-btn:hover {
  background: var(--bc-wood-light);
  color: var(--bc-parchment);
}

.tool-btn-danger {
  background: var(--bc-danger);
}

.tool-btn-danger:hover {
  background: var(--bc-danger-light);
}

/*--------------------------------------------------------------
# Main area: side panel and board
--------------------------------------------------------------*/
/* The board fills what's left of the window next to the side panel (and the chat, online) and below
   the header. */
.play-main {
  --chat-space: 0px;
  --board: clamp(320px, min(900px, 100vw - 48px - var(--side-width) - var(--gap) - var(--card-chrome) - var(--chat-space), 100vh - 230px), 900px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
}

@supports (height: 100dvh) {
  .play-main {
    --board: clamp(320px, min(900px, 100vw - 48px - var(--side-width) - var(--gap) - var(--card-chrome) - var(--chat-space), 100dvh - 230px), 900px);
  }
}

.play-main.has-chat {
  --chat-space: calc(var(--chat-width) + var(--gap));
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 0 0 var(--side-width);
  width: var(--side-width);
}

.card {
  background: var(--bc-parchment);
  color: var(--bc-wood-dark);
  border: 2px solid var(--bc-wood-dark);
  border-radius: 16px;
  padding: 20px;
  --focus: var(--bc-teal);
}

.card-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}

.now-playing {
  padding: 16px;
  text-align: center;
}

.side-label {
  margin: 4px 0 6px;
  min-height: 1.4em;
  font-style: italic;
  font-weight: 600;
}

.portrait {
  width: 170px;
  height: 170px;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bc-parchment-dark);
  box-shadow: 0 0 0 1px rgba(74, 46, 20, 0.15);
}

.portrait img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hint {
  margin: 8px 0 0;
  min-height: 2.8em;
}

.scoreboard .card-title {
  margin-bottom: 10px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 10px;
  background: var(--bc-parchment-dark);
  border: 1.5px solid var(--bc-gold);
  border-radius: 10px;
  text-align: center;
}

.stat-number {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--bc-ink-soft);
}

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn {
  padding: 10px 20px;
  border: 0;
  border-radius: 12px;
  font: 700 20px/1.2 var(--font-body);
  cursor: pointer;
}

.btn-primary {
  background: var(--bc-gold);
  color: var(--bc-wood-dark);
}

.btn-primary:hover {
  background: var(--bc-gold-light);
}

.btn-secondary {
  background: var(--bc-wood);
  color: var(--bc-parchment);
}

.btn-secondary:hover {
  background: var(--bc-wood-light);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-small {
  padding: 5px 10px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

/*--------------------------------------------------------------
# Online: room code, opponent and chat
--------------------------------------------------------------*/
.room-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
  max-width: 760px;
  margin: 0 auto 16px;
  padding: 10px 16px;
}

.room-banner-label {
  font-size: 16px;
  font-weight: 700;
}

.room-code {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--bc-gold-text);
}

.room-banner-hint {
  font-style: italic;
}

.vs-label {
  margin: -4px 0 6px;
  font-size: 12px;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 var(--chat-width);
  width: var(--chat-width);
  height: calc(var(--board) + var(--card-chrome));
  padding: 12px;
}

.chat-log {
  flex: 1;
  min-height: 120px;
  margin: 0;
  padding: 0 4px;
  overflow-y: auto;
  list-style: none;
  overflow-wrap: anywhere;
}

.chat-log li {
  margin: 2px 0 6px;
}

.chat-sender {
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.chat-emoji {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.emoji-btn {
  padding: 4px 8px;
  border-radius: 9px;
  font-size: 16px;
}

.chat-form {
  display: flex;
  gap: 6px;
}

.chat-form input,
.field input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  background: #fffaf0;
  color: var(--bc-wood-dark);
  border: 1.5px solid var(--bc-wood);
  border-radius: 8px;
  font: 15px/1.3 var(--font-body);
}

.chat-form input:focus-visible,
.field input:focus-visible {
  outline-offset: 0;
}

/*--------------------------------------------------------------
# Board
--------------------------------------------------------------*/
.board-card {
  flex: 0 0 auto;
  padding: 12px;
  background: var(--bc-parchment);
  border: 2px solid var(--bc-wood-dark);
  border-radius: 16px;
}

.board {
  position: relative;
  width: var(--board);
  aspect-ratio: 1;
  background: #3a2c1c url("../img/play/board.webp") center / cover no-repeat;
}

.board-drawing,
.board-marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.board-drawing line {
  stroke: #d2b48c; /* Tan */
  stroke-width: 5;
}

.board-drawing rect {
  fill: #8b4513; /* SaddleBrown */
  stroke: #f4a460; /* SandyBrown */
  stroke-width: 1;
}

.pieces {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Pieces are 50 units wide; play.js sets left and top. Goats in hand wait on the top left corner,
   and captured goats end up on the bottom right one, as in the Windows game. */
.piece {
  position: absolute;
  width: calc(100% * 50 / 900);
  height: calc(100% * 50 / 900);
  transition: left 0.5s ease-in-out, top 0.5s ease-in-out;
}

.pieces.no-anim .piece {
  transition: none;
}

#hint-marks circle {
  fill: rgba(76, 175, 80, 0.59);
}

#selection-ring {
  fill: rgba(217, 164, 65, 0.27);
  stroke: var(--bc-gold);
  stroke-width: 4;
}

.points {
  position: absolute;
  inset: 0;
}

.point {
  position: absolute;
  width: calc(100% / 6);
  height: calc(100% / 6);
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.point:focus-visible {
  outline: none;
}

.point:focus-visible::after {
  content: "";
  position: absolute;
  inset: 26%;
  border: 3px dashed var(--bc-parchment);
  border-radius: 10px;
}

.noscript {
  margin: 12px 0 0;
  color: var(--bc-wood-dark);
  font-weight: 600;
  text-align: center;
}

/*--------------------------------------------------------------
# Footer
--------------------------------------------------------------*/
.play-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 18px;
  margin-top: 20px;
  font-size: 13px;
  color: rgba(243, 227, 195, 0.75);
}

.play-footer a {
  color: rgba(243, 227, 195, 0.9);
}

.play-footer a:hover {
  color: var(--bc-gold);
}

/*--------------------------------------------------------------
# Dialogs
--------------------------------------------------------------*/
.game-dialog {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 24px;
  background: var(--bc-parchment);
  color: var(--bc-wood-dark);
  border: 3px solid var(--bc-wood-dark);
  border-radius: 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --focus: var(--bc-teal);
}

.game-dialog::backdrop {
  background: rgba(8, 14, 12, 0.6);
}

.game-dialog form {
  margin: 0;
}

.dialog-title {
  margin: 0 0 12px;
  font-size: 26px;
  font-weight: 700;
}

.dialog-section {
  margin: 0 0 18px;
  padding: 0;
  border: 0;
  min-width: 0;
}

.dialog-section legend,
.section-label {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  font-size: 22px;
  font-weight: 700;
}

.mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
}

.radio {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.radio input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--bc-wood);
}

.side-options {
  display: flex;
  gap: 16px;
}

.side-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 150px;
  height: 150px;
  background: var(--bc-parchment);
  border: 2px solid var(--bc-wood-dark);
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
}

.side-tile:hover {
  background: #f7ebd2;
}

.side-tile input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.side-tile:has(input:checked) {
  border-color: var(--bc-gold);
  box-shadow: inset 0 0 0 2px var(--bc-gold);
}

.side-tile:has(input:focus-visible) {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.difficulty-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
}

.difficulty-row > span {
  padding-top: 2px;
}

.difficulty-track {
  flex: 1;
}

/* The track shows the chosen level in gold, the rest of the unlocked levels in wood, and the
   locked ones faded. play.js sets --fill and --unlocked. */
#difficulty {
  --fill: 0%;
  --unlocked: 0%;
  display: block;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

#difficulty::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(var(--track-dir), var(--bc-gold) var(--fill), var(--bc-wood) var(--fill) var(--unlocked), rgba(139, 90, 43, 0.25) var(--unlocked));
}

#difficulty::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(var(--track-dir), var(--bc-gold) var(--fill), var(--bc-wood) var(--fill) var(--unlocked), rgba(139, 90, 43, 0.25) var(--unlocked));
}

#difficulty::-webkit-slider-thumb {
  width: 20px;
  height: 20px;
  margin-top: -7px;
  background: var(--bc-gold);
  border: 2px solid var(--bc-wood-dark);
  border-radius: 50%;
  -webkit-appearance: none;
  appearance: none;
}

#difficulty::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--bc-gold);
  border: 2px solid var(--bc-wood-dark);
  border-radius: 50%;
}

.difficulty-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--bc-ink-soft);
}

.difficulty-ticks span {
  width: 12px;
  text-align: center;
}

.difficulty-ticks .is-current {
  color: var(--bc-wood-dark);
}

.locked-hint,
.dialog-note {
  margin: 6px 0 0;
  font-size: 13px;
  font-style: italic;
}

.dialog-note {
  margin: -6px 0 18px;
}

/* Online, the dialog widens to put the match details beside the usual options, as in the game. */
.new-game-dialog.is-online {
  width: min(820px, calc(100vw - 32px));
}

@media (min-width: 760px) {
  .new-game-dialog.is-online .new-game-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
  }
}

.online-section {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.online-section .section-label {
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: stretch;
}

.field-label {
  font-size: 14px;
  font-weight: 600;
}

.room-code-row {
  display: flex;
  gap: 8px;
}

#room-code-input {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

#room-code-input[readonly] {
  background: var(--bc-parchment-dark);
}

.online-status {
  margin: 0;
  font-size: 14px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.dialog-actions-single {
  grid-template-columns: minmax(160px, auto);
  justify-content: center;
}

.notice-dialog {
  width: min(380px, calc(100vw - 32px));
  text-align: center;
}

.game-over-kicker {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--bc-wood);
}

.game-over-portrait {
  display: block;
  width: 120px;
  height: 120px;
  margin: 4px auto 12px;
  border-radius: 50%;
}

.game-over-title {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  color: var(--bc-gold-text);
}

.game-over-unlock {
  margin: 10px auto 0;
  max-width: 280px;
  font-size: 15px;
  font-weight: 600;
}

.notice-dialog .dialog-actions {
  margin-top: 18px;
}

.notice-title {
  margin: 0 0 10px;
  font-size: 24px;
  font-weight: 700;
  color: var(--bc-gold-text);
}

.notice-text {
  margin: 0;
}

.text-dialog {
  width: min(600px, calc(100vw - 32px));
}

.text-dialog p {
  margin: 0 0 12px;
}

.rules {
  margin: 0 0 12px;
  padding-inline-start: 24px;
}

.rules li {
  margin-bottom: 6px;
}

.about-publisher {
  font-size: 13px;
  color: var(--bc-ink-soft);
}

/*--------------------------------------------------------------
# Smaller windows: the panel cards go above and below the board
--------------------------------------------------------------*/
@media (max-width: 879px) {
  .play-main,
  .play-main.has-chat {
    --board: min(100vw - 32px - var(--card-chrome), 640px);
  }

  .play-shell {
    padding: 12px 16px;
  }

  .play-main {
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }

  .side-panel {
    display: contents;
  }

  .now-playing,
  .scoreboard,
  .chat {
    width: 100%;
    max-width: calc(640px + var(--card-chrome));
  }

  .chat {
    order: 5;
    flex-basis: auto;
    height: 340px;
  }

  .now-playing {
    order: 1;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "portrait title"
      "portrait side"
      "portrait hint";
    align-items: center;
    column-gap: 14px;
    padding: 10px 14px;
    text-align: start;
  }

  .now-playing .card-title {
    grid-area: title;
    font-size: 18px;
    text-align: start;
  }

  .side-label {
    grid-area: side;
    margin: 0;
    min-height: 0;
    font-size: 14px;
  }

  .portrait {
    grid-area: portrait;
    width: 72px;
    height: 72px;
  }

  .hint {
    grid-area: hint;
    margin: 2px 0 0;
    min-height: 2.8em;
    font-size: 15px;
  }

  .board-card {
    order: 2;
    padding: 8px;
  }

  .actions {
    order: 3;
  }

  .scoreboard {
    order: 4;
    padding: 12px;
  }

  .scoreboard .card-title {
    font-size: 18px;
    margin-bottom: 8px;
  }

  .stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .stat {
    padding: 6px 4px;
  }

  .stat-number {
    font-size: 22px;
  }

  .stat-label {
    font-size: 11px;
  }
}

@media (max-width: 559px) {
  .play-header {
    gap: 8px;
    margin-bottom: 12px;
  }

  .toolbar {
    gap: 6px;
    padding: 6px;
  }

  /* Phones set the volume with their own buttons; keep the mute switches. */
  .sound-panel {
    display: flex;
    gap: 4px;
    padding: 2px 4px;
  }

  .sound-row input[type="range"] {
    display: none;
  }

  .sound-row label {
    width: auto;
    padding-right: 4px;
  }

  .tool-btn {
    padding: 6px 9px;
    font-size: 13px;
  }

  .language-select {
    width: 118px;
    padding: 5px 6px;
    font-size: 13px;
  }

  .btn {
    font-size: 18px;
    padding: 9px 16px;
  }

  .game-dialog {
    padding: 18px;
  }

  .side-tile {
    width: 120px;
    height: 120px;
  }

  .stat-label {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .piece {
    transition: none;
  }
}
