/* Chez Paul - a chess study at night.
   Materials: green baize, boxwood + walnut, brass trim, ivory type. */

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

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/fraunces-v38-latin-regular.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/fraunces-v38-latin-500.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/fraunces-v38-latin-600.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/fraunces-v38-latin-italic.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/fraunces-v38-latin-500italic.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/inter-v20-latin-regular.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/inter-v20-latin-500.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/inter-v20-latin-600.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/jetbrains-mono-v24-latin-regular.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/jetbrains-mono-v24-latin-500.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono-v24-latin-700.woff2") format("woff2");
}

:root {
  /* Palette */
  --baize: #14211b;
  --baize-felt: #1b2c24;
  --baize-deep: #0e1813;
  --brass: #c9a45c;
  --brass-bright: #e6cc8a;
  --ivory: #f1ebdc;
  --sage: #9ba593;
  --sage-dim: #6f7a6c;
  --hairline: rgba(201, 164, 92, 0.18);

  --boxwood: #e9d7ae;
  --walnut: #9c6a43;
  --select-ring: #f4dca0;
  --select-seam: rgba(14, 10, 5, 0.55);
  --last-ring: #4fb79a;
  --last-glow: rgba(79, 183, 154, 0.28);
  --capture-ring: rgba(196, 90, 74, 0.85);

  --alarm: #d27a5f;
  --alarm-bg: rgba(196, 90, 74, 0.16);

  /* Type */
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  /* Geometry. Square size is capped so the whole page fits a ~1080p
     viewport without scrolling: it shrinks to honour available height
     (board + masthead + chrome) and width (board + control card). */
  --sq: min(76px, calc((100vh - 300px) / 8), calc((100vw - 470px) / 8));
  --coord: 22px;
  --mat: 24px;
  --board: calc(var(--sq) * 8);
  --radius: 4px;
}

body {
  font-family: var(--sans);
  color: var(--ivory);
  background-color: var(--baize);
  background-image:
    radial-gradient(
      120% 80% at 50% -10%,
      rgba(201, 164, 92, 0.1),
      transparent 60%
    ),
    radial-gradient(100% 70% at 50% 120%, rgba(0, 0, 0, 0.45), transparent 65%);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: clamp(16px, 3vh, 36px) 20px;
  -webkit-font-smoothing: antialiased;
}

.room {
  width: 100%;
  max-width: 1080px;
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 3vh, 32px);
}

/* ---------- Masthead ---------- */

.masthead {
  text-align: center;
}

.masthead__eyebrow {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--brass);
  padding-left: 0.42em;
  margin-bottom: 0.7rem;
}

.masthead__mark {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.6rem, 7vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: -0.01em;
  color: var(--ivory);
}

.masthead__mark em {
  font-style: italic;
  font-weight: 400;
  color: var(--brass-bright);
}

/* ---------- Layout ---------- */

.parlor {
  display: flex;
  gap: clamp(24px, 4vw, 44px);
  align-items: stretch;
  justify-content: center;
}

/* ---------- The table (board) ---------- */

.table {
  animation: settle 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.table__mat {
  padding: var(--mat);
  background:
    radial-gradient(
      130% 120% at 50% 0%,
      rgba(255, 255, 255, 0.05),
      transparent 55%
    ),
    var(--baize-felt);
  border-radius: 10px;
  border: 1px solid rgba(201, 164, 92, 0.28);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 30px 70px rgba(0, 0, 0, 0.55);
}

.board-frame {
  display: grid;
  grid-template-columns: var(--coord) var(--board);
  grid-template-rows: var(--board) var(--coord);
  gap: 0;
}

.board {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(8, var(--sq));
  grid-template-rows: repeat(8, var(--sq));
  /* brass bezel */
  box-shadow:
    0 0 0 2px var(--brass),
    0 0 0 4px var(--baize-deep),
    inset 0 0 30px rgba(0, 0, 0, 0.35);
}

.ranks,
.files {
  display: flex;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--brass);
  opacity: 0.7;
}

.ranks {
  grid-column: 1;
  grid-row: 1;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}

.files {
  grid-column: 2;
  grid-row: 2;
  justify-content: space-around;
  align-items: center;
  padding-top: 6px;
}

/* ---------- Squares ---------- */

.square {
  width: var(--sq);
  height: var(--sq);
  position: relative;
  cursor: pointer;
  user-select: none;
  background-repeat: no-repeat;
  background-position: center 52%;
  background-size: 84%;
  transition: filter 0.12s ease;
}

.square.light {
  background-color: var(--boxwood);
}

.square.dark {
  background-color: var(--walnut);
}

.square:hover {
  filter: brightness(1.06);
}

.square.selected {
  box-shadow:
    inset 0 0 0 3px var(--select-ring),
    inset 0 0 0 6px var(--select-seam),
    inset 0 0 26px rgba(244, 220, 150, 0.42);
}

.square.last-move::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 3px var(--last-ring),
    inset 0 0 16px var(--last-glow);
}

.square.legal-move::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24%;
  height: 24%;
  background: rgba(14, 24, 19, 0.5);
  box-shadow: 0 0 0 2px rgba(241, 235, 220, 0.45);
  border-radius: 50%;
}

.square.legal-capture {
  box-shadow: inset 0 0 0 5px var(--capture-ring);
}

/* ---------- The card ---------- */

.card {
  width: 312px;
  flex-shrink: 0;
  background: var(--baize-felt);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  animation: settle 0.7s 0.08s cubic-bezier(0.22, 1, 0.36, 1) both;
  /* Cap the card at the board's height so it never grows past it. This
     gives the flex:1 scoresheet a definite bound to scroll inside,
     instead of the card (and page) stretching with every move. */
  max-height: calc(var(--board) + var(--coord) + var(--mat) * 2);
}

.card__head {
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 16px;
}

.card__title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.card__sub {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--sage-dim);
  margin-top: 0.45rem;
}

/* Clock readout */

.clock {
  display: flex;
  align-items: stretch;
  background: var(--baize-deep);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
}

.clock__cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
}

.clock__divider {
  width: 1px;
  background: var(--hairline);
}

.clock__key {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--sage-dim);
}

.clock__val {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--brass-bright);
  font-variant-numeric: tabular-nums;
}

/* Status - the maitre d' line */

.status {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.08rem;
  text-align: center;
  padding: 13px 14px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--hairline);
  color: var(--ivory);
  transition:
    color 0.2s ease,
    background 0.2s ease;
}

.status.check {
  background: var(--alarm-bg);
  border-color: rgba(210, 122, 95, 0.5);
  color: var(--alarm);
}

.status.thinking {
  color: var(--brass-bright);
  border-color: rgba(201, 164, 92, 0.45);
  animation: breathe 1.6s ease-in-out infinite;
}

.status.game-over {
  background: rgba(201, 164, 92, 0.14);
  border-color: var(--brass);
  color: var(--brass-bright);
  font-style: normal;
  font-weight: 500;
}

/* Controls */

.controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field__label {
  font-size: 0.85rem;
  color: var(--sage);
}

select {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ivory);
  background: var(--baize-deep);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

select:hover {
  border-color: rgba(201, 164, 92, 0.45);
}

select:focus-visible {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 2px rgba(201, 164, 92, 0.3);
}

.buttons {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  flex: 1;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform 0.1s ease,
    box-shadow 0.15s ease,
    background 0.15s ease,
    color 0.15s ease;
}

.btn--primary {
  background: var(--brass);
  color: var(--baize-deep);
  font-weight: 600;
}

.btn--primary:hover {
  background: var(--brass-bright);
  box-shadow: 0 6px 18px rgba(201, 164, 92, 0.3);
  transform: translateY(-1px);
}

.btn--primary:active {
  transform: translateY(0);
}

.btn--ghost {
  background: transparent;
  color: var(--ivory);
  border-color: var(--hairline);
}

.btn--ghost:hover {
  border-color: var(--brass);
  color: var(--brass-bright);
}

.btn--ghost.inactive,
.btn:disabled {
  color: var(--sage-dim);
  border-color: rgba(201, 164, 92, 0.1);
  cursor: not-allowed;
  pointer-events: none;
}

/* Scoresheet */

.scoresheet {
  flex: 1;
  display: flex;
  flex-direction: column;
  /* min-height:0 lets this shrink so the inner list scrolls rather than
     pushing the card taller; flex:1 still fills the space beside the board. */
  min-height: 0;
}

.scoresheet__list {
  flex: 1;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ivory);
  background: var(--baize-deep);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 164, 92, 0.4) transparent;
}

/* One ruled line per ply, so the rule always sits under its text and
   scrolls with it (a fixed background would drift on scroll). */
.ply {
  line-height: 26px;
  border-bottom: 1px solid var(--hairline);
}

.scoresheet__list:empty::before,
.history-content:empty::before {
  content: "No moves yet.";
  display: block;
  line-height: 26px;
  color: var(--sage-dim);
}

.history-content {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  justify-content: flex-end;
}

.scoresheet__list::-webkit-scrollbar {
  width: 6px;
}

.scoresheet__list::-webkit-scrollbar-thumb {
  background: rgba(201, 164, 92, 0.4);
  border-radius: 3px;
}

/* ---------- Promotion modal ---------- */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 11, 0.78);
  backdrop-filter: blur(3px);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
  animation: fade 0.2s ease both;
}

.modal-content {
  background: var(--baize-felt);
  border: 1px solid var(--brass);
  padding: 28px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
}

.modal-content h3 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.3rem;
  margin-bottom: 18px;
}

.promotion-choices {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.promo-btn {
  width: 68px;
  height: 68px;
  font-size: 46px;
  line-height: 1;
  color: var(--baize-deep);
  background: var(--boxwood);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    transform 0.15s ease,
    border-color 0.15s ease;
}

.promo-btn:hover {
  border-color: var(--brass);
  transform: translateY(-3px);
}

/* ---------- Motion ---------- */

@keyframes settle {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes breathe {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .parlor {
    flex-direction: column;
    align-items: center;
  }

  :root {
    --sq: 64px;
  }

  .card {
    width: 100%;
    max-width: calc(var(--board) + var(--coord) + var(--mat) * 2);
    /* Board is stacked above the card here, so don't cap to its height;
       the scoresheet is bounded by its own max-height below. */
    max-height: none;
  }

  .scoresheet {
    min-height: 120px;
    max-height: 220px;
  }
}

@media (max-width: 560px) {
  :root {
    --sq: min(40px, calc((100vw - 96px) / 8));
    --mat: 14px;
    --coord: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

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