*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-hover: #334155;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --success: #22c55e;
  --error: #ef4444;
  --self-bg: #6366f1;
  --other-bg: #334155;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.screen {
  display: none;
  width: 100%;
  max-width: 480px;
}

.screen.active {
  display: block;
}

#chat-screen.active {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  height: calc(100vh - 32px);
  max-height: 800px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
}

.logo {
  font-size: 48px;
  margin-bottom: 8px;
}

h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

h2 {
  font-size: 20px;
  font-weight: 600;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

form label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 16px;
}

form label:first-of-type {
  margin-top: 0;
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: var(--primary);
}

input[type="text"]::placeholder {
  color: #64748b;
}

.btn-primary {
  width: 100%;
  margin-top: 24px;
  padding: 13px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  margin-top: 20px;
  padding: 10px 24px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.error {
  color: var(--error);
  font-size: 13px;
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

.pulse-ring {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse-dot {
  width: 16px;
  height: 16px;
  background: var(--primary);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.8); opacity: 0.4; }
}

.room-code {
  margin: 12px 0;
  font-size: 16px;
}

.room-code strong {
  color: var(--primary-hover);
  font-size: 22px;
  letter-spacing: 2px;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}

.status-bar {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
  color: var(--success);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-info h2 {
  font-size: 18px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-voice-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-voice-toggle:hover,
.btn-voice-toggle.active {
  border-color: var(--primary);
  color: var(--primary-hover);
  background: rgba(99, 102, 241, 0.1);
}

.voice-status {
  padding: 8px 20px;
  background: rgba(99, 102, 241, 0.15);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--primary-hover);
  font-size: 13px;
  text-align: center;
}

.btn-voice {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-voice:hover:not(:disabled) {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.btn-voice.recording {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.15);
  animation: mic-pulse 1.2s ease-in-out infinite;
}

.btn-voice:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.message-body {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.message-text {
  flex: 1;
}

.btn-read {
  flex-shrink: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.6;
  padding: 0 2px;
  transition: opacity 0.2s;
}

.btn-read:hover {
  opacity: 1;
}

.badge {
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 1px;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  word-break: break-word;
}

.message.self {
  align-self: flex-end;
  background: var(--self-bg);
  border-bottom-right-radius: 4px;
}

.message.other {
  align-self: flex-start;
  background: var(--other-bg);
  border-bottom-left-radius: 4px;
}

.message .sender {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 2px;
  opacity: 0.7;
}

.message .time {
  font-size: 10px;
  opacity: 0.5;
  margin-top: 4px;
  text-align: right;
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px;
}

.message-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 16px 16px;
}

.input-area {
  position: relative;
}

.btn-emoji {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-emoji:hover,
.btn-emoji.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.emoji-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
  z-index: 10;
  overflow: hidden;
}

.emoji-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}

.emoji-tab {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s;
}

.emoji-tab:hover {
  background: var(--surface-hover);
}

.emoji-tab.active {
  background: var(--bg);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.emoji-item {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.emoji-item:hover {
  background: var(--surface-hover);
  transform: scale(1.15);
}

.message-text.emoji-only {
  font-size: 36px;
  line-height: 1.3;
  letter-spacing: 4px;
}

.message.emoji-only-msg {
  background: transparent !important;
  padding: 4px 8px;
}

@media (max-width: 480px) {
  .emoji-grid {
    grid-template-columns: repeat(7, 1fr);
    max-height: 180px;
  }

  .emoji-item {
    font-size: 20px;
  }
}

.message-form input {
  flex: 1;
}

.btn-send {
  padding: 12px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}

.btn-send:hover {
  background: var(--primary-hover);
}

@media (max-width: 480px) {
  .card {
    padding: 28px 20px;
  }

  #chat-screen.active {
    height: calc(100vh - 16px);
    max-height: none;
  }
}
