* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  min-height: 100%;
  min-height: 100dvh;
  margin: 0;
  background: linear-gradient(180deg, #06304d 0%, #0a4a72 40%, #0d5f8f 100%);
  color: #eaf4fb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.app-header {
  padding: 14px 0 6px;
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.app-header h1 {
  font-size: 1.3rem;
  margin: 0;
  letter-spacing: 0.5px;
  text-align: center;
}
.mute-btn {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
}
.mute-btn:active { transform: translateY(-50%) scale(0.92); }
.home-btn {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1rem;
  line-height: 34px;
  text-align: center;
  cursor: pointer;
  color: inherit;
  text-decoration: none;
  display: inline-block;
}
.home-btn:active { transform: translateY(-50%) scale(0.92); }

.app-icon {
  border-radius: 7px;
  margin-right: 8px;
  vertical-align: middle;
}

.screen {
  display: none;
  width: 100%;
  max-width: 480px;
  padding: 8px 14px 24px;
  flex: 1;
}
.screen.active { display: block; }

.card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.card.center { text-align: center; }

label {
  display: block;
  font-size: 0.85rem;
  opacity: 0.85;
  margin: 12px 0 6px;
}
label:first-child { margin-top: 0; }

input[type="text"] {
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.9);
  color: #0a2a43;
  outline: none;
}
input[type="text"]:focus { border-color: #4fc3f7; }

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.btn-row button { flex: 1; min-width: 120px; }

.btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 13px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: #ffb84d; color: #3a2400; }
.btn-secondary { background: rgba(255,255,255,0.14); color: #eaf4fb; border: 1px solid rgba(255,255,255,0.25); }
.btn-danger-outline { background: transparent; color: #ff8a80; border: 1px solid #ff8a80; margin-top: 18px; width: 100%; }

.hidden { display: none !important; }

.solo-box {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(255,255,255,0.15);
}
.solo-label {
  margin: 0 0 10px;
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
}
.btn-solo {
  width: 100%;
  background: rgba(90,180,220,0.22);
  color: #eaf4fb;
  border: 1px solid rgba(90,180,220,0.6);
}
.level-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.level-btn {
  flex: 1;
  padding: 9px 0;
  font-size: 0.85rem;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  color: #eaf4fb;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s;
}
.level-btn.active {
  background: #ffb84d;
  border-color: #ffb84d;
  color: #3a2400;
  font-weight: 600;
}
.level-btn:active { transform: scale(0.96); }

.error {
  color: #ff8a80;
  font-size: 0.85rem;
  margin-top: 10px;
}

.code-display {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 16px;
  margin: 14px 0;
}

.hint { opacity: 0.8; font-size: 0.9rem; margin-top: 14px; }
.dots span { animation: blink 1.4s infinite; opacity: 0; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity:0; } 40% { opacity:1; } }

.board-label {
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.85;
  margin: 4px 0 0;
}

.capture-banner {
  color: #ff8a80;
  font-weight: 700;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 4px;
  font-size: 0.9rem;
}
.turn-indicator {
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255,255,255,0.12);
}
.turn-indicator.my-turn { background: #ffb84d; color: #3a2400; }
.turn-indicator:not(.my-turn) { animation: radarPulse 2s ease-in-out infinite; }
@keyframes radarPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79,195,247,0.5); }
  50% { box-shadow: 0 0 0 8px rgba(79,195,247,0); }
}

.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,42,67,0.95);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 0.9rem;
  z-index: 50;
  transition: opacity 0.25s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

h2 { margin-top: 0; }

/* ---------- Reconnect banner ---------- */

.reconnect-banner {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  z-index: 70;
  background: #ffb84d;
  color: #3a2400;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  transition: transform 0.25s ease;
}
.reconnect-banner.hidden { transform: translateY(-120%); }

/* ---------- Emoji reaction bar ---------- */

.emoji-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  justify-content: flex-start;
  padding: 6px 2px 2px;
  margin-top: 6px;
}
.emoji-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.emoji-btn:active { transform: scale(0.88); background: rgba(255,255,255,0.2); }

#emoji-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 65;
}
.emoji-bubble {
  position: absolute;
  bottom: 60px;
  font-size: 1.8rem;
  animation: emojiFloat 2.2s ease-out forwards;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.35));
}
@keyframes emojiFloat {
  0% { transform: translateY(0) scale(0.6) rotate(0deg); opacity: 0; }
  15% { opacity: 1; transform: translateY(-20px) scale(1.1) rotate(-4deg); }
  100% { transform: translateY(-320px) scale(1) rotate(6deg); opacity: 0; }
}

/* ---------- Game-over sheet ---------- */

.gameover-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(8,36,58,0.97);
  border: 1px solid rgba(255,255,255,0.15);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  text-align: center;
  box-shadow: 0 -8px 30px rgba(0,0,0,0.4);
  transition: transform 0.3s ease;
  max-height: 60vh;
  overflow-y: auto;
}
.gameover-sheet.hidden { transform: translateY(105%); }
.sheet-toggle {
  position: absolute;
  top: 8px;
  right: 12px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  color: inherit;
  cursor: pointer;
}
.sheet-reopen {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 55;
  background: #ffb84d;
  color: #3a2400;
  border: none;
  border-radius: 30px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  cursor: pointer;
}

/* ---------- Dame board ---------- */

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  margin: 10px auto;
  border-radius: 8px;
  overflow: hidden;
  border: 3px solid rgba(255,255,255,0.15);
  user-select: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.square.light { background: #2a5578; }
.square.dark { background: #123650; cursor: pointer; }
.square.dark.selected { background: #3a6e28; }
.square.dark.legal-target { background: #2f5f2a; }
.square.dark.legal-target::after {
  content: "";
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: rgba(255,184,77,0.55);
}

.piece {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: transform 0.1s ease;
}
.piece.w { background: radial-gradient(circle at 32% 28%, #ffffff, #d9e3ea 65%, #a9b7c1 100%); box-shadow: 0 2px 3px rgba(0,0,0,0.4); }
.piece.b { background: radial-gradient(circle at 32% 28%, #5a636e, #23272d 65%, #0d0f12 100%); box-shadow: 0 2px 3px rgba(0,0,0,0.4); }
.piece.king::after { content: "♛"; opacity: 0.75; }
.piece.w.king::after { color: #7a5b1e; }
.piece.b.king::after { color: #d8c98a; }
.piece.selected { transform: scale(1.1); box-shadow: 0 0 0 3px #ffb84d; }
