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

:root {
  --bg: #002204;
  --panel: #002704;
  --ink: #ffffff;
  --muted: #7d8b7b;
  --accent: #028728;
  --accent-dark: #00ad31;
  --board-bg: #002204;
  --cell-border: #000000;
  --cell-empty: #003606;
  --tile-face: #fdf6e9;
  --tile-border: #c4b59a;
  --tw: #1f3d37;
  --dw: #742f3d;
  --tl: #223f62;
  --dl: #2a627e;
  --center: #9c2634;
  --pending: #fff3bf;
  --selected: #ffd666;
  --shadow: 0 4px 14px rgba(44, 40, 37, 0.12);
  --radius: 10px;
  --font: "Times New Roman";
  --font-ui: "Times New Roman";
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg)
}

body {
  padding-bottom: 1.5rem;
}

.hidden {
  display: none !important;
}

/* --- App shell --- */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.app-header {
  padding: 1rem 0 0.5rem;
}

.logo {
  font-family: var(--font);
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
}

.logo-sub {
  font-weight: 400;
  color: var(--muted);
  font-size: 1rem;
}

.main {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-start;
  justify-content: center;
}

/* --- Board --- */
.board-section {
  flex: 0 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  grid-template-rows: repeat(15, minmax(0, 1fr));
  gap: 2px;
  width: min(72vmin, 640px);
  height: min(72vmin, 640px);
  background: var(--cell-border);
  padding: 4px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.cell {
  position: relative;
  container-type: size;
  container-name: boardcell;
  background: var(--cell-empty);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-weight: 700;
  font-size: clamp(0.55rem, 2.1vmin, 1rem);
  cursor: pointer;
  user-select: none;
  min-width: 0;
  min-height: 0;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.cell:hover:not(.has-letter) {
  filter: brightness(1.03);
}

.cell .cell-label {
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(0.22rem, 1.05vmin, 0.48rem);
  font-weight: 700;
  line-height: 1.08;
  opacity: 0.92;
  pointer-events: none;
  font-family: var(--font-ui);
  hyphens: auto;
  overflow: hidden;
}

/* Center start square: star fills the cell */
.cell .cell-center-star {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 400;
  pointer-events: none;
  font-size: clamp(0.7rem, 3.5vmin, 2.25rem);
}

@supports (font-size: 1cqmin) {
  .cell .cell-center-star {
    font-size: 78cqmin;
  }
}

.cell .letter {
  z-index: 1;
  text-transform: uppercase;
}

.cell .points {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 0.42em;
  font-weight: 600;
  opacity: 0.75;
  pointer-events: none;
  font-family: var(--font-ui);
}

/* Premium backgrounds */
.cell.premium-tw {
  background: hsl(169, 34%, 37%);
  color: #ffffff;
}
.cell.premium-dw {
  background: #aa2c43;
  color: #ffffff;
}
.cell.premium-tl {
  background: #255fad;
  color: #ffffff;
}
.cell.premium-dl {
  background: #2a8bb2;
  color: #ffffff;
}
.cell.premium-center {
  background: var(--center);
  color: #4a2529;
}

.cell.has-letter {
  background: var(--tile-face);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.06);
  cursor: default;
}

.cell.pending {
  outline: 2px solid #d4a017;
  background: var(--pending);
}

.cell.pending.has-letter {
  background: linear-gradient(180deg, var(--pending) 0%, var(--tile-face) 100%);
}

.cell.selected-target {
  box-shadow: inset 0 0 0 3px var(--accent);
}

/* --- Sidebar --- */
.sidebar {
  flex: 1 1 220px;
  max-width: 280px;
  background: var(--panel);
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar h2 {
  font-family: var(--font);
  font-size: 1.1rem;
  margin: 0.75rem 0 0.5rem;
}

.sidebar h2:first-child {
  margin-top: 0;
}

.sidebar-line {
  margin: 0.35rem 0;
  font-size: 0.95rem;
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.score-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid #e8e2d9;
  font-size: 0.95rem;
}

.score-list li.current {
  background: #fff8e8;
  margin: 0 -0.6rem;
  padding-left: 0.6rem;
  padding-right: 0.6rem;
  border-radius: 6px;
  border-bottom-color: transparent;
}

.status {
  margin: 0.75rem 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.4;
  min-height: 2.75rem;
}

.status-info {
  background: #eef6ff;
  color: #254061;
  border: 1px solid #c5daf0;
}

.status-error {
  background: #fff0f0;
  color: #6b2020;
  border: 1px solid #e8b4b4;
}

.status-success {
  background: #eef8f0;
  color: #1e4d2e;
  border: 1px solid #b8dcc4;
}

.legend {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.6rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  align-items: center;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  display: inline-block;
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.swatch.tw {
  background: #a8d4cc;
  border: 1px solid #1e4d44;
}
.swatch.dw {
  background: #f0c4cc;
  border: 1px solid #6b2f3d;
}
.swatch.tl {
  background: #b8d0f0;
  border: 1px solid #1e3d6b;
}
.swatch.dl {
  background: #c8e6f2;
  border: 1px solid #1e556b;
}
.swatch.ce {
  background: var(--center);
  border: 1px solid #4a2529;
}

/* --- Footer: controls + rack --- */
.footer {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #d9d0c4;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  border: 1px solid #c4bbb0;
  background: #fff;
  color: #000000;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.btn:hover {
  background: #faf8f5;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

.rack-label {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.rack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  min-height: 3.25rem;
  padding: 0.5rem;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.rack-tile {
  width: 2.5rem;
  height: 2.85rem;
  border-radius: 6px;
  background: linear-gradient(180deg, #fffef9 0%, var(--tile-face) 100%);
  border: 2px solid var(--tile-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  user-select: none;
  color: #000000;
}

.rack-tile .rack-letter {
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.15rem;
  text-transform: uppercase;
  line-height: 1;
}

.rack-tile .rack-points {
  position: absolute;
  bottom: 3px;
  right: 4px;
  font-family: var(--font-ui);
  font-size: 0.5rem;
  font-weight: 700;
  opacity: 0.82;
  line-height: 1;
}

.rack-tile:hover {
  transform: translateY(-2px);
}

.rack-tile .sub {
  font-size: 0.55rem;
  font-family: var(--font-ui);
  color: var(--muted);
  margin-top: 0.1rem;
}

.rack-tile.selected {
  outline: 3px solid var(--accent);
  transform: translateY(-3px);
}

.rack-tile.placed-pending {
  opacity: 0.35;
  pointer-events: none;
}

/* --- Overlays --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 40, 37, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 1.5rem 1.75rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}

.modal h1 {
  font-family: var(--font);
  font-size: 1.5rem;
  margin: 0 0 0.5rem;
}

.setup-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.setup-players {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.setup-players label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.setup-players input {
  flex: 1;
  padding: 0.45rem 0.6rem;
  border: 1px solid #c4bbb0;
  border-radius: 6px;
  font-size: 0.95rem;
}

.setup-count {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

.setup-count select {
  margin-left: 0.35rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid #c4bbb0;
}

.setup-actions {
  display: flex;
  justify-content: flex-end;
}

.end-modal #end-message {
  font-size: 1rem;
  line-height: 1.5;
  margin: 0.5rem 0 1.25rem;
  white-space: pre-line;
}

@media (max-width: 700px) {
  .main {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar {
    max-width: none;
  }

  .board {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }
}
