:root {
  --black: #111111;
  --gray-900: #1a1a1a;
  --gray-600: #555555;
  --gray-300: #d9d9d9;
  --gray-100: #f4f4f4;
  --white: #ffffff;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--white);
  color: var(--black);
  padding: 40px 24px;
}

.card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  border: 1px solid var(--gray-300);
  border-radius: 12px;
  padding: 32px;
  background: var(--white);
  transition: max-width 0.2s ease;
}

.card.board-active {
  max-width: 960px;
}

.narrow-col {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--gray-600);
  margin: 0 0 28px;
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  border: 1px solid var(--black);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 24px;
}

.tab {
  flex: 1;
  padding: 10px 0;
  text-align: center;
  background: var(--white);
  color: var(--black);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  border-right: 1px solid var(--black);
}

.tab:last-child {
  border-right: none;
}

.tab.active {
  background: var(--black);
  color: var(--white);
}

.panel {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.panel.active {
  display: flex;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--gray-900);
}

input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--white);
  color: var(--black);
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--black);
}

input[type="text"].code-input {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 700;
}

button.primary {
  width: 100%;
  padding: 13px 0;
  border: none;
  border-radius: 8px;
  background: var(--black);
  color: var(--white);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

button.primary:hover {
  background: var(--gray-900);
}

button.primary:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

button.secondary {
  width: 100%;
  padding: 11px 0;
  border: 1px solid var(--black);
  border-radius: 8px;
  background: var(--white);
  color: var(--black);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button.secondary:hover {
  background: var(--gray-100);
}

.error {
  color: #b00020;
  font-size: 0.88rem;
  min-height: 1.2em;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.room-code {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  background: var(--white);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--gray-100);
  border-color: var(--black);
}

.room-sub {
  color: var(--gray-600);
  font-size: 0.85rem;
  margin-bottom: 24px;
}

.players {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 0.95rem;
}

.player .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-300);
  margin-right: 8px;
}

.player.connected .dot {
  background: #2e9e44;
}

.player .badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gray-600);
  letter-spacing: 0.05em;
}

.game-room {
  text-align: center;
  padding: 40px 0;
  border: 1px dashed var(--gray-300);
  border-radius: 10px;
  margin-bottom: 24px;
  font-size: 1.3rem;
  font-weight: 700;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-top: 10px;
}

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-600);
  margin: 0 0 8px;
}

.pending-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pending-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  background: var(--gray-100);
  font-size: 0.9rem;
}

.pending-actions {
  display: flex;
  gap: 6px;
}

button.mini {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

button.mini.primary {
  border: none;
  background: var(--black);
  color: var(--white);
}

button.mini.primary:hover {
  background: var(--gray-900);
}

button.mini.secondary {
  border: 1px solid var(--gray-300);
  background: var(--white);
  color: var(--black);
}

button.mini.secondary:hover {
  background: var(--gray-100);
}

#lobby-panel {
  margin-bottom: 24px;
}

.waiting-text {
  text-align: center;
  padding: 14px 0;
  color: var(--gray-600);
  font-size: 0.95rem;
  border: 1px dashed var(--gray-300);
  border-radius: 10px;
  margin: 0;
}

button.danger {
  width: 100%;
  padding: 11px 0;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  background: var(--white);
  color: #b00020;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button.danger:hover {
  background: #fdecec;
  border-color: #b00020;
}

.text-link {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 4px;
  border: none;
  background: none;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  color: var(--gray-600);
}

.text-link:hover {
  text-decoration: underline;
}

.text-link-danger {
  color: #b00020;
}

/* ---- Game board ---- */

.status-bar {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--gray-600);
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--gray-300);
}

.turn-flow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.turn-arrow {
  color: var(--gray-600);
  font-weight: 700;
}

.hex-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hex {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 80px;
  max-width: 200px;
  padding: 14px 30px;
  background: var(--white);
  border: 2px solid var(--black);
  clip-path: polygon(6% 0%, 94% 0%, 100% 50%, 94% 100%, 6% 100%, 0% 50%);
  font-weight: 700;
  font-size: 0.82rem;
  text-align: center;
  line-height: 1.25;
  word-break: break-word;
}

.hex.start-hex {
  border-width: 3px;
}

.hex.anchor-hex {
  border-style: dashed;
}

.hex.blank-hex {
  border-style: dashed;
  color: var(--gray-600);
  font-weight: 800;
}

.hex.matched {
  border-color: #2e9e44;
  box-shadow: 0 0 0 2px rgba(46, 158, 68, 0.15);
}

.hex.missed-hex {
  border-color: #b00020;
}

.connector-rect {
  background: var(--white);
  border: 2px solid var(--black);
  border-radius: 8px;
  padding: 12px 20px;
  font-weight: 600;
  font-size: 0.82rem;
  text-align: center;
  min-width: 140px;
  max-width: 280px;
}

.phase-block {
  margin-top: 18px;
}

.phase-block label {
  display: block;
  margin: 10px 0 6px;
}

.phase-block select,
.phase-block input[type='text'] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--white);
  color: var(--black);
}

.phase-block select:focus,
.phase-block input[type='text']:focus {
  outline: none;
  border-color: var(--black);
}

.direction-toggle {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  margin: 12px 0;
}

.direction-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  margin: 0;
}

.edge-picker {
  position: relative;
  margin: 10px auto 14px;
}

.edge-picker-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 2px solid var(--gray-300);
  clip-path: polygon(6% 0%, 94% 0%, 100% 50%, 94% 100%, 6% 100%, 0% 50%);
  background: var(--gray-100);
}

.edge-btn {
  position: absolute;
  border: 1px solid var(--gray-300);
  border-radius: 50%;
  background: var(--white);
  color: var(--gray-600);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edge-btn:hover {
  border-color: #5b3dd1;
  color: #5b3dd1;
}

.edge-btn.selected {
  border-color: #5b3dd1;
  background: #5b3dd1;
  color: var(--white);
}

.preview {
  font-style: italic;
  color: var(--gray-600);
  font-size: 0.85rem;
  margin: 6px 0 14px;
}

.card-choices {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.card-choice {
  flex: 1;
  min-width: 100px;
}

.guide-panel {
  margin-top: 20px;
  padding: 14px;
  border: 1px solid var(--gray-300);
  border-radius: 10px;
  background: var(--gray-100);
}

.secret-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.secret-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--white);
  border: 1px solid var(--gray-300);
}

.secret-item.revealed {
  opacity: 0.5;
  text-decoration: line-through;
}

.secret-status {
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--gray-600);
  font-weight: 700;
}

.guesser-statuses {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guesser-status {
  font-size: 0.85rem;
  color: var(--gray-600);
  padding: 6px 10px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
}

.guesser-status.done {
  color: #2e9e44;
  border-color: #2e9e44;
  font-weight: 600;
}

.outcome-banner {
  text-align: center;
  padding: 16px;
  border-radius: 10px;
  font-weight: 700;
  margin: 16px 0;
}

.outcome-banner.win {
  background: #e6f6ea;
  color: #1c7a30;
  border: 1px solid #2e9e44;
}

.outcome-banner.lose {
  background: #fdecec;
  color: #8a0016;
  border: 1px solid #b00020;
}

.badge.guide-badge {
  color: #5b3dd1;
}

.stats-block {
  margin-top: 20px;
  padding: 14px;
  border: 1px solid var(--gray-300);
  border-radius: 10px;
  background: var(--gray-100);
}

.stats-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.88rem;
  color: var(--gray-900);
}

/* ---- Chat ---- */

#chat-section {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--gray-300);
}

.chat-messages {
  height: 150px;
  overflow-y: auto;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0 10px;
  background: var(--gray-100);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-message {
  font-size: 0.85rem;
  line-height: 1.4;
  word-break: break-word;
}

.chat-author {
  font-weight: 700;
  margin-right: 6px;
}

#chat-form {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

#chat-form input[type='text'] {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--white);
  color: var(--black);
}

#chat-form input[type='text']:focus {
  outline: none;
  border-color: var(--black);
}

#chat-send-btn {
  width: auto;
  flex: none;
  padding: 0 20px;
  margin-top: 0;
}

/* ---- Network diagram ---- */

#board-stage {
  position: relative;
  margin: 24px -32px;
  height: 440px;
  overflow: hidden;
  border-top: 1px solid var(--gray-300);
  border-bottom: 1px solid var(--gray-300);
  background: radial-gradient(var(--gray-300) 1px, transparent 1px) 0 0 / 24px 24px, var(--white);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.board-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 6px;
}

.board-toolbar .icon-btn {
  width: 34px;
  height: 34px;
  background: var(--white);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

#board-viewport {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
}

#board-viewport.dragging {
  cursor: grabbing;
}

#board-world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

#board-lines {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}

.board-line {
  fill: none;
  stroke: var(--gray-300);
  stroke-width: 2;
}

.board-line.pending {
  stroke: var(--gray-600);
  stroke-dasharray: 5 5;
}

.board-node {
  position: absolute;
}

.board-node .hex,
.board-node .connector-rect {
  width: 100%;
  height: 100%;
  padding: 4px 10px;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  overflow: hidden;
}

.board-node .connector-rect {
  justify-content: space-between;
  gap: 4px;
  padding: 4px 8px;
}

.rect-mark {
  flex: none;
  font-weight: 800;
  color: var(--gray-600);
  font-size: 0.85rem;
  line-height: 1;
}

.rect-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.board-node .hex.selectable {
  cursor: pointer;
}

.board-node .hex.selectable:hover {
  border-color: #5b3dd1;
}

.board-node .hex.selected-anchor {
  border-color: #5b3dd1;
  box-shadow: 0 0 0 3px rgba(91, 61, 209, 0.2);
}

.board-node .connector-rect.pending-rect {
  border-style: dashed;
  color: var(--gray-600);
}

@media (max-width: 700px) {
  #board-stage {
    margin: 20px -32px;
    height: 340px;
  }
}
