/* Mobile-First Portrait Design */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-touch-callout: none;
}

body, html {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: #2a2a2a;
  color: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

button, input, select, textarea {
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
  border-radius: 0;
}

#app-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

/* Screen visibility */
.screen {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: #2a2a2a;
  transition: transform 0.3s ease-in-out;
  transform: translateX(0);
}

.screen.hidden {
  transform: translateX(100%);
  pointer-events: none;
}

/* Header */
.top-header {
  background-color: #1a2a40;
  padding: 16px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  z-index: 10;
}

.top-header h1 {
  font-size: 1.2rem;
  color: #fff;
}

/* Form Controls */
.capsule-input, .capsule-button {
  width: 100%;
  border-radius: 9999px;
  border: 1px solid #4a4a4a;
  padding: 14px 20px;
  font-size: 1rem;
  outline: none;
  background-color: #ffffff;
  color: #333333;
  margin-bottom: 12px;
}

input.capsule-input {
  user-select: auto;
  -webkit-user-select: auto;
}

.capsule-button {
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  transition: transform 0.1s;
  text-align: center;
}

.capsule-button:active {
  transform: scale(0.98);
}

/* Specific UI Elements */
.content-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.sidebar {
  width: 35%;
  flex-shrink: 0;
  background-color: #1f1f1f;
  border-right: 1px solid #3a3a3a;
  display: flex;
  flex-direction: column;
  padding: 10px;
  transition: width 0.3s ease-in-out;
}

.mobile-back-btn {
  display: none;
  width: 100%;
  background: none;
  border: none;
  color: #28a745;
  font-size: 1rem;
  padding: 10px 0;
  margin-bottom: 10px;
  font-weight: bold;
  cursor: pointer;
  text-align: right;
}

@media (max-width: 768px) {
  .sidebar.mobile-expanded {
    width: 85%;
  }
  .sidebar.mobile-expanded .mobile-back-btn {
    display: block;
  }
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  font-size: 0.85rem;
  margin-bottom: 10px;
  color: #ccc;
  word-wrap: break-word;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-input-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  min-height: 46px;
  max-height: 120px;
  border-radius: 20px;
  border: 1px solid #4a4a4a;
  padding: 12px 16px;
  font-size: 1rem;
  outline: none;
  background-color: #ffffff;
  color: #333333;
  resize: none;
  font-family: inherit;
  overflow-y: auto;
}

.chat-send-btn {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: none;
  background-color: #28a745;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s, background-color 0.1s;
}

.chat-send-btn:active {
  transform: scale(0.95);
  background-color: #218838;
}

.chat-msg {
  background: #333;
  padding: 6px;
  border-radius: 6px;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow-y: auto;
}

.room-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.room-card {
  background-color: #3a3a3a;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.room-card-title {
  font-weight: bold;
  font-size: 1.1rem;
}

.room-card-status {
  font-size: 0.9rem;
  color: #aaa;
}

.join-button {
  background-color: #28a745;
  color: white;
  border: none;
  margin-bottom: 0;
  padding: 10px;
}



/* Footer */
.app-footer {
  background-color: #1a1a1a;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #dc3545; /* disconnected */
}

.status-dot.connected {
  background-color: #28a745;
}

/* Screen B (Setup) */
.setup-container {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center; /* lower two-thirds cluster approximation */
  margin-top: auto;
  margin-bottom: 20px;
}

.small-hint {
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 16px;
  text-align: center;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: #ccc;
}

.action-group {
  display: flex;
  gap: 12px;
}

/* Screen C (Game) */
.game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.game-status {
  font-size: 1.2rem;
  margin-bottom: 20px;
  text-align: center;
  font-weight: bold;
}

.tic-tac-toe-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  grid-gap: 10px;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  margin-bottom: 30px;
}

.tic-tac-toe-board.disabled {
  pointer-events: none;
  opacity: 0.5;
}

.cell {
  background-color: #3a3a3a;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.1s;
}

.cell:active {
  background-color: #4a4a4a;
}

/* Overlays */
.overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background-color: #2a2a2a;
  padding: 24px;
  border-radius: 16px;
  text-align: center;
  border: 1px solid #444;
}

/* iOS Bottom Sheet */
.bottom-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: #1a1a1a;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding: 24px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.5);
  transform: translateY(0);
  transition: transform 0.3s ease-out;
  z-index: 200;
}

.bottom-sheet.hidden {
  transform: translateY(100%);
}

.sheet-content h3 {
  margin-bottom: 12px;
}

.sheet-content p {
  margin-bottom: 20px;
  line-height: 1.4;
  color: #ccc;
}

.share-icon {
  display: inline-block;
  padding: 0 4px;
}
