:root {
  color-scheme: light;
  font-family: 'Nunito', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --accent: #ff6b81;
  --accent-dark: #ff4764;
  --border: rgba(0, 0, 0, 0.08);
  --text: #1f2933;
  --muted: #52606d;
  --shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  padding: 3rem 1.5rem 1.5rem;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3rem);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.75rem auto 0;
  max-width: 40rem;
  color: var(--muted);
}

.app-layout {
  width: min(1100px, 92vw);
  margin: 0 auto 4rem;
  display: grid;
  gap: 2rem;
}

.panel {
  background: var(--panel);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.panel.hidden {
  display: none;
}

.panel h2 {
  margin-top: 0;
}

.session-options {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.card {
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 600;
}

.field input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
}

button {
  cursor: pointer;
  border-radius: 999px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  padding: 0.75rem 1.4rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
  box-shadow: none;
}

button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
  box-shadow: 0 12px 20px rgba(255, 107, 129, 0.35);
}

button.secondary {
  background: #1fb6ff;
  color: white;
  box-shadow: 0 12px 20px rgba(31, 182, 255, 0.25);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(15, 23, 42, 0.15);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Nunito', monospace;
}

.room-info code {
  background: rgba(31, 182, 255, 0.12);
  color: #0379b5;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-weight: 700;
}

.uploader {
  margin: 1.5rem 0;
}

.upload-area {
  display: grid;
  place-items: center;
  gap: 0.5rem;
  background: rgba(31, 182, 255, 0.08);
  border: 2px dashed rgba(31, 182, 255, 0.45);
  border-radius: 20px;
  padding: 2.5rem 1rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-area:hover {
  border-color: rgba(31, 182, 255, 0.85);
  background: rgba(31, 182, 255, 0.12);
}

#cardUpload {
  display: none;
}

.board-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1rem;
}

.board-grid.editable .card {
  position: relative;
  padding-bottom: 0;
}

.card-inner {
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.6));
  border-radius: 16px;
  padding: 0.75rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-height: 170px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.3s ease;
}

.card img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px rgba(15, 23, 42, 0.08);
}

.card-label,
.card-name-input {
  width: 100%;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.card-name-input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  font-family: inherit;
}

.card.editing button.remove {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255, 71, 100, 0.9);
  color: white;
  border: none;
  font-size: 1rem;
}

.card.down .card-inner {
  filter: grayscale(100%) brightness(0.85);
  transform: translateY(4px) scale(0.97);
  box-shadow: inset 0 0 0 3px rgba(15, 23, 42, 0.12);
}

.card.secret .card-inner {
  box-shadow: 0 0 0 3px rgba(255, 107, 129, 0.8);
}

.card:focus-visible .card-inner,
.card:hover:not(.editing) .card-inner {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.editor-actions {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: flex-end;
}

.game-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.room-code code {
  background: rgba(31, 182, 255, 0.12);
  color: #0379b5;
  padding: 0.25rem 0.55rem;
  border-radius: 8px;
}

.players {
  display: flex;
  gap: 1rem;
}

.player-tag {
  background: rgba(15, 23, 42, 0.05);
  padding: 0.5rem 0.8rem;
  border-radius: 10px;
  font-weight: 600;
}

.game-body {
  display: grid;
  gap: 2rem;
  grid-template-columns: minmax(0, 3fr) minmax(240px, 1fr);
}

.sidebar {
  display: grid;
  gap: 1.5rem;
}

.secret h3,
.chat h3 {
  margin-top: 0;
}

#chatLog {
  background: rgba(15, 23, 42, 0.04);
  border-radius: 12px;
  padding: 1rem;
  min-height: 160px;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.95rem;
}

.chat-entry {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.chat-entry .meta {
  font-size: 0.75rem;
  color: var(--muted);
}

#chatForm {
  display: flex;
  gap: 0.5rem;
}

#chatInput {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 0.6rem 1rem;
  font-size: 1rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 900px) {
  .game-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .sidebar {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 1.5rem;
  }

  .card-inner {
    min-height: 150px;
  }
}
