:root {
  color-scheme: dark;
  font-family: Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: #fff;
  background: #071012 url('../images/backgrounds/background_image.PNG') no-repeat center center fixed;
  background-size: cover;
}

#background {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(0, 0, 0, .44);
  pointer-events: none;
}

.page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 28%);
  gap: 16px;
  align-items: start;
  padding: 12px;
}

#spectator-main, #chat-panel { min-width: 0; }

.spectator-header {
  text-align: center;
  margin: 16px 12px 8px;
}

.spectator-header h1 {
  margin: 0 0 10px;
  font-size: clamp(30px, 4vw, 44px);
  text-shadow: 0 0 10px rgba(255,255,255,.75);
}

.spectator-header p { margin: 6px 0; color: #cfd8dc; }

.status {
  width: min(680px, 96%);
  margin-inline: auto !important;
  padding: 10px 14px;
  border: 1px solid #566;
  border-radius: 10px;
  background: rgba(0,0,0,.56);
}
.status--live { border-color: #00e6a8; color: #dffff6 !important; }
.status--loading { border-color: #67a7c2; }
.status--warning { border-color: #d9ad4a; color: #ffe7ad !important; }
.status--error { border-color: #ef5b70; color: #ffd2d9 !important; }
.status--finished { border-color: #00ffff; color: #cfffff !important; }

.turn-display {
  min-height: 28px;
  margin: 10px 0;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

.duel-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 12px 6px 88px;
}

.player {
  width: min(96%, 920px);
  padding: 18px;
  background: rgba(0,0,0,.68);
  border: 2px solid #566269;
  border-radius: 12px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.player.active {
  border-color: #00ffff;
  box-shadow: 0 0 14px rgba(0,255,255,.55);
}
.player h2 {
  margin: 0 0 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #7b858b;
  text-align: center;
  font-size: 24px;
}
.hp { text-align: center; font-size: 18px; font-weight: 700; }
.piles { margin: 8px 0 12px; text-align: center; color: #cfe9ff; font-size: 13px; }

.field, .hand {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 154px;
  margin: 10px 0;
}
.field { border-bottom: 1px solid rgba(255,255,255,.08); padding-bottom: 10px; }
.hand { opacity: .92; }

.card {
  position: relative;
  flex: 0 0 auto;
  width: 100px;
  height: 140px;
  overflow: hidden;
  background: #111;
  border: 1px solid #8c969b;
  border-radius: 6px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 5px 4px;
  font-size: 11px;
  line-height: 1.15;
  background: rgba(0,0,0,.78);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card.face-down { border-style: dashed; border-color: #61727a; }
.card:hover { transform: scale(1.04); box-shadow: 0 0 12px rgba(0,255,255,.45); }

body.practice-mode .spectator-header h1 {
  color: #cfffff;
  text-shadow: 0 0 15px #00ffff;
}
body.practice-mode { border-top: 4px solid #00ffff; }

#chat-panel {
  position: sticky;
  top: 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-height: 460px;
  max-height: calc(100vh - 24px);
  overflow: hidden;
  background: rgba(0,0,0,.72);
  border: 1px solid rgba(0,255,255,.42);
  border-radius: 12px;
  backdrop-filter: blur(5px);
}
#chat-panel, #chat-panel * { pointer-events: auto; }

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  border-bottom: 1px solid rgba(0,255,255,.16);
}
.chat-title { font-weight: 800; color: #9ff; }
.chat-identity { margin-top: 3px; font-size: 11px; color: #9cb2bd; }
.chat-presence { font-size: 12px; color: #cfe9ff; white-space: nowrap; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,255,255,.35) transparent;
}
.chat-row { display: flex; margin-bottom: 8px; }
.chat-row.me { justify-content: flex-end; }
.chat-bubble {
  max-width: 88%;
  padding: 8px 10px;
  background: rgba(10,20,25,.82);
  border: 1px solid rgba(0,255,255,.16);
  border-radius: 10px;
  word-break: break-word;
}
.chat-row.me .chat-bubble { background: rgba(0,60,70,.82); border-color: rgba(0,255,255,.4); }
.chat-meta { display: flex; gap: 8px; font-size: 11px; }
.chat-name { color: #bfe; font-weight: 700; }
.chat-time { color: #9ad; }
.chat-text { margin-top: 3px; line-height: 1.35; }
.chat-typing { min-height: 22px; padding: 2px 12px 6px; font-size: 12px; color: #9ad; }
.chat-form {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid rgba(0,255,255,.16);
  background: rgba(0,0,0,.5);
}
#chat-input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  color: #eefcff;
  background: rgba(0,0,0,.5);
  border: 1px solid rgba(0,255,255,.25);
  border-radius: 8px;
  outline: none;
}
#chat-input:focus { border-color: rgba(0,255,255,.7); box-shadow: 0 0 8px rgba(0,255,255,.16); }
#chat-send {
  padding: 9px 13px;
  border: 1px solid rgba(0,255,255,.48);
  border-radius: 8px;
  color: #bff;
  background: rgba(0,60,70,.78);
  cursor: pointer;
}
#chat-send:disabled { opacity: .55; cursor: not-allowed; }

.audio-toggle, .hub-btn {
  position: fixed;
  right: 16px;
  z-index: 10020;
  border: 1px solid rgba(0,255,255,.55);
  color: #dfffff;
  background: rgba(0,25,32,.9);
  backdrop-filter: blur(4px);
  text-decoration: none;
  cursor: pointer;
}
.audio-toggle {
  bottom: 16px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
}
.hub-btn {
  bottom: 70px;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
}
.audio-toggle:hover, .hub-btn:hover, #chat-send:hover { box-shadow: 0 0 10px rgba(0,255,255,.45); }

.highlight-blue { color: #00ffff !important; text-shadow: 0 0 12px #00ffff; }
.join-toast {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 10040;
  transform: translate(-50%, -10px);
  opacity: 0;
  padding: 10px 16px;
  white-space: nowrap;
  color: #bff;
  background: rgba(0,30,40,.94);
  border: 1px solid rgba(0,255,255,.5);
  border-radius: 12px;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.join-toast.show { opacity: 1; transform: translate(-50%, 0); }

.duel-result {
  position: fixed;
  inset: 0;
  z-index: 10030;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.duel-result.show { opacity: 1; pointer-events: auto; }
.duel-result__card {
  width: min(92vw, 520px);
  padding: 20px;
  text-align: center;
  color: #e8fafe;
  background: rgba(0,30,40,.98);
  border: 1px solid rgba(0,255,255,.5);
  border-radius: 14px;
  box-shadow: 0 0 20px rgba(0,255,255,.22);
}
.duel-result__title { color: #8ff; font-size: 21px; font-weight: 800; }
.duel-result__winner { margin: 10px 0 6px; font-size: 19px; font-weight: 800; }
.duel-result__reason { color: #cfe9ff; }
.duel-result__close {
  margin-top: 16px;
  padding: 9px 14px;
  border: 1px solid rgba(0,255,255,.45);
  border-radius: 9px;
  color: #bff;
  background: rgba(0,60,70,.75);
  cursor: pointer;
}

@media (max-width: 980px) {
  .page { grid-template-columns: 1fr; }
  #chat-panel { position: relative; top: auto; max-height: 560px; order: 3; }
}

@media (max-width: 620px) {
  .page { padding: 6px; }
  .player { width: 100%; padding: 12px 8px; }
  .duel-container { gap: 18px; padding-inline: 0; }
  .field, .hand { gap: 6px; min-height: 118px; }
  .card { width: 76px; height: 106px; }
  .card-name { font-size: 9px; }
  .hub-btn { left: 10px; right: auto; bottom: 12px; }
  .audio-toggle { right: 10px; bottom: 10px; }
  #chat-send { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
