* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --sky: #28B5F5;
  --navy: #1B4E9B;
  --body-bg: #F3EEF0;
  --text: #1A1A1A;
  --input-border: #B8D4F0;
  --rec-red: #E53935;
  --white: #fff;
}

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--sky);
  color: var(--text);
  overscroll-behavior: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input,
textarea,
select,
.field-input,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}

/* Legacy class hooks — inherit from body; listed for clarity */
.login-header,
.login-logo-box,
.login-version,
.login-btn,
.field-icon,
.error-badge,
.error-tooltip,
.room-header,
.settings-btn,
.user-line,
.brand-card,
.agent-name,
.tool-row,
.circle-btn,
.status-text,
.mic-outer,
.mic-ring3,
.mic-ring2,
.mic-ring1,
.mic-emoji,
.room-footer,
.footer-left,
.footer-right,
.toast,
.settings-backdrop,
.settings-menu,
.settings-menu button,
.login-form,
.field-block,
.input-row,
.tooltip-box,
.tooltip-arrow {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.hidden { display: none !important; }

.screen {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
}

.screen.active { display: flex; }

/* ---------- Login ---------- */
#login-screen.active {
  background: var(--sky);
}

.login-header {
  flex: 0 0 36%;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: env(safe-area-inset-top, 0);
}

.login-logo-box {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 14px;
}

.login-logo-img {
  width: 56px;
  height: 56px;
  object-fit: contain;
}

.login-version {
  color: var(--white);
  font-size: 16px;
  font-weight: 500;
}

.login-form {
  flex: 1;
  background: var(--white);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 32px 28px calc(20px + env(safe-area-inset-bottom, 0));
}

.field-block {
  margin-bottom: 4px;
  position: relative;
  z-index: 1;
}

.input-row {
  display: flex;
  align-items: center;
  height: 52px;
  border: 1.5px solid var(--input-border);
  border-radius: 26px;
  padding: 0 14px;
  margin-bottom: 4px;
  background: var(--white);
}

.field-icon {
  width: 28px;
  text-align: center;
  font-size: 18px;
  flex-shrink: 0;
}

.field-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  min-width: 0;
  padding: 0 8px;
}

.field-input::placeholder { color: #888; font-weight: 500; }

.error-badge {
  width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--rec-red);
  color: var(--white);
  font-weight: 800;
  font-size: 14px;
  line-height: 22px;
  text-align: center;
  flex-shrink: 0;
}

.error-tooltip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-bottom: 12px;
  z-index: 20;
}

.tooltip-arrow {
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 10px solid var(--rec-red);
  margin-right: 28px;
}

#error-tooltip-pass .tooltip-arrow { margin-right: 14px; }

.tooltip-box {
  width: 100%;
  background: #ECEFF1;
  border-top: 3px solid var(--rec-red);
  border-radius: 4px;
  padding: 12px 14px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.14);
  color: #424242;
  font-size: 15px;
  line-height: 22px;
}

.login-btn {
  width: 100%;
  height: 52px;
  margin-top: 8px;
  border: none;
  border-radius: 26px;
  background: var(--navy);
  color: var(--white);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-btn:disabled { opacity: 0.7; cursor: wait; }

.login-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- User room ---------- */
#room-screen {
  background: var(--body-bg);
}

.room-header {
  background: var(--sky);
  text-align: center;
  padding: calc(12px + env(safe-area-inset-top, 0)) 16px 18px;
  position: relative;
}

.settings-btn {
  position: absolute;
  top: calc(22px + env(safe-area-inset-top, 0));
  right: 16px;
  border: none;
  background: none;
  font-size: 26px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.user-line {
  font-size: 16px;
  font-weight: 600;
  margin: 8px 0 10px;
}

.brand-card {
  width: 120px;
  height: 150px;
  margin: 0 auto 10px;
  border-radius: 6px;
  overflow: hidden;
  background: #111;
}

.brand-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.agent-name {
  color: var(--white);
  font-size: clamp(24px, 7vw, 34px);
  font-weight: 800;
  letter-spacing: 1px;
}

.room-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 18px;
}

.tool-row {
  display: flex;
  gap: 18px;
  justify-content: center;
  padding: 0 16px;
}

.circle-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--white);
  box-shadow: 0 2px 4px rgba(0,0,0,0.12);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.circle-btn.rec-btn {
  font-size: 11px;
  font-weight: 800;
  color: var(--text);
}

.circle-btn.power-btn {
  color: var(--rec-red);
  font-size: 22px;
}

.circle-btn.lock-btn:disabled {
  opacity: 1;
  cursor: default;
}

.status-text {
  margin-top: 16px;
  font-size: 18px;
  font-weight: 700;
  color: #111;
}

.mic-outer {
  margin-top: 24px;
  touch-action: none;
  cursor: pointer;
}

.mic-ring3 {
  width: min(220px, 72vw);
  height: min(220px, 72vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #2E2E2E;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-ring2 {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  background: #3D3D3D;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-ring1 {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  background: #757575;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.mic-ring1.live { background: #5C9E54; }

.mic-emoji { font-size: clamp(40px, 12vw, 64px); line-height: 1; }

.room-footer {
  background: var(--sky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px calc(10px + env(safe-area-inset-bottom, 0));
  gap: 8px;
}

.footer-left, .footer-right {
  color: var(--white);
  font-size: 14px;
  font-weight: 600;
}

.footer-left { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.footer-right { font-weight: 800; white-space: nowrap; }

.toast {
  position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom, 0));
  left: 20px;
  right: 20px;
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 14px;
  border-radius: 10px;
  text-align: center;
  font-size: 14px;
  z-index: 30;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 40;
}

.settings-menu {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.settings-menu button {
  display: block;
  width: 100%;
  border: none;
  background: #fff;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 1px solid #eee;
}

.settings-menu button:last-child { border-bottom: none; color: #666; }

.settings-menu #btn-logout-menu { color: var(--rec-red); }

/* Narrow phones */
@media (max-width: 360px) {
  .tool-row { gap: 10px; }
  .circle-btn {
    width: 52px;
    height: 52px;
    font-size: 22px;
  }
  .login-form {
    padding-left: 20px;
    padding-right: 20px;
  }
  .brand-card {
    width: 100px;
    height: 125px;
  }
}

/* Short screens (small height / landscape) */
@media (max-height: 720px) {
  .login-header {
    flex: 0 0 auto;
    min-height: 160px;
    padding-bottom: 8px;
  }

  .login-form {
    padding-top: 24px;
  }

  .brand-card {
    width: 96px;
    height: 120px;
  }

  .user-line {
    margin: 4px 0 8px;
  }

  .room-body {
    padding-top: 10px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mic-outer { margin-top: 12px; }
  .status-text { margin-top: 10px; font-size: 16px; }
}

/* Tablets / wider screens — keep phone-like layout centered */
@media (min-width: 520px) {
  .login-form,
  .room-header,
  .room-body,
  .room-footer {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }

  #room-screen.active {
    align-items: center;
  }

  #room-screen.active .room-header,
  #room-screen.active .room-footer {
    width: 100%;
    max-width: 480px;
  }
}
