* { box-sizing: border-box; margin: 0; padding: 0; }

html,
body {
  width: 100%;
  height: 100%;
}

body {
  background: #09091d;
  color: white;
  font-family: 'Nunito', Arial, sans-serif;
  font-size: 20px;
  display: flex;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#app {
  position: relative;
  width: 98%;
  height: 97vh;
  margin: auto;
  border-radius: 10px;
  overflow: hidden;
}

.bg {
  position: absolute;
  inset: 0;
  background: url('https://images.alphacoders.com/122/thumb-1920-1226538.jpg') center/cover;
  opacity: 100%;
  z-index: 0;
}

.app-inner {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  z-index: 1;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(210, 179, 241, 0.15);
  gap: 12px;
  flex-shrink: 0;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: #b3e1f1;
  letter-spacing: 0.03em;
}

.header-sub {
  font-size: 12px;
  font-weight: 300;
  color: rgba(179, 225, 241, 0.6);
}

.header-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.hbtn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(210, 179, 241, 0.2);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  color: #b3e1f1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.hbtn:hover,
.hbtn.active {
  background: rgba(179, 225, 241, 0.15);
  border-color: #b3e1f1;
}

.hbtn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panels {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.panel {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  min-height: 0;
}

.panel.active {
  display: flex;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(179, 225, 241, 0.2) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 75%;
}

.msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg.ai {
  align-self: flex-start;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.msg.ai .avatar {
  background: rgba(179, 225, 241, 0.15);
  color: #b3e1f1;
  border: 1px solid rgba(179, 225, 241, 0.3);
}

.msg.user .avatar {
  background: rgba(150, 120, 200, 0.2);
  color: #d2b3f1;
  border: 1px solid rgba(210, 179, 241, 0.3);
}

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
}

.msg.ai .bubble {
  background: rgba(179, 225, 241, 0.08);
  border: 1px solid rgba(179, 225, 241, 0.12);
  border-bottom-left-radius: 4px;
  color: #e8f5fb;
}

.msg.user .bubble {
  background: rgba(210, 179, 241, 0.1);
  border: 1px solid rgba(210, 179, 241, 0.18);
  border-bottom-right-radius: 4px;
  color: #f0e8fb;
}

.typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 4px 2px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(179, 225, 241, 0.4);
  animation: dot 1.2s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.9);
  }
  40% {
    opacity: 1;
    transform: scale(1.1);
  }
}

.chat-input-area {
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.4);
  border-top: 1px solid rgba(210, 179, 241, 0.1);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(210, 179, 241, 0.2);
  border-radius: 12px;
  color: white;
  font-family: inherit;
  font-size: 16px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.15s;
  scrollbar-width: thin;
}

.chat-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.chat-input:focus {
  border-color: rgba(179, 225, 241, 0.4);
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(179, 225, 241, 0.25);
  background: rgba(179, 225, 241, 0.1);
  color: #b3e1f1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.send-btn:hover {
  background: rgba(179, 225, 241, 0.2);
}

.send-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.memory-panel-inner {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(179, 225, 241, 0.2) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.memory-header {
  margin-bottom: 18px;
}

.memory-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: #b3e1f1;
}

.memory-header p {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 3px;
}

.memory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.memory-card {
  background: rgba(179, 225, 241, 0.04);
  border: 1px solid rgba(179, 225, 241, 0.12);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.memory-card:hover {
  background: rgba(179, 225, 241, 0.1);
  border-color: rgba(179, 225, 241, 0.3);
}

.memory-card-id {
  font-size: 11px;
  color: rgba(179, 225, 241, 0.5);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.memory-card-preview {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.memory-card-time {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  margin-top: 4px;
}

.memory-empty {
  text-align: center;
  color: rgba(255, 255, 255, 0.3);
  font-size: 14px;
  padding: 60px 20px;
}

.settings-inner {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(179, 225, 241, 0.2) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.settings-section {
  margin-bottom: 28px;
}

.settings-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(179, 225, 241, 0.5);
  text-transform: uppercase;
  margin-bottom: 12px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(210, 179, 241, 0.1);
  border-radius: 10px;
  margin-bottom: 8px;
  gap: 12px;
}

.setting-row-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.setting-row-label {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.85);
}

.setting-row-sub {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.35);
}

.setting-row select {
  background: rgba(179, 225, 241, 0.08);
  border: 1px solid rgba(179, 225, 241, 0.2);
  color: white;
  border-radius: 8px;
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
  font-family: inherit;
  cursor: pointer;
  flex-shrink: 0;
}

.setting-row select option {
  background: #111;
}

.setting-row input[type="range"] {
  width: 120px;
  cursor: pointer;
  accent-color: #b3e1f1;
  flex-shrink: 0;
}

.speed-val {
  font-size: 13px;
  color: #b3e1f1;
  min-width: 64px;
  text-align: right;
}

.settings-save {
  margin-top: 8px;
  width: 100%;
  padding: 11px;
  border-radius: 10px;
  border: 1px solid rgba(179, 225, 241, 0.3);
  background: rgba(179, 225, 241, 0.1);
  color: #b3e1f1;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.settings-save:hover {
  background: rgba(179, 225, 241, 0.2);
}

#font-preview {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 8px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.07);
}

@media (max-width: 768px) {
  body {
    font-size: 16px;
  }

  #app {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .header {
    padding: 10px 12px;
    gap: 8px;
  }

  .header-title {
    font-size: 16px;
  }

  .header-sub {
    font-size: 11px;
  }

  .header-buttons {
    gap: 6px;
  }

  .hbtn {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  .hbtn svg {
    width: 18px;
    height: 18px;
  }

  .chat-messages {
    padding: 12px;
    gap: 10px;
  }

  .msg {
    max-width: 88%;
  }

  .avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  .bubble {
    font-size: 13px;
    padding: 9px 12px;
  }

  .chat-input-area {
    padding: 10px 12px;
    gap: 8px;
  }

  .chat-input {
    min-height: 40px;
    max-height: 100px;
    padding: 10px 12px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
  }

  .memory-panel-inner,
  .settings-inner {
    padding: 12px;
  }

  .memory-grid {
    grid-template-columns: 1fr;
  }

  .setting-row {
    padding: 10px 12px;
    flex-wrap: wrap;
  }

  .setting-row select,
  .setting-row input[type="range"] {
    width: 100%;
  }

  .speed-val {
    width: 100%;
    text-align: left;
  }
}
