/* ==========================================================================
   Rummikub - Stylesheet
   Mobile-first, Dracula dark theme, uses skills CSS variables
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Reset and Layout
   -------------------------------------------------------------------------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #282A36;
  color: #F8F8F2;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
#app { min-height: 100vh; min-height: 100dvh; max-width: 760px; margin: 0 auto; }
#game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: 60px; /* Space for menu button */
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   2. Status Bar
   -------------------------------------------------------------------------- */
#status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.75rem;
  background: var(--skills-surface, #1E1F29);
  border-bottom: 1px solid var(--skills-border, #44475A);
  font-size: 0.8rem;
  flex-shrink: 0;
}
#turn-status {
  font-weight: bold;
  color: var(--skills-accent, #BD93F9);
}
#pool-count {
  color: var(--skills-text, #F8F8F2);
  opacity: 0.7;
}

/* --------------------------------------------------------------------------
   3. Players Section
   -------------------------------------------------------------------------- */
#players-section {
  background: var(--skills-surface, #1E1F29);
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--skills-border, #44475A);
  flex-shrink: 0;
}
#players-display {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
}
.player-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  white-space: nowrap;
  background: rgba(255,255,255,0.05);
  border: 1px solid transparent;
  transition: all 0.2s;
}
.player-chip.is-me {
  border-color: var(--skills-accent, #BD93F9);
}
.player-chip.is-current {
  background: rgba(80, 250, 123, 0.15);
  border-color: var(--skills-success, #50FA7B);
  animation: pulse-turn 1.5s infinite;
}
.player-chip-name { font-weight: bold; }
.player-chip-count {
  background: rgba(255,255,255,0.1);
  padding: 0.1rem 0.35rem;
  border-radius: 8px;
  font-size: 0.7rem;
}

/* --------------------------------------------------------------------------
   4. Table Area
   -------------------------------------------------------------------------- */
#table-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.5rem;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.table-set {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 0.4rem;
  padding: 0.2rem 0.15rem;
  border-radius: 6px;
  min-height: 52px;
  position: relative;
  flex-wrap: nowrap;
}
.table-set.invalid {
  background: rgba(255, 85, 85, 0.15);
  border: 1px solid rgba(255, 85, 85, 0.4);
  animation: shake 0.4s ease-in-out;
}
#new-set-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  margin-top: 0.3rem;
  border: 2px dashed rgba(255,255,255,0.2);
  border-radius: 8px;
  color: rgba(255,255,255,0.4);
  font-size: 0.85rem;
  transition: all 0.2s;
  cursor: pointer;
}
#new-set-zone.drop-hover {
  border-color: var(--skills-success, #50FA7B);
  background: rgba(80, 250, 123, 0.1);
  color: var(--skills-success, #50FA7B);
}

/* --------------------------------------------------------------------------
   5. Tiles
   -------------------------------------------------------------------------- */
.tile {
  width: 44px;
  height: 60px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.2rem;
  background: #F8F8F2;
  border: 2px solid #CCCCCC;
  cursor: pointer;
  position: relative;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.tile:active {
  transform: scale(0.95);
}
.tile.tile-red { color: #FF5555; }
.tile.tile-blue { color: #5B8FEF; }
.tile.tile-black { color: #333333; }
.tile.tile-orange { color: #E8943A; }
.tile.tile-joker {
  color: #BD93F9;
  font-size: 1.4rem;
}
.tile .tile-number {
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.tile .tile-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  margin-top: 2px;
}
.tile-red .tile-dot { background: #FF5555; }
.tile-blue .tile-dot { background: #5B8FEF; }
.tile-black .tile-dot { background: #333333; }
.tile-orange .tile-dot { background: #E8943A; }
.tile-joker .tile-dot { background: #BD93F9; }

/* Tile played this turn (from rack to table) */
.tile.played-this-turn {
  border-color: var(--skills-accent, #BD93F9);
  box-shadow: 0 0 6px rgba(189, 147, 249, 0.4);
}

/* Selected tile */
.tile.selected {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 4px 12px rgba(255, 184, 108, 0.5);
  border-color: #FFB86C;
  z-index: 10;
}

/* Dragging states */
.tile.dragging {
  opacity: 0.3;
}
.drag-ghost {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  transform: scale(1.1);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0.9;
}

/* --------------------------------------------------------------------------
   6. Insert Slots (appear between tiles when one is selected)
   -------------------------------------------------------------------------- */
.insert-slot {
  width: 0;
  height: 52px;
  border: none;
  background: transparent;
  transition: width 0.2s, border-color 0.2s, background 0.2s;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 4px;
  position: relative;
}
.insert-slot.active {
  width: 24px;
  border: 2px dashed rgba(255, 184, 108, 0.5);
  background: rgba(255, 184, 108, 0.08);
}
.insert-slot.active:hover,
.insert-slot.drop-hover {
  border-color: var(--skills-success, #50FA7B);
  background: rgba(80, 250, 123, 0.15);
}
.insert-slot.active::after {
  content: '+';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 184, 108, 0.5);
  font-size: 0.8rem;
  font-weight: bold;
}

/* --------------------------------------------------------------------------
   7. Action Bar
   -------------------------------------------------------------------------- */
#action-bar {
  display: flex;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: var(--skills-surface, #1E1F29);
  border-top: 1px solid var(--skills-border, #44475A);
  border-bottom: 1px solid var(--skills-border, #44475A);
  flex-shrink: 0;
}
.action-btn {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--skills-border, #44475A);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: var(--skills-text, #F8F8F2);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.action-btn:active:not(:disabled) {
  transform: scale(0.97);
}
.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.action-btn.btn-primary {
  background: var(--skills-success, #50FA7B);
  color: #282A36;
  border-color: var(--skills-success, #50FA7B);
}
.action-btn.btn-primary:disabled {
  background: rgba(80, 250, 123, 0.3);
  border-color: rgba(80, 250, 123, 0.3);
  color: rgba(40, 42, 54, 0.6);
}

/* --------------------------------------------------------------------------
   8. Rack Area
   -------------------------------------------------------------------------- */
#rack-area {
  background: var(--skills-surface, #1E1F29);
  padding: 0.5rem;
  border-top: 1px solid var(--skills-border, #44475A);
  flex-shrink: 0;
  overflow: hidden;
}
#rack-tiles {
  display: flex;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 0.3rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
#rack-tiles::-webkit-scrollbar {
  height: 4px;
}
#rack-tiles::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   9. Turn Indicator
   -------------------------------------------------------------------------- */
#turn-indicator {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  animation: turn-slide-in 0.3s ease-out;
}
.turn-content {
  background: var(--skills-success, #50FA7B);
  color: #282A36;
  padding: 0.4rem 1.2rem;
  border-radius: 0 0 12px 12px;
  font-weight: 900;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 4px 16px rgba(80, 250, 123, 0.3);
}

/* --------------------------------------------------------------------------
   10. Toast Notifications
   -------------------------------------------------------------------------- */
#toast-container {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  animation: toast-in 0.3s ease-out;
  pointer-events: auto;
}
.toast.error {
  background: rgba(255, 85, 85, 0.95);
  color: #F8F8F2;
}
.toast.success {
  background: rgba(80, 250, 123, 0.95);
  color: #282A36;
}
.toast.info {
  background: rgba(189, 147, 249, 0.95);
  color: #282A36;
}

/* --------------------------------------------------------------------------
   11. How to Play Modal
   -------------------------------------------------------------------------- */
#howtoplay-modal {
  position: fixed;
  inset: 0;
  background: #282A36;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#howtoplay-modal .modal-content {
  position: relative;
  padding: 1.5rem 1.25rem 2rem;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}
#howtoplay-modal .modal-close-x {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  transition: color 0.15s;
}
#howtoplay-modal .modal-close-x:hover {
  color: #fff;
}
#howtoplay-modal h2 {
  text-align: center;
  margin-bottom: 0.5rem;
  color: #50FA7B;
  font-size: 1.75rem;
  font-weight: 800;
}
#howtoplay-modal h3 {
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  color: #50FA7B;
  font-size: 1.35rem;
}
#howtoplay-modal p {
  font-size: 1.25rem;
  line-height: 1.7;
  color: #e0e0e0;
  margin-bottom: 0.6rem;
}
#howtoplay-modal li {
  font-size: 1.2rem;
  line-height: 1.7;
  color: #e0e0e0;
  margin-bottom: 0.4rem;
}
#howtoplay-modal strong {
  color: #fff;
}
#howtoplay-modal em {
  color: #FFB86C;
}
#howtoplay-modal ul {
  padding-left: 1.2rem;
}
#howtoplay-modal .btn-close-howto {
  display: block;
  margin: 2rem auto 0;
  padding: 0.7rem 2rem;
  border-radius: 6px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  background: #50FA7B;
  color: #1a1a2e;
  font-size: 1rem;
}

/* --------------------------------------------------------------------------
   12. Animations
   -------------------------------------------------------------------------- */
@keyframes pulse-turn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
@keyframes turn-slide-in {
  from { transform: translateX(-50%) translateY(-100%); }
  to { transform: translateX(-50%) translateY(0); }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* --------------------------------------------------------------------------
   13. Responsive
   -------------------------------------------------------------------------- */
@media (min-width: 500px) {
  .tile {
    width: 48px;
    height: 64px;
    font-size: 1.3rem;
  }
  .insert-slot.active {
    width: 28px;
  }
}
