* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Arial', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  padding-top: env(safe-area-inset-top);
}

:root {
  --prompter-bg: #000000;
  --prompter-color: #ffffff;
  --prompter-font-size: 2.2rem;
  --prompter-placeholder: rgba(255, 255, 255, 0.35);
}

.screen {
  display: none;
  width: 100vw;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#join-screen {
  justify-content: center;
  align-items: center;
  padding: 20px;
  padding-top: max(40px, env(safe-area-inset-top));
  position: relative;
}

.back-btn-join {
  position: absolute;
  top: max(20px, calc(env(safe-area-inset-top) + 10px));
  left: 20px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid white;
  border-radius: 50px;
  color: white;
  text-decoration: none;
  font-size: 1em;
  transition: all 0.3s ease;
  z-index: 100;
}

.back-btn-join:hover {
  background: white;
  color: #667eea;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.container {
  text-align: center;
  color: white;
  width: 100%;
  max-width: 400px;
  padding: 40px 30px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.container h1 {
  font-size: 4em;
  margin-bottom: 20px;
}

.container h2 {
  font-size: 1.8em;
  margin-bottom: 15px;
}

.container p {
  font-size: 1.1em;
  margin-bottom: 20px;
  opacity: 0.9;
}

#room-code-input {
  width: 100%;
  padding: 15px 20px;
  font-size: 1.5em;
  text-align: center;
  border: 2px solid white;
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  margin-bottom: 20px;
  outline: none;
}

#room-code-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: normal;
}

#join-btn {
  width: 100%;
  padding: 15px 30px;
  font-size: 1.2em;
  background: white;
  color: #667eea;
  border: none;
  border-radius: 50px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
}

#join-btn:active {
  transform: scale(0.95);
}

.error {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.2);
  padding: 10px;
  border-radius: 10px;
  margin-top: 15px;
  display: none;
  font-size: 0.9em;
}

.error.show {
  display: block;
}

#control-screen {
  justify-content: flex-start;
  padding: 0;
  padding-top: env(safe-area-inset-top);
}

.control-header {
  background: rgba(0, 0, 0, 0.3);
  padding: max(25px, calc(env(safe-area-inset-top) + 15px)) 20px 15px 20px;
  color: white;
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex-shrink: 0;
}

.header-buttons {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.exit-btn,
.calibrate-btn-top {
  flex: 1;
  padding: 10px 16px;
  font-size: 0.95em;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid white;
  border-radius: 15px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.exit-btn:active,
.calibrate-btn-top:active {
  transform: scale(0.95);
}

.room-code-display {
  text-align: center;
  font-size: 2em;
  font-weight: bold;
  letter-spacing: 0.15em;
  padding: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
}

.permission-btn {
  padding: 12px 24px;
  font-size: 1em;
  background: rgba(255, 215, 0, 0.3);
  color: white;
  border: 2px solid #ffd700;
  border-radius: 15px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(255, 215, 0, 0);
  }
}

.color-toggle-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.3s ease;
  background: linear-gradient(135deg, #0066ff 0%, #004db3 100%);
  min-height: 0;
}

.color-toggle-area.red {
  background: linear-gradient(135deg, #ff0000 0%, #b30000 100%);
}

.color-toggle-area.weapon-mode {
  background: linear-gradient(135deg, #c0c0c0 0%, #808080 100%);
}

.color-toggle-area.weapon-mode.shield {
  background: linear-gradient(135deg, #8b4513 0%, #5c2e0a 100%);
}

.prompter-container {
  display: none;
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
}

#prompter-textarea {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  padding: 40px 24px 80px;
  font-size: var(--prompter-font-size, 2.2rem);
  background: var(--prompter-bg, #000);
  color: var(--prompter-color, #fff);
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-y: auto;
  font-family: inherit;
  touch-action: auto;
}

#prompter-textarea.prompter-locked {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  caret-color: transparent;
}

#prompter-textarea::placeholder {
  color: var(--prompter-placeholder, rgba(255, 255, 255, 0.35));
}

.scroll-top-btn {
  position: absolute;
  right: 20px;
  bottom: 20px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 1.5em;
  display: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.scroll-top-btn.visible {
  display: flex;
}

.fullscreen-btn {
  position: absolute;
  right: 20px;
  bottom: 80px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 1.4em;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.fullscreen-btn.visible {
  display: flex;
}

body.prompter-mode .scroll-top-btn {
  position: fixed;
  right: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
}

body.prompter-mode .fullscreen-btn {
  position: fixed;
  right: 20px;
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 64px));
}

body.prompter-mode {
  background: #000;
}

body.prompter-mode #control-screen {
  padding: 0;
}

body.prompter-mode .control-header,
body.prompter-mode #color-toggle-area {
  display: none;
}

body.prompter-mode #prompter-container {
  display: flex;
}

.color-label {
  font-size: 5em;
  font-weight: bold;
  color: white;
  text-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  user-select: none;
}

@media (max-height: 700px) {
  .color-label {
    font-size: 4em;
  }
  
  .room-code-display {
    font-size: 1.8em;
    padding: 6px;
  }
}

@media (max-height: 600px) {
  .color-label {
    font-size: 3.5em;
  }
  
  .control-header {
    gap: 8px;
    padding: max(20px, calc(env(safe-area-inset-top) + 10px)) 15px 10px 15px;
  }
  
  .exit-btn,
  .calibrate-btn-top {
    padding: 8px 12px;
    font-size: 0.9em;
  }
  
  .room-code-display {
    font-size: 1.5em;
    padding: 5px;
  }
}
