@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@700;800;900&display=swap');

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

:root {
  --bg-top: #9b59f7;
  --bg-bottom: #7c3aed;
  --card: #ffffff;
  --card-shadow: rgba(0, 0, 0, 0.1);
  --text-dark: #3a2d6b;
  --text-light: #ffffff;
  --text-muted: #a89cc8;
  --green: #6dd400;
  --green-shadow: #4da600;
  --pink: #ff6b9d;
  --pink-shadow: #d44a7a;
  --yellow: #ffc835;
  --yellow-shadow: #d4a020;
  --cyan: #5ce1e6;
  --cyan-shadow: #3ab8bd;
  --purple-btn: #7c4dff;
  --purple-btn-shadow: #5a35c9;
  --danger: #ff4757;
  --success: #2ed573;
}

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--text-light);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.screen { display: none; height: 100vh; height: 100dvh; }
.screen.active { display: flex; }

/* === JOIN === */
.join-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

h1 {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--yellow);
  text-shadow: 0 4px 0 rgba(0,0,0,0.15), 0 0 30px rgba(255,200,53,0.3);
  margin-bottom: 2rem;
  line-height: 1;
}

.subtitle {
  display: block;
  font-size: 1.5rem;
  letter-spacing: 0.3em;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.1);
}

#join-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

input[type="text"] {
  width: 100%;
  padding: 1rem 1.2rem;
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--card);
  border: 3px solid transparent;
  border-radius: 1.25rem;
  color: var(--text-dark);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 6px 20px var(--card-shadow);
  -webkit-appearance: none;
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus {
  border-color: var(--purple-btn);
  box-shadow: 0 6px 20px var(--card-shadow), 0 0 0 4px rgba(124,77,255,0.2);
}

.btn-primary {
  width: 100%;
  background: var(--green);
  color: var(--text-light);
  border: none;
  padding: 1rem;
  font-family: inherit;
  font-size: 1.3rem;
  font-weight: 900;
  border-radius: 3rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 6px 0 var(--green-shadow), 0 8px 20px rgba(0,0,0,0.15);
  text-shadow: 0 2px 2px rgba(0,0,0,0.2);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  top: 0;
}

.btn-primary:active {
  top: 4px;
  box-shadow: 0 2px 0 var(--green-shadow), 0 3px 10px rgba(0,0,0,0.15);
}

/* === HOST CONTROLS (on player phones) === */
.host-badge {
  background: var(--yellow);
  color: var(--text-dark);
  font-size: 0.9rem;
  font-weight: 900;
  padding: 0.3rem 1rem;
  border-radius: 1.5rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.75rem;
  box-shadow: 0 3px 0 var(--yellow-shadow);
}

.host-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.host-transfer {
  display: flex;
  gap: 0.5rem;
  width: 100%;
}

.transfer-select {
  flex: 1;
  padding: 0.6rem 0.8rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  background: var(--card);
  color: var(--text-dark);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 0.75rem;
  outline: none;
  -webkit-appearance: none;
}

.btn-transfer {
  background: var(--purple-btn);
  color: white;
  border: none;
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 900;
  border-radius: 0.75rem;
  box-shadow: 0 3px 0 var(--purple-btn-shadow);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-transfer:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--purple-btn-shadow);
}

.btn-secondary-sm {
  background: var(--pink);
  color: white;
  border: none;
  padding: 0.7rem 1.5rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 900;
  border-radius: 2rem;
  box-shadow: 0 4px 0 var(--pink-shadow);
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary-sm:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--pink-shadow);
}

/* === WAITING === */
.waiting-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.waiting-container h2 {
  font-size: 1.6rem;
  font-weight: 900;
  margin-bottom: 1rem;
  text-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.waiting-text {
  color: rgba(255,255,255,0.7);
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  animation: breathe 2s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.waiting-players {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.waiting-chip {
  background: var(--card);
  color: var(--text-dark);
  padding: 0.4rem 0.9rem;
  border-radius: 1.5rem;
  font-size: 0.9rem;
  font-weight: 800;
  box-shadow: 0 3px 10px var(--card-shadow);
}

/* === PLAYING === */
.playing-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 0.75rem;
}

.playing-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.25rem;
}

.mobile-timer {
  font-size: 2.2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.15);
}

.mobile-timer.urgent {
  color: var(--yellow);
  text-shadow: 0 3px 0 rgba(0,0,0,0.15), 0 0 20px rgba(255,200,53,0.4);
}

.mobile-timer.critical {
  color: var(--danger);
  text-shadow: 0 3px 0 rgba(0,0,0,0.2), 0 0 20px rgba(255,71,87,0.5);
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.02); }
}

.mobile-score {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--yellow);
  background: rgba(255,255,255,0.15);
  padding: 0.3rem 0.9rem;
  border-radius: 1.5rem;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

.mobile-board {
  display: inline-grid;
  gap: 0.35rem;
  padding: 0.75rem;
  background: var(--card);
  border-radius: 1.25rem;
  margin: 0.5rem auto;
  box-shadow: 0 8px 30px var(--card-shadow);
}

.mobile-board.size-4 { grid-template-columns: repeat(4, 1fr); }
.mobile-board.size-5 { grid-template-columns: repeat(5, 1fr); }

.mobile-tile {
  width: 3.6rem;
  height: 3.6rem;
  background: linear-gradient(180deg, #f0eaff 0%, #e0d5ff 100%);
  border: 2px solid var(--purple-btn);
  border-radius: 0.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--text-dark);
  box-shadow: 0 3px 0 #c4b5e3, inset 0 2px 0 rgba(255,255,255,0.5);
}

.mobile-tile .qu-small { font-size: 1.1rem; }

.word-input-area {
  padding: 0.5rem 0;
}

#word-form {
  display: flex;
  gap: 0.5rem;
}

#word-input {
  flex: 1;
  padding: 0.85rem 1rem;
  font-size: 1.2rem;
  text-transform: uppercase;
  border-radius: 1.25rem;
}

.btn-submit {
  background: var(--cyan);
  color: var(--text-dark);
  border: none;
  padding: 0.85rem 1.5rem;
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 900;
  border-radius: 1.25rem;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--cyan-shadow);
  text-shadow: 0 1px 1px rgba(0,0,0,0.1);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  top: 0;
}

.btn-submit:active {
  top: 3px;
  box-shadow: 0 1px 0 var(--cyan-shadow);
}

.submitted-words {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  -webkit-overflow-scrolling: touch;
}

.submitted-word {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.85rem;
  margin-bottom: 0.35rem;
  border-radius: 0.75rem;
  font-size: 1rem;
  font-weight: 700;
  animation: slideIn 0.2s ease;
}

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

.submitted-word.accepted {
  background: rgba(255, 255, 255, 0.15);
  color: var(--success);
}

.submitted-word.rejected {
  background: rgba(255, 71, 87, 0.15);
  color: rgba(255, 200, 200, 0.8);
}

.submitted-word .word-text {
  font-weight: 800;
  text-transform: uppercase;
}

.submitted-word .word-status {
  font-size: 0.85rem;
  font-weight: 900;
}

/* === RESULTS === */
.results-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 1.5rem;
  overflow-y: auto;
  height: 100vh;
  height: 100dvh;
  -webkit-overflow-scrolling: touch;
}

.results-container h2 {
  text-align: center;
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 1rem;
  text-shadow: 0 3px 0 rgba(0,0,0,0.15);
}

.results-container h3 {
  font-size: 1.2rem;
  font-weight: 900;
  margin: 1.5rem 0 0.75rem;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.your-score {
  text-align: center;
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 3px 0 rgba(0,0,0,0.15);
  margin-bottom: 0.75rem;
}

.your-words {
  background: var(--card);
  color: var(--text-dark);
  border-radius: 1.25rem;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 6px 20px var(--card-shadow);
}

.result-word {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.result-word.duplicate {
  color: var(--danger);
  text-decoration: line-through;
  opacity: 0.5;
}

.result-word .pts {
  font-weight: 900;
}

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

.mobile-rank {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  color: var(--text-dark);
  padding: 0.8rem 1rem;
  border-radius: 1rem;
  font-weight: 800;
  box-shadow: 0 4px 12px var(--card-shadow);
}

.mobile-rank.you {
  border: 3px solid var(--yellow);
  background: linear-gradient(180deg, #fff9e6, #fff);
}

.rank-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.rank-num {
  font-weight: 900;
  font-size: 1.2rem;
  min-width: 1.5rem;
  color: var(--purple-btn);
}

.rank-pts {
  font-weight: 900;
  color: var(--green);
}
