:root {
  --bg: #15120f;
  --panel: #1f1a16;
  --frame: #3b2d1f;
  --frame-gilt: #8a6b3a;
  --text: #e7dccb;
  --muted: #9d8f7c;
  --accent: #c9a24a;
  --canvas: #0d0b09;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(ellipse at top, #241d17 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.4 Georgia, "Times New Roman", serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;   /* title | counters centred | controls */
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  border-bottom: 1px solid #2c241d;
  background: rgba(0, 0, 0, 0.25);
}
.topbar h1 {
  font-size: 20px;
  font-weight: normal;
  letter-spacing: 0.04em;
  margin: 0;
}
.stats { display: flex; gap: 36px; font-variant-numeric: tabular-nums; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; order: 2; margin-top: 3px; }
.stat .value { font-size: 22px; color: var(--accent); white-space: nowrap; }
.actions { display: flex; gap: 8px; align-items: center; justify-self: end; }
.level-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; margin-right: 8px; }
select {
  font: inherit;
  color: var(--text);
  background-color: var(--panel);
  border: 1px solid #4a3f33;
  border-radius: 4px;
  padding: 5px 30px 5px 10px;
  cursor: pointer;
  /* own chevron, inset from the edge (the native one sits flush against the border) */
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%239d8f7c' stroke-width='1.5' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--frame);
  border: 1px solid var(--frame-gilt);
  border-radius: 4px;
  padding: 6px 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #4a3826; }
button.secondary { background: transparent; border-color: #4a3f33; color: var(--muted); }
button.secondary:hover { color: var(--text); }
button:disabled { opacity: 0.4; cursor: default; }

.game {
  flex: 1;
  display: flex;
  gap: 24px;
  padding: 20px;
  min-height: 0;
}

.board-column {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.board {
  position: relative;
  background: var(--canvas);
  box-shadow:
    0 0 0 6px var(--frame),
    0 0 0 8px var(--frame-gilt),
    0 0 0 18px var(--frame),
    0 20px 60px rgba(0, 0, 0, 0.7);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 8px 8px;
}
.board.active {
  outline: 2px solid rgba(201, 162, 74, 0.35);
  outline-offset: 4px;
  /* faint cell grid while a piece is being dragged or selected; --cell-w/h set from game.js */
  background-image:
    linear-gradient(rgba(201, 162, 74, 0.22) 1px, transparent 1px),
    linear-gradient(90deg, rgba(201, 162, 74, 0.22) 1px, transparent 1px);
  background-size: var(--cell-w) var(--cell-h);
  background-position: -1px -1px;
}

.hand-column {
  flex: none;            /* width set from game.js: slots are sized in image px times the shared scale */
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.hand-header { display: flex; align-items: baseline; justify-content: space-between; }
.hand-header h2 { font-size: 14px; font-weight: normal; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 0; }
.box-count { color: var(--muted); font-size: 13px; }
.hand {
  background: var(--panel);
  border: 1px solid #2c241d;
  border-radius: 6px;
  display: grid;         /* size and grid-template-columns set from game.js; padding and gap must match game.js */
  box-sizing: border-box;
  gap: 8px;
  padding: 8px;
  justify-content: center;
  align-content: center;
  align-items: center;
}
.slot { border: 1px dashed rgba(255, 255, 255, 0.05); border-radius: 4px; flex: none; }

/* Pieces live in a full-window layer so they can travel between hand and board. */
.stage {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.piece {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  pointer-events: auto;
  cursor: grab;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.7));
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), filter 150ms;
  will-change: transform;
  touch-action: none;
}
.piece.dragging { transition: none; cursor: grabbing; z-index: 100; filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.8)); }
.piece.selected { filter: drop-shadow(0 0 2px var(--accent)) drop-shadow(0 0 2px var(--accent)) drop-shadow(0 0 12px rgba(201, 162, 74, 0.9)); z-index: 20; }
.piece.placed { cursor: default; pointer-events: none; filter: none; z-index: 1; }
.piece.loose { z-index: 5; }
.piece.in-hand { z-index: 10; }
.piece.shake { animation: shake 320ms ease; }
.piece-img {
  width: 100%;
  height: 100%;
  background-image: url("artifacts/portrait.jpeg");
  background-repeat: no-repeat;
}

@keyframes shake {
  0%, 100% { translate: 0 0; }
  25% { translate: -6px 0; }
  50% { translate: 6px 0; }
  75% { translate: -4px 0; }
}

.done {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  animation: fade 400ms ease;
}
.done[hidden] { display: none; }
.done-card {
  background: var(--panel);
  border: 1px solid var(--frame-gilt);
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
}
.done-card h2 { margin: 0 0 8px; font-weight: normal; font-size: 22px; }
.done-card p { color: var(--muted); margin: 0 0 18px; }

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

@media (max-width: 800px) {
  .topbar { grid-template-columns: 1fr; gap: 10px; }
  .stats { gap: 32px; justify-self: center; }
  .actions { justify-self: center; flex-wrap: wrap; justify-content: center; }
  .game { flex-direction: column; gap: 24px; padding: 20px; }
  .hand { display: flex; overflow-x: auto; align-items: center; justify-content: flex-start; }
}
