/* === Base Styles === */

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  background: #000;
  color: #00ff41;
  font-family: 'VT323', monospace;
  font-size: 18px;
}

@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}

/* === CRT Scanline Effect === */

body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  z-index: 9999;
  animation: flicker 8s infinite;
}

@keyframes flicker {
  0%, 100% { opacity: 0.95; }
  50% { opacity: 1; }
}

/* === Device Status Bar === */

.status-bar {
  height: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
  font-size: 14px;
  color: #008f11;
  border-bottom: 1px solid #0a0a0a;
  box-sizing: border-box;
}

/* === Screen Containers === */

.screen {
  position: absolute;
  top: 30px;
  left: 0;
  width: 100%;
  height: calc(100% - 90px - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  display: none;
  padding: 15px;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 0.2s ease-in;
}

.screen.active {
  display: block;
  opacity: 1;
  animation: screenBoot 0.3s ease-out;
}

@keyframes screenBoot {
  0% { opacity: 0; transform: scale(0.98); }
  100% { opacity: 1; transform: scale(1); }
}

#home-screen {
  display: none;
  flex-direction: column;
}

#home-screen.active {
  display: flex;
}

/* === Bottom Navigation Bar === */

.nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: #0a0a0a;
  border-top: 1px solid #008f11;
  z-index: 100;
  box-sizing: border-box;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #008f11;
  font-family: 'VT323', monospace;
  font-size: 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  gap: 2px;
}

.nav-btn .nav-icon {
  font-size: 20px;
}

.nav-btn.active {
  color: #ffb000;
}

.nav-btn:hover {
  color: #00ff41;
}

/* === Notification Badges === */

.badge {
  position: absolute;
  top: 2px;
  right: 25%;
  min-width: 16px;
  height: 16px;
  background: #ff0000;
  color: #000;
  border-radius: 50%;
  font-size: 12px;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 16px;
  text-align: center;
}

.badge.visible {
  display: flex;
}

/* === Toast Notifications === */

.toast-container {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.toast {
  background: #0a0a0a;
  border: 1px solid #ffb000;
  color: #ffb000;
  padding: 10px 20px;
  font-family: 'VT323', monospace;
  font-size: 16px;
  margin-bottom: 5px;
  animation: toastSlide 3s forwards;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 0 15px rgba(255, 176, 0, 0.2);
}

@keyframes toastSlide {
  0% { opacity: 0; transform: translateY(-10px); }
  8% { opacity: 1; transform: translateY(0); }
  85% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

/* === Scrollbar Styling === */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #0a0a0a;
}

::-webkit-scrollbar-thumb {
  background: #008f11;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #00ff41;
}

/* === Home Screen === */

.device-title {
  text-align: center;
  padding: 10px 0 5px;
  color: #008f11;
  font-size: 24px;
  letter-spacing: 6px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.app-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 10px 20px;
  max-width: 350px;
  margin: 0 auto;
  flex-shrink: 0;
}

.app-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  border: 1px solid #008f11;
  cursor: pointer;
  transition: all 0.2s;
}

.app-icon:hover {
  border-color: #00ff41;
  background: rgba(0, 255, 65, 0.05);
}

.app-icon.offline {
  opacity: 0.4;
  cursor: not-allowed;
}

.app-icon.offline:hover {
  border-color: #008f11;
  background: transparent;
}

.app-icon .icon {
  font-size: 32px;
  margin-bottom: 8px;
}

.app-icon .label {
  font-size: 16px;
  color: #00ff41;
  letter-spacing: 2px;
}

.app-icon .sublabel {
  font-size: 14px;
  color: #008f11;
}

.home-notifications {
  padding: 10px 20px;
  margin: 5px 20px;
  border: 1px solid #0a0a0a;
  flex-shrink: 0;
}

.home-notification-item {
  color: #008f11;
  font-size: 16px;
  padding: 4px 0;
}

.home-notification-item::before {
  content: '● ';
  color: #ffb000;
}

.device-footer {
  text-align: center;
  padding: 15px 10px;
  margin-top: auto;
  font-size: 14px;
  color: #008f11;
}

.device-footer .status {
  color: #ff0000;
}

.device-footer .signal {
  color: #ffb000;
  animation: blink 1.5s infinite;
}

.reset-btn {
  margin-top: 8px;
  color: #333;
  font-size: 12px;
  cursor: pointer;
  letter-spacing: 1px;
}

.reset-btn:hover {
  color: #ff0000;
}

/* === Audio Display === */

#audio-display {
  position: fixed;
  top: 5px;
  right: 15px;
  font-family: 'VT323', monospace;
  font-size: 12px;
  cursor: pointer;
  z-index: 9998;
  letter-spacing: 1px;
  user-select: none;
}

#audio-display.audio-on {
  color: #008f11;
}

#audio-display.audio-off {
  color: #333;
}

#audio-display.audio-muted {
  color: #ff0000;
}

/* === Keyframe Animations === */

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes blink {
  50% { opacity: 0; }
}

@keyframes glitch {
  0% { transform: translate(0); }
  20% { transform: translate(-2px, 1px); }
  40% { transform: translate(1px, -1px); }
  60% { transform: translate(-1px, 2px); }
  80% { transform: translate(2px, -2px); }
  100% { transform: translate(0); }
}

body.glitching .screen.active {
  animation: screenGlitch 0.3s steps(4);
}

@keyframes screenGlitch {
  0% { transform: translate(0); filter: none; }
  25% { transform: translate(-3px, 1px) skewX(1deg); filter: hue-rotate(90deg); }
  50% { transform: translate(2px, -1px) skewX(-0.5deg); filter: hue-rotate(180deg) saturate(2); }
  75% { transform: translate(-1px, 2px); filter: hue-rotate(270deg); }
  100% { transform: translate(0); filter: none; }
}

/* === Incoming Call === */

#call-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 9990;
  display: flex;
  align-items: center;
  justify-content: center;
}

#call-overlay.ringing {
  animation: callRing 0.5s ease-in-out infinite alternate;
}

@keyframes callRing {
  0% { background: rgba(0, 0, 0, 0.95); }
  100% { background: rgba(0, 30, 0, 0.95); }
}

.call-content {
  text-align: center;
  padding: 40px;
}

.call-icon {
  font-size: 48px;
  margin-bottom: 20px;
  animation: callPulse 1s infinite;
}

.call-icon.active {
  animation: none;
}

@keyframes callPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.call-label {
  color: #00ff41;
  font-size: 16px;
  letter-spacing: 4px;
  margin-bottom: 10px;
  animation: blink 1s infinite;
}

.call-agent {
  color: #ffb000;
  font-size: 28px;
  letter-spacing: 3px;
  margin-bottom: 15px;
}

.call-signal {
  color: #008f11;
  font-size: 14px;
  margin-bottom: 30px;
  letter-spacing: 2px;
}

.call-buttons {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.call-btn {
  padding: 12px 30px;
  font-family: 'VT323', monospace;
  font-size: 18px;
  border: 1px solid;
  background: transparent;
  cursor: pointer;
  letter-spacing: 2px;
}

.call-btn.accept {
  color: #00ff41;
  border-color: #00ff41;
}

.call-btn.accept:hover {
  background: rgba(0, 255, 65, 0.1);
}

.call-btn.reject {
  color: #ff0000;
  border-color: #ff0000;
}

.call-btn.reject:hover {
  background: rgba(255, 0, 0, 0.1);
}

.call-timer {
  color: #008f11;
  font-size: 20px;
  margin: 15px 0;
  letter-spacing: 3px;
}

.call-wave {
  color: #00ff41;
  font-size: 24px;
  letter-spacing: 2px;
  animation: waveAnim 0.8s ease-in-out infinite alternate;
}

@keyframes waveAnim {
  0% { opacity: 0.4; letter-spacing: 1px; }
  100% { opacity: 1; letter-spacing: 4px; }
}

.call-ended {
  color: #ff0000;
  font-size: 20px;
  letter-spacing: 4px;
  padding: 40px;
}

/* Demon call */
#call-overlay.demon-call {
  background: rgba(30, 0, 0, 0.97);
}

#call-overlay.demon-call.ringing {
  animation: demonRing 0.3s ease-in-out infinite alternate;
}

@keyframes demonRing {
  0% { background: rgba(30, 0, 0, 0.97); }
  100% { background: rgba(60, 0, 0, 0.97); }
}

#call-overlay.demon-end {
  animation: demonGlitch 0.2s steps(3) infinite;
}

@keyframes demonGlitch {
  0% { filter: none; }
  33% { filter: hue-rotate(60deg) saturate(3); transform: skewX(2deg); }
  66% { filter: hue-rotate(-60deg) invert(0.1); transform: skewX(-1deg); }
  100% { filter: none; }
}

/* === Responsive === */

/* Small phones */
@media (max-width: 360px) {
  html, body { font-size: 16px; }
  .device-title { font-size: 22px; letter-spacing: 4px; }
  .app-grid { gap: 10px; padding: 15px; max-width: 100%; }
  .app-icon { padding: 15px 8px; }
  .app-icon .icon { font-size: 26px; }
  .app-icon .label { font-size: 14px; }
  .nav-btn .nav-icon { font-size: 18px; }
  .nav-btn { font-size: 10px; }
  .nav-bar { height: 50px; }
  .screen { height: calc(100% - 80px); }
  .device-footer { bottom: 55px; font-size: 12px; }
  .toast { font-size: 14px; padding: 6px 12px; }
}

/* Standard phones (360-480) */
@media (min-width: 361px) and (max-width: 480px) {
  .app-grid { max-width: 100%; }
}

/* Large phones / small tablets (481-768) */
@media (min-width: 481px) and (max-width: 768px) {
  .app-grid { max-width: 400px; }
  .app-icon .icon { font-size: 36px; }
}

/* Tablets and desktop - device frame */
@media (min-width: 769px) {
  body {
    display: block;
  }

  .status-bar {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 480px;
    max-width: 480px;
    border-left: 1px solid #0a0a0a;
    border-right: 1px solid #0a0a0a;
  }

  .screen {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid #0a0a0a;
    border-right: 1px solid #0a0a0a;
  }

  .nav-bar {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid #0a0a0a;
    border-right: 1px solid #0a0a0a;
  }

  .chat-input-area {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
  }

  .app-grid { max-width: 400px; }

  #audio-display {
    right: calc(50% - 230px);
  }
}
