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

body {
  font-family: system-ui, sans-serif;
  background: #f5f0e8;
  color: #333;
  min-height: 100vh;
}

nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: #2c5f2e;
  color: white;
}

p {
  line-height: 1.5em;
}

nav a {
  color: #cfe8cf;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 1.2rem;
}

h1 {
  font-size: 1.6rem;
  font-weight: bold;
}

h2 {
  font-size: 1.4rem;
}

.form {
  background-color: rgba(180, 50, 60, 0.2);
}

.login-box {
  max-width: 320px;
  margin: 6rem auto;
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-box input,
.login-box button {
  width: 100%;
  padding: 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
}

.login-box button {
  background: #2c5f2e;
  color: white;
  border: none;
  cursor: pointer;
}

.login-box ul {
  margin-left: 2em;
}

.error {
  color: red;
  font-size: 0.9rem;
}

.toasts {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
}

.toast {
  padding: 0.7rem 1.1rem;
  border-radius: 6px;
  background: #2c5f2e;
  color: white;
  font-size: 0.9rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: opacity 0.4s, transform 0.4s;
}

.toast-error {
  background: #b03030;
}

.toast-warning {
  background: #a06010;
}

.toast-hide {
  opacity: 0;
  transform: translateX(1rem);
  pointer-events: none;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  padding: 1rem;
  height: calc(100vh - 48px);
}

.board-section {
  background: white;
  border-radius: 8px;
  padding: 1rem;
  overflow: auto;
}

.sidebar {
  display: flex;
  flex-direction: column;
}

.chat-section {
  background: white;
  border-radius: 8px;
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 400px;
}

.chat-message {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
}

.chat-message.mine {
  align-items: flex-end;
}

.chat-message.theirs {
  align-items: flex-start;
}

.chat-message .text {
  background: #e8f5e9;
  padding: 0.3rem 0.6rem;
  border-radius: 12px;
}

.chat-message.mine .text {
  background: #2c5f2e;
  color: white;
}

.chat-message .author,
.chat-message .time {
  font-size: 0.7rem;
  color: #888;
}

.chat-section form {
  margin-top: auto;
  display: flex;
  gap: 0.4rem;
}

.chat-section input {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.chat-section button {
  padding: 0.4rem 0.8rem;
  background: #2c5f2e;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.setup-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-width: 480px;
  margin: 3rem auto;
  padding: 0 1rem;
}

.setup-card {
  background: white;
  border-radius: 8px;
  padding: 1.5rem 2rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.games-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.game-link {
  display: block;
  padding: 0.55rem 1rem;
  background: #f5f0e8;
  border-radius: 6px;
  text-decoration: none;
  color: #333;
  font-weight: 500;
  border: 1px solid #e5dbcd;
  transition: background 0.15s;
}

.game-link:hover {
  background: #ede6dc;
}

.muted {
  color: #999;
  font-size: 0.9rem;
}

.new-game-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-label {
  font-size: 0.9rem;
  color: #555;
}

.player-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.player-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.player-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 1.1rem;
  border-radius: 999px;
  border: 2px solid #ccc;
  background: #f9f7f4;
  cursor: pointer;
  user-select: none;
  font-size: 1rem;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.player-pill input[type="checkbox"] {
  display: none;
}

.player-option.active .player-pill {
  border-color: #2c5f2e;
  background: #e8f5e9;
  color: #2c5f2e;
  font-weight: 600;
}

.goes-first-option {
  display: none;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: #555;
  cursor: pointer;
}

.you-label {
  font-size: 0.7em;
  font-weight: normal;
  font-style: normal;
  opacity: 0.6;
  padding-left: 5px;
}

.player-option.active .goes-first-option {
  display: inline-flex;
}

.goes-first-random {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: #777;
  cursor: pointer;
}

.start-btn {
  align-self: flex-start;
  padding: 0.55rem 1.4rem;
  background: #2c5f2e;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.start-btn:hover {
  background: #235026;
}

div.board-wrapper {
  max-width: 800px;
  margin: 2rem auto;
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.board-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding: 0 0.25rem;
}

.scoreboard {
  display: flex;
  gap: 1.5rem;
}

.score-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.85rem;
  color: #888;
}

.score-entry.active {
  color: #2c5f2e;
  font-weight: 600;
}

.score-name {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.score-value {
  font-size: 1.3rem;
  font-weight: bold;
}

.tiles-remaining {
  font-size: 0.8rem;
  color: #aaa;
}

#board {
  width: 600px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: repeat(15, 40px);
  grid-template-columns: repeat(15, 40px);
  grid-gap: 0;
  outline: 2px solid #e5dbcd;
}

div.tile {
  background-color: #f4f1ed;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-items: center;
  align-content: center;
  justify-content: center;
  border: 1px solid #ede6dc;
  position: relative;
}

div.tile.mod.letter-2 {
  background-color: #cdf0f5;
}

div.tile.mod.letter-3 {
  background-color: #a6b3ee;
}

div.tile.mod.word-2 {
  background-color: #f2c3ca;
}

div.tile.mod.word-3 {
  background-color: #fa5e75;
}

div.tile.mod::before {
  font-size: 0.45rem;
  text-align: center;
  font-weight: bold;
  font-variant: small-caps;
}

div.tile.mod.letter-2::before {
  content: "Double Letter Score"
}

div.tile.mod.letter-3::before {
  content: "Triple Letter Score"
}

div.tile.mod.word-2::before {
  content: "Double Word Score"
}

div.tile.mod.word-3::before {
  content: "Triple Word Score"
}

div.tile .letter {
  display: block;
  position: absolute;
  width: 33px;
  height: 35px;
  border-radius: 3px;
  border: 1px solid #e6e2de;
  background-color: #f9f7f4;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  font-weight: bold;
  font-size: 1.2rem;
}

div#rack {
  display: flex;
  flex-direction: row;
  justify-content: center;
  margin: 0em auto;
  gap: 0.5em;
  width: 450px;
  height: 80px;
  padding: 0.5em;
  border-bottom: 4px solid #a06010;
  align-items: center;
}

div#rack div.letter {
  width: 50px;
  height: 60px;
  border-radius: 3px;
  border: 1px solid #e6e2de;
  background-color: #f9f7f4;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  font-weight: bold;
  font-size: 1.8rem;
  cursor: pointer;
  position: relative;
}

div.letter span.points {
  display: inline-block;
  position: absolute;
  right: 0;
  bottom: 0;
  padding: 2px;
  font-size: 0.7rem;
}

div#rack div.letter span.points {
  font-size: 1rem;
}

div#rack div.letter[data-idx] {
  transition: transform 0.1s, box-shadow 0.1s;
  user-select: none;
}

div#rack div.letter[data-idx]:hover:not(.used) {
  transform: translateY(-4px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

div#rack div.letter[data-idx].selected {
  transform: translateY(-6px);
  box-shadow: 0 6px 12px rgba(44, 95, 46, 0.4);
  border-color: #2c5f2e;
  background-color: #e8f5e9;
}

div#rack div.letter[data-idx].used {
  opacity: 0.3;
  cursor: default;
  transform: none;
  box-shadow: none;
}

div.tile { cursor: default; }
#board-container.selecting .tile { cursor: pointer; }
div.tile.pending { cursor: pointer;
  outline: 2px solid #2c5f2e;
  outline-offset: -2px;
}

div.tile.pending .pending-letter {
  background-color: #d4edda;
  border-color: #2c5f2e;
}

.rack-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-left: auto;
  align-self: center;
}

.rack-actions button {
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
}

#submit-move {
  width: 100%;
  background: #2c5f2e;
  color: white;
  padding: 0.3rem 0.5rem;
  border: none;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
}

#confirm-swap {
  width: 100%;
  background: #2c5f2e;
  color: white;
  padding: 0.3rem 0.5rem;
  border: none;
  border-radius: 4px;
  font-size: 0.65rem;
  cursor: pointer;
}

#submit-move:disabled {
  background: #aaa;
  cursor: default;
}

#cancel-move {
  width: 100%;
  background: #b08e30;
  color: white;
  padding: 0.3rem 1.2rem;
  border: none;
  border-radius: 4px;
  font-size: 0.65rem;
  cursor: pointer;
}

#skip-turn {
  width: 100%;
  background: #b03030;
  color: white;
  padding: 0.3rem 1.2rem;
  border: none;
  border-radius: 4px;
  font-size: 0.65rem;
  cursor: pointer;
}

.rack-row {
  padding-top: 1em;
  display: flex;
  align-items: start;
  justify-content: center;
  
}

.rack-wrapper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.shuffle-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #ccc;
  background: #f0ece4;
  color: #888;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.shuffle-icon:hover {
  background: #e8e0d4;
  color: #444;
}

.rack-submit-area {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.4rem;
  margin-left: 1rem;
}

.score-preview {
  font-size: 0.85rem;
  font-weight: bold;
  color: white;
  min-height: 1.2em;
}

.rack-waiting {
  text-align: center;
  color: #888;
  font-style: italic;
  margin-top: 0.5rem;
}

div.rack-letters {
  display: flex;
  flex-direction: row;
  gap: 0.5em;
}

.move-error {
  color: #b03030;
  font-size: 0.8rem;
  max-width: 160px;
}

.swap-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #ccc;
  background: #f0ece4;
  color: #888;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.swap-icon:hover {
  background: #e8e0d4;
  color: #444;
}

.swap-icon.active {
  background: #2c5f2e;
  color: white;
  border-color: #2c5f2e;
}

div#rack div.letter[data-idx].swap-selected {
  background-color: #fff3cd;
  border-color: #a06010;
  box-shadow: 0 4px 8px rgba(160, 96, 16, 0.3);
  transform: translateY(-4px);
}

.game-over-banner {
  background: #2c5f2e;
  color: white;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.final-scores {
  list-style: none;
  display: flex;
  gap: 1rem;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  opacity: 0.9;
}

.game-link {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.game-link-players {
  font-weight: 500;
}

.game-link-meta {
  font-size: 0.75rem;
  color: #888;
  font-weight: normal;
}

.prove-it-box {
  max-width: 520px;
  margin: 4rem auto;
  background: white;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  text-align: center;
}

.prove-subtitle {
  color: #777;
  font-size: 0.95rem;
}

.prove-viewport {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  background: #111;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.prove-viewport video,
.prove-viewport img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.prove-buttons {
  display: flex;
  gap: 0.75rem;
}

.prove-btn {
  padding: 0.6rem 1.4rem;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.prove-btn.primary {
  background: #2c5f2e;
  color: white;
}

.prove-btn.primary:hover {
  background: #235026;
}

.prove-btn.primary:disabled {
  background: #aaa;
  cursor: default;
}

.prove-btn.secondary {
  background: #f0ece4;
  color: #555;
  border: 1px solid #ddd;
}

.prove-btn.secondary:hover {
  background: #e8e0d4;
}