@font-face {
  font-family: 'Bernie Sans Beta';
  src: url('https://joro.io/files/BernieSansBetaVF.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
}

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

body {
  font-family: 'Bernie Sans Beta', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  position: relative;
}

/* Burger Menu */
#burger-menu {
  position: absolute;
  top: 15px;
  right: 15px;
  z-index: 1000;
}

#burger-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: white;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s;
}

#burger-btn:hover {
  background: #f5f5f5;
  transform: scale(1.05);
}

#burger-dropdown {
  position: absolute;
  top: 60px;
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  min-width: 150px;
  overflow: hidden;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 12px 20px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 1em;
  transition: background 0.2s;
}

.menu-item:hover {
  background: #f5f5f5;
}

/* Dialog Styles */
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.dialog {
  background: white;
  border-radius: 12px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.dialog-large {
  max-width: 700px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 2px solid #e0e0e0;
}

.dialog-header h2 {
  margin: 0;
  color: #667eea;
}

.close-dialog {
  background: none;
  border: none;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  color: #999;
  padding: 0;
  width: 32px;
  height: 32px;
  transition: color 0.2s;
}

.close-dialog:hover {
  color: #333;
}

.dialog-content {
  padding: 20px;
}

.dialog-content h2 {
  color: #667eea;
  margin-top: 20px;
  margin-bottom: 10px;
}

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

.dialog-content h3 {
  color: #764ba2;
  margin-top: 15px;
  margin-bottom: 8px;
}

.dialog-content ul {
  margin-left: 20px;
  margin-bottom: 15px;
}

.dialog-content li {
  margin-bottom: 5px;
}

.dialog-content a {
  color: #667eea;
}

.setting-item {
  margin-bottom: 20px;
}

.setting-item label {
  display: block;
  font-weight: bold;
  margin-bottom: 8px;
  color: #333;
}

.setting-item input,
.setting-item select {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 1em;
  background: white;
  box-sizing: border-box;
}

.setting-item input:focus,
.setting-item select:focus {
  outline: none;
  border-color: #667eea;
}

.setting-item input[type="number"] {
  -moz-appearance: textfield;
}

.setting-item input[type="number"]::-webkit-outer-spin-button,
.setting-item input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.dialog-footer {
  padding: 20px;
  border-top: 2px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.dialog-footer:has(> button:only-child),
.dialog-footer:has(> .primary-btn:only-child) {
  justify-content: center;
}

.checkbox-label,
.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.radio-label input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.letter-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
  padding: 15px;
  max-width: 550px;
  margin: 0 auto;
}

.letter-option {
  width: 45px;
  height: 45px;
  font-size: 1.4em;
  font-family: 'Noto Sans Shavian', sans-serif;
  font-weight: bold;
  background: linear-gradient(135deg, #f5e5a3 0%, #f0e68c 50%, #e6d77a 100%);
  border: 2px solid #daa520;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.4),
              inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.1s, box-shadow 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.letter-option:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.letter-option:active {
  transform: scale(0.98);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.primary-btn {
  padding: 10px 24px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.3s;
}

.primary-btn:hover {
  background: #5568d3;
}

/* Compound letter breakdown */
.compound-breakdown {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin: 20px 0;
  padding: 20px;
  background: #f5f5f5;
  border-radius: 8px;
}

.breakdown-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.breakdown-row .tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 45px;
  height: 45px;
  background: linear-gradient(135deg, #f5e5a3 0%, #f0e68c 50%, #e6d77a 100%);
  border: 2px solid #daa520;
  border-radius: 4px;
  font-size: 1.4em;
  font-weight: bold;
  color: #333;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.4),
              inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.breakdown-row .tile.compound {
  background: linear-gradient(135deg, #ffb3b3 0%, #ff9999 50%, #ff7f7f 100%);
  border-color: #cc5555;
}

.breakdown-row .operator {
  font-size: 1.3em;
  font-weight: bold;
  color: #667eea;
  padding: 0 4px;
}

.important-note {
  background: #fff3cd;
  padding: 15px;
  border-left: 4px solid #ffc107;
  border-radius: 4px;
  margin: 20px 0;
}

/* Lobby Screen */
#lobby-screen {
  background: white;
  border-radius: 12px;
  padding: 40px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  max-width: 600px;
  margin: 50px auto;
  position: relative;
}

#lobby-screen h1 {
  text-align: center;
  color: #333;
  margin-bottom: 10px;
  font-size: 2.5em;
}

#lobby-screen > p {
  text-align: center;
  color: #666;
  margin-bottom: 40px;
}

#lobby-screen .copyright {
  margin-bottom: 20px;
  font-size: 0.9em;
  opacity: 0.7;
}

#lobby-screen .copyright a {
  color: #667eea;
  text-decoration: none;
}

#lobby-screen .copyright a:hover {
  text-decoration: underline;
}

#lobby-options {
  display: flex;
  gap: 20px;
  flex-direction: column;
  align-items: center;
  max-width: 400px;
  margin: 0 auto;
}

.lobby-btn {
  width: 100%;
  padding: 20px 40px;
  font-size: 1.2em;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: 600;
}

.lobby-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.lobby-option {
  flex: 1;
  min-width: 200px;
}

.lobby-option h2 {
  font-size: 1.3em;
  margin-bottom: 15px;
  color: #667eea;
}

.lobby-option input {
  width: 100%;
  padding: 12px;
  margin-bottom: 10px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 1em;
}

.lobby-option input:focus {
  outline: none;
  border-color: #667eea;
}

.lobby-option button {
  width: 100%;
  padding: 12px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1em;
  cursor: pointer;
  transition: background 0.3s;
}

.lobby-option button:hover {
  background: #5568d3;
}

#invite-link-container {
  margin-top: 30px;
  padding: 20px;
  background: #f5f5f5;
  border-radius: 8px;
}

.invite-link {
  display: flex;
  gap: 10px;
  margin: 15px 0;
}

.invite-link input {
  flex: 1;
  padding: 10px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-family: monospace;
}

.invite-link button {
  padding: 10px 20px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.waiting-message {
  text-align: center;
  color: #666;
  font-style: italic;
}

/* Game Screen */
#game-screen {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  position: relative;
}

#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 20px;
  padding-right: 70px; /* Make room for burger menu */
  border-bottom: 2px solid #e0e0e0;
}

#game-header h1 {
  font-size: 2em;
  color: #333;
}

#game-info {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

#game-info button {
  padding: 10px 20px;
  font-size: 1em;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.3s ease;
  background: #666;
  color: white;
}

#game-info button:hover {
  background: #555;
}

#main-menu-game-btn {
  background: #2196F3;
}

#main-menu-game-btn:hover {
  background: #1976D2;
}

#leave-game-btn {
  background: #FF9800;
}

#leave-game-btn:hover {
  background: #F57C00;
}

#end-game-btn {
  background: #f44336;
}

#end-game-btn:hover {
  background: #d32f2f;
}

#tiles-remaining {
  font-weight: bold;
  font-size: 1.1em;
  padding: 0 15px;
}

#pass-turn-btn {
  padding: 10px 20px;
  background: #999;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

#pass-turn-btn:hover {
  background: #777;
}

#game-container {
  display: grid;
  grid-template-columns: 200px 1fr;
  grid-template-rows: auto auto;
  gap: 20px;
}

/* Players Panel */
#players-panel {
  grid-row: 1 / 3;
}

#players-panel h2 {
  font-size: 1.3em;
  margin-bottom: 15px;
  color: #667eea;
}

.player-card {
  padding: 15px;
  margin-bottom: 10px;
  background: #f5f5f5;
  border-radius: 8px;
  border-left: 4px solid #ddd;
}

.player-card.active {
  border-left-color: #667eea;
  background: #e8eaf6;
}

.player-card.current-user {
  background: #fff3cd;
  border-left-color: #ffc107;
}

.player-card.disconnected {
  opacity: 0.6;
  background: #f0f0f0;
  border-left-color: #999;
}

.player-card.left-game {
  opacity: 0.5;
  background: #fafafa;
  border-left-color: #bbb;
  text-decoration: line-through;
}

.player-card.spectator {
  background: #e3f2fd;
  border-left-color: #2196f3;
}

.player-name {
  font-weight: bold;
  margin-bottom: 5px;
}

.player-score {
  color: #666;
  font-size: 0.9em;
}

.remove-player-btn {
  margin-top: 8px;
  padding: 4px 8px;
  background: #ff5252;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
}

.remove-player-btn:hover {
  background: #ff1744;
}

/* Board */
#board-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

#board {
  display: grid;
  grid-template-columns: repeat(15, 40px);
  grid-template-rows: repeat(15, 40px);
  gap: 1px;
  background: #999;
  border: 2px solid #333;
}

.square {
  width: 40px;
  height: 40px;
  background: #f5deb3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5em;
  font-weight: bold;
  cursor: pointer;
  position: relative;
  user-select: none;
}

.square.TW { background: #ff6b6b; }
.square.DW { background: #ffa07a; }
.square.TL { background: #4dabf7; }
.square.DL { background: #74c0fc; }

.square.center {
  background: #ffd700 url('/shcrabble/Lion.png') center center no-repeat;
  background-size: contain;
}

.square:not(.occupied):hover {
  background-color: #fff8dc;
}

.square.occupied {
  background: linear-gradient(135deg, #f5e5a3 0%, #f0e68c 50%, #e6d77a 100%);
  border: 2px solid #daa520;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.4),
              inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

.square.placement {
  background: linear-gradient(135deg, #b3f5b3 0%, #98fb98 50%, #7ee67e 100%) !important;
  border: 2px solid #52b152 !important;
  border-radius: 3px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.4),
              inset 0 -1px 0 rgba(0, 0, 0, 0.1);
}

/* Ghost placement - tiles placed while waiting for turn */
.square.ghost-placement {
  background: linear-gradient(135deg, rgba(179, 245, 179, 0.3) 0%, rgba(152, 251, 152, 0.3) 50%, rgba(126, 230, 126, 0.3) 100%) !important;
  border: 2px dashed #52b152 !important;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.square.ghost-placement .placed-tile {
  opacity: 0.5;
}

.bonus-label {
  position: absolute;
  font-size: 0.5em;
  color: white;
  font-weight: bold;
  text-shadow: 0 0 2px rgba(0,0,0,0.5);
  width: 100%;
  text-align: center;
  top: 50%;
  transform: translateY(-50%);
}

.tile-letter {
  font-size: 1.3em;
  color: #333;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.5);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.1));
}

.square .tile-points {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 0.4em;
  font-weight: normal;
  color: #333;
}

/* Rack */
#rack-container {
  padding: 20px;
  background: #f5f5f5;
  border-radius: 8px;
}

#rack-container h3 {
  margin-bottom: 15px;
  color: #667eea;
}

#rack {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  min-height: 60px;
  padding: 10px;
  background: white;
  border-radius: 6px;
}

@keyframes tileAppear {
  0% {
    opacity: 0;
    transform: translateY(-20px) scale(0.8);
  }
  50% {
    transform: translateY(5px) scale(1.05);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes slideInFromLeft {
  from {
    opacity: 0;
    transform: translateX(-100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideToPosition {
  from {
    transform: translateX(var(--slide-from, 0));
  }
  to {
    transform: translateX(0);
  }
}

@keyframes recallTile {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(0.8);
  }
  100% {
    opacity: 0;
    transform: scale(0.5);
  }
}

.rack-tile {
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, #f5e5a3 0%, #f0e68c 50%, #e6d77a 100%);
  border: 2px solid #daa520;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5em;
  font-weight: bold;
  cursor: grab;
  user-select: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2),
              inset 0 1px 0 rgba(255, 255, 255, 0.4),
              inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.1s;
  position: relative;
}

.rack-tile.new-tile {
  animation: slideInFromLeft 0.4s ease-out;
}

.rack-tile.sliding {
  animation: slideToPosition 0.3s ease-out;
}

.rack-tile.recalling {
  animation: recallTile 0.3s ease-out forwards;
  pointer-events: none;
}

.placed-tile.recalling {
  animation: recallTile 0.3s ease-out forwards;
  pointer-events: none;
}

/* Highlight last move */
.square.last-move-highlight {
  box-shadow: 0 0 0 3px #4CAF50, 0 0 15px rgba(76, 175, 80, 0.6);
  animation: pulseHighlight 2s ease-in-out infinite;
  z-index: 10;
  position: relative;
}

@keyframes pulseHighlight {
  0%, 100% {
    box-shadow: 0 0 0 3px #4CAF50, 0 0 15px rgba(76, 175, 80, 0.6);
  }
  50% {
    box-shadow: 0 0 0 3px #66BB6A, 0 0 20px rgba(76, 175, 80, 0.8);
  }
}

.square.last-move-highlight.fading {
  animation: fadeHighlight 1s ease-out forwards;
}

@keyframes fadeHighlight {
  from {
    box-shadow: 0 0 0 3px #4CAF50, 0 0 15px rgba(76, 175, 80, 0.6);
  }
  to {
    box-shadow: none;
  }
}

.rack-tile.rack-gap {
  opacity: 0 !important;
  pointer-events: none;
  background: transparent;
  border: none;
  box-shadow: none;
}

.rack-tile .tile-points {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 0.5em;
  font-weight: normal;
  color: #333;
}

.rack-tile:active {
  cursor: grabbing;
}

.rack-tile.dragging {
  opacity: 1;
  transform: scale(1.1) rotate(3deg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

.rack-tile.drag-over {
  margin-left: 60px;
  transition: margin-left 0.2s ease;
}

.rack-tile.blank {
  background: linear-gradient(135deg, #fff0d0 0%, #ffe4b5 50%, #ffd89b 100%);
  font-style: italic;
}

#move-controls {
  display: flex;
  gap: 10px;
}

#move-controls button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 6px;
  font-size: 1em;
  cursor: pointer;
  transition: all 0.3s;
}

#submit-move-btn {
  background: #667eea;
  color: white;
}

#submit-move-btn:hover:not(:disabled) {
  background: #5568d3;
}

#submit-move-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

#recall-tiles-btn {
  background: #ff6b6b;
  color: white;
}

#recall-tiles-btn:hover {
  background: #ff5252;
}

/* Messages */
#message-area {
  margin-top: 20px;
  padding: 15px;
  background: #e3f2fd;
  border-radius: 8px;
  min-height: 40px;
}

.error {
  background: #ffebee !important;
  color: #c62828;
}

.success {
  background: #e8f5e9 !important;
  color: #2e7d32;
}

/* Your turn notification */
@keyframes turnFlash {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(255, 215, 0, 0);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(255, 215, 0, 0.8),
                0 0 0 16px rgba(255, 215, 0, 0.4);
  }
}

#game-screen.your-turn {
  animation: turnFlash 2s ease-in-out infinite;
  border-radius: 8px;
}

/* Mobile Layout for portrait screens (phones) */
@media (max-width: 768px) and (orientation: portrait) {
  /* Adjust game container to stack vertically */
  #game-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
  }

  /* Move players to horizontal scrollable bar at top */
  #players-panel {
    order: -1;
    width: 100%;
    margin-bottom: 10px;
  }

  #players-panel h2 {
    font-size: 1em;
    margin-bottom: 8px;
  }

  #players-list {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .player-card {
    flex: 0 0 140px;
    padding: 10px;
    margin-bottom: 0;
    font-size: 0.85em;
  }

  .section-header {
    flex: 0 0 auto;
    padding: 10px;
    font-weight: bold;
    color: #667eea;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    white-space: nowrap;
  }

  .player-score {
    font-size: 0.8em;
  }

  /* Make board container touch-zoomable */
  #board-container {
    width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y pinch-zoom;
    position: relative;
  }

  #board-container-zoom {
    transform-origin: top left;
    transition: transform 0.2s ease-out;
  }

  /* Scale board to fit width on mobile */
  #board {
    /* 15 squares * 32px + gaps */
    grid-template-columns: repeat(15, 32px);
    grid-template-rows: repeat(15, 32px);
    margin: 0 auto;
  }

  .square {
    width: 32px;
    height: 32px;
    font-size: 1.2em;
  }

  .bonus-label {
    font-size: 0.5em;
  }

  .tile-points {
    font-size: 0.6em;
  }

  /* Rack container */
  #rack-container {
    width: 100%;
    padding: 10px;
  }

  #rack-container h3 {
    font-size: 1em;
    margin-bottom: 8px;
  }

  #rack {
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
  }

  .rack-tile {
    width: 40px;
    height: 40px;
    font-size: 1.3em;
  }

  #move-controls {
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
  }

  #move-controls button {
    flex: 1 1 auto;
    min-width: 100px;
    font-size: 0.85em;
    padding: 8px 12px;
  }

  /* Adjust header for mobile */
  #game-header {
    flex-wrap: wrap;
    padding: 10px;
    gap: 10px;
  }

  #game-header h1 {
    font-size: 1.2em;
    flex: 1 1 100%;
  }

  #tiles-remaining {
    font-size: 0.9em;
  }

  #game-info {
    gap: 6px;
  }

  #game-info button {
    font-size: 0.8em;
    padding: 6px 10px;
  }

  /* Burger menu positioning */
  #burger-menu {
    top: 8px;
    right: 8px;
  }

  #burger-btn {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
}
