.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1200px;
  padding: 8px 12px;
  background: #131c38;
  border-radius: 8px;
  margin-bottom: 12px;
  box-sizing: border-box;
  gap: 12px;
  flex-wrap: wrap;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #c8d0e8;
  font-size: 0.95em;
}

#level-label { color: #80a8ff; font-weight: 600; }

.progress {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #f0f4ff;
}

.play-area {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  width: 100%;
  max-width: 1500px;
  justify-content: center;
}

.canvas-region {
  position: relative;
  flex: 0 0 auto;
}

#game-canvas, #editor-canvas {
  display: block;
  background: #020514;
  border-radius: 8px;
  box-shadow: 0 0 60px rgba(80, 120, 255, 0.2);
  touch-action: none;
  max-width: 100%;
  height: auto;
  cursor: crosshair;
}

.sidebar {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-section {
  background: #131c38;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
}

.sidebar-section h2 {
  margin: 0 0 8px 0;
  font-size: 0.95em;
  font-weight: 600;
  color: #a8b8d8;
  border-bottom: 1px solid #2a3a60;
  padding-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#game-player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.95em;
}

#game-player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: #d0d8ee;
}

#game-player-list li.is-you { color: #80e0ff; }
#game-player-list li.is-turn {
  background: rgba(120, 160, 255, 0.12);
  border-radius: 4px;
  padding: 4px 6px;
  margin: 0 -6px;
}

#game-player-list .player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

#game-player-list .player-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#game-player-list .player-score {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #a8b8d8;
}

#chat-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px 0;
  max-height: 220px;
  min-height: 120px;
  overflow-y: auto;
  font-size: 0.9em;
}

#chat-list li {
  padding: 4px 0;
  color: #d0d8ee;
  word-break: break-word;
  line-height: 1.4;
}

#chat-list li .sender { font-weight: 600; margin-right: 4px; }
#chat-list li.kind-system { color: #a8b8d8; font-style: italic; }

.chat-input-row { display: flex; gap: 6px; }

#chat-input {
  flex: 1;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid #2a3a60;
  background: #0e1530;
  color: #f0f4ff;
  font-family: inherit;
  font-size: 0.9em;
  min-width: 0;
}

#btn-send-chat { padding: 7px 12px; font-size: 0.9em; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 15, 31, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: 8px;
  backdrop-filter: blur(4px);
}

.overlay-card {
  background: #131c38;
  border: 1px solid #2a3a60;
  border-radius: 10px;
  padding: 24px 32px;
  text-align: center;
  max-width: 90%;
  min-width: 320px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.overlay-card h2 { margin: 0 0 8px 0; color: #f0f4ff; }
.overlay-card .overlay-sub { margin: 0 0 16px 0; color: #a8b0c8; }
.overlay-card .overlay-sub strong { color: #ffd479; font-size: 1.2em; }

.final-scoreboard {
  list-style: decimal inside;
  padding: 0;
  margin: 0 0 16px 0;
  text-align: left;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.final-scoreboard li {
  padding: 6px 10px;
  color: #d0d8ee;
  font-size: 1.05em;
  display: flex;
  justify-content: space-between;
}

.final-scoreboard li:first-child { color: #ffd479; font-weight: 700; }
.final-scoreboard li .player-score { font-variant-numeric: tabular-nums; }

/* Editor */
.tool-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.tool-list button {
  padding: 8px;
  font-size: 0.85em;
  text-align: left;
}

.tool-list button.active {
  background: #4a6fd0;
  border-color: #80a8ff;
  color: #fff;
}

.custom-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.9em;
}

.custom-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  color: #d0d8ee;
}

.custom-list li .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.custom-list li button { padding: 3px 8px; font-size: 0.8em; }

/* Portrait phones/tablets: stack sidebar below the canvas as a slim strip. */
@media (max-width: 1100px) and (orientation: portrait) {
  .play-area { flex-direction: column; align-items: center; }
  .sidebar {
    width: 100%;
    max-width: 800px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }
  .sidebar-section { flex: 1 1 auto; min-width: 0; }
  #game-player-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
  }
  #game-player-list li.is-turn { padding: 2px 6px; margin: 0; }
}

/* Landscape phones/small tablets: keep sidebar on the right, but narrow it. */
@media (max-width: 1100px) and (orientation: landscape) {
  .play-area { gap: 8px; }
  .sidebar {
    width: 130px;
    gap: 8px;
  }
  .sidebar-section {
    padding: 6px 8px;
  }
  .sidebar-section h2 {
    font-size: 0.75em;
    margin: 0 0 4px 0;
    padding-bottom: 3px;
  }
  #game-player-list { font-size: 0.8em; }
  #game-player-list li { padding: 2px 0; gap: 6px; }
  #game-player-list .player-score { font-size: 0.9em; }
}

/* Phone-size: shrink chrome on all axes. */
@media (max-width: 900px) {
  body { padding: 6px; }
  h1 { font-size: 1.2em; margin-bottom: 8px; }
  .game-header {
    font-size: 0.85em;
    padding: 6px 8px;
    margin-bottom: 6px;
    gap: 6px;
  }
  .header-left, .header-right { gap: 8px; }
  #level-label {
    max-width: 35vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Short viewports (landscape phones): drop the title; minimize header. */
@media (max-height: 500px) {
  h1 { display: none; }
  body { padding: 4px; }
  .game-header {
    margin-bottom: 4px;
    padding: 3px 8px;
    font-size: 0.8em;
  }
  .game-header button { padding: 4px 10px; font-size: 0.85em; }
}

/* Editor on phones: more tool columns, narrower side rail in landscape. */
@media (max-width: 900px) and (orientation: portrait) {
  .editor-area .sidebar { max-width: 100%; }
  .tool-list { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 1100px) and (orientation: landscape) {
  .editor-area .sidebar { width: 160px; }
  .tool-list { grid-template-columns: 1fr; }
}
