/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* === TOKENS — dark (default) === */
:root {
  --bg:           #0e0a08;
  --surface:      #1a0f0c;
  --elevated:     #251510;
  --border:       #3a2018;
  --accent:       #ff4500;
  --accent-hover: #cc3700;
  --text:         #f2e8e4;
  --muted:        #9a7060;
  --danger:       #ff2244;
  --online:       #ff8c00;
  --me-bg:        #ffb3a0;
  --me-text:      #3d1008;
  --them-bg:      #251510;
  --radius:       14px;
  --shadow:       0 8px 32px rgba(0,0,0,0.65);
  --chat-bg:      #100906;
  --toggle-icon:  '☀️';
}

/* === TOKENS — light === */
[data-theme="light"] {
  --bg:           #fdf3ef;
  --surface:      #fff8f5;
  --elevated:     #ffeee8;
  --border:       #f0cfc4;
  --text:         #2a1008;
  --muted:        #9a6050;
  --them-bg:      #f0ddd8;
  --shadow:       0 8px 32px rgba(180,80,40,0.15);
  --chat-bg:      #fdf0eb;
  --toggle-icon:  '🌙';
}

[data-theme="light"] body {
  background: var(--bg);
}

/* Light mode: chat pattern lighter */
[data-theme="light"] .msg-list {
  background-color: var(--chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cpath d='M32 23 L41 32 L32 41 L23 32 Z' fill='none' stroke='%23ff4500' stroke-opacity='0.12' stroke-width='1.2'/%3E%3Ccircle cx='0' cy='0' r='2.2' fill='%23ff5500' fill-opacity='0.1'/%3E%3Ccircle cx='64' cy='64' r='2.2' fill='%23ff5500' fill-opacity='0.1'/%3E%3Ccircle cx='64' cy='0' r='2.2' fill='%23ff5500' fill-opacity='0.1'/%3E%3Ccircle cx='0' cy='64' r='2.2' fill='%23ff5500' fill-opacity='0.1'/%3E%3Ccircle cx='32' cy='32' r='1.2' fill='%23ff6a00' fill-opacity='0.13'/%3E%3C/svg%3E");
}

[data-theme="light"] .modal-backdrop {
  background: rgba(80,20,0,0.5);
}


/* === BASE === */
html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* === APP CONTAINER === */
#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* Ad panels: hidden on mobile */
.ad-panel { display: none; }

/* === SCREENS === */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.screen.hidden { display: none !important; }

/* =====================
   HOME
   ===================== */

/* Override .screen defaults for home to allow flex layout with scrollable topics */
#screen-home {
  justify-content: flex-start;
  padding: 0;
  align-items: stretch;
  overflow: hidden;
}

.home-top {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 52px 24px 20px;
}

/* Topic-aware home toggle — positions within home-top */
#screen-home .theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
}

.home-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

/* ---- Topic input ---- */
.topic-input-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.topic-input {
  width: 100%;
  background: var(--elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s;
  caret-color: var(--accent);
}
.topic-input::placeholder { color: var(--muted); }
.topic-input:focus { border-color: var(--accent); }

.topic-hint {
  color: var(--muted);
  font-size: 0.76rem;
}

/* ---- Mövzular section ---- */
.topics-section {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

.topics-label {
  padding: 12px 0 10px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.topics-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: flex-start;
}

.topic-chip-btn {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 7px 16px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.topic-chip-btn:hover  { background: var(--border); border-color: var(--accent); color: var(--accent); }
.topic-chip-btn:active { transform: scale(0.95); }

.topics-empty {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 14px 0;
}

.brand-icon {
  width: 72px;
  height: 72px;
  filter: drop-shadow(0 4px 20px rgba(255,69,0,0.5));
}

.brand h1 {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ff9a3c, #ff4500 50%, #ff2244);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-top: 10px;
}

.brand-sub {
  color: var(--muted);
  margin-top: 6px;
  font-size: 0.95rem;
}

.online-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 9px 20px;
  font-size: 0.9rem;
  color: var(--muted);
}

.online-badge strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* pulse dot */
.dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  background: var(--online);
  border-radius: 50%;
  animation: pulse-dot 2.2s infinite;
}

@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(255,140,0,.6); }
  70%  { box-shadow: 0 0 0 8px rgba(255,140,0,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,140,0,0); }
}

.disclaimer {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

/* =====================
   BUTTONS
   ===================== */
.btn-primary {
  display: block;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 15px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.2px;
  transition: background 0.18s, transform 0.12s, box-shadow 0.18s;
  box-shadow: 0 4px 20px rgba(255,69,0,0.4);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn-primary:hover  { background: var(--accent-hover); box-shadow: 0 4px 24px rgba(255,69,0,0.5); }
.btn-primary:active { transform: scale(0.97); }

.btn-ghost {
  display: block;
  width: 100%;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 24px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn-ghost:hover  { background: var(--surface); color: var(--text); }
.btn-ghost.mt     { margin-top: 8px; }

.btn-danger {
  background: rgba(255,77,109,0.12);
  color: var(--danger);
  border: 1px solid rgba(255,77,109,0.25);
  border-radius: 9px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.btn-danger:hover  { background: rgba(255,77,109,0.22); }
.btn-danger:active { transform: scale(0.96); }

/* =====================
   MODAL
   ===================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal.hidden { display: none !important; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-box {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px 28px;
  max-width: 400px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal-badge {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #ff8c00, #ff4500);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: -1px;
  box-shadow: 0 4px 20px rgba(255,69,0,0.45);
}

.modal-box h2 {
  font-size: 1.3rem;
  font-weight: 800;
}

.modal-box p {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.65;
  max-width: 300px;
}
.modal-box p strong { color: var(--text); }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* =====================
   WAITING
   ===================== */
.waiting-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  max-width: 300px;
}

.waiting-inner h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.waiting-inner p {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Triple-ring spinner */
.loader {
  position: relative;
  width: 64px;
  height: 64px;
  margin-bottom: 4px;
}

.loader-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  animation: spin 1.3s linear infinite;
}

.r1 { border-top-color: var(--accent);  animation-duration: 1.3s; }
.r2 { inset: 9px; border-top-color: #ff8c00; animation-duration: 1s; animation-direction: reverse; }
.r3 { inset: 18px; border-top-color: var(--online); animation-duration: 0.8s; }

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

/* =====================
   CHAT SCREEN
   ===================== */
#screen-chat {
  padding: 0;
  justify-content: flex-start;
  gap: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
  gap: 12px;
}

.chat-peer {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 0.95rem;
  overflow: hidden;
}

.peer-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peer-dot {
  width: 9px;
  height: 9px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--online);
  transition: background 0.3s;
}
.peer-dot.away { background: var(--muted); }

.chat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Messages */
.msg-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 14px 100px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;

  /* Chat background pattern */
  background-color: var(--chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64'%3E%3Cpath d='M32 23 L41 32 L32 41 L23 32 Z' fill='none' stroke='%23ff4500' stroke-opacity='0.09' stroke-width='1.2'/%3E%3Ccircle cx='0' cy='0' r='2.2' fill='%23ff5500' fill-opacity='0.08'/%3E%3Ccircle cx='64' cy='64' r='2.2' fill='%23ff5500' fill-opacity='0.08'/%3E%3Ccircle cx='64' cy='0' r='2.2' fill='%23ff5500' fill-opacity='0.08'/%3E%3Ccircle cx='0' cy='64' r='2.2' fill='%23ff5500' fill-opacity='0.08'/%3E%3Ccircle cx='32' cy='32' r='1.2' fill='%23ff6a00' fill-opacity='0.1'/%3E%3C/svg%3E");
}

.msg-list::-webkit-scrollbar { width: 3px; }
.msg-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  animation: pop-in 0.18s ease-out;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.9) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.msg-bubble.me {
  background: var(--me-bg);
  color: var(--me-text);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg-bubble.them {
  background: var(--them-bg);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg-time {
  display: block;
  font-size: 0.66rem;
  margin-top: 4px;
  text-align: right;
  opacity: 0.5;
  line-height: 1;
  letter-spacing: 0.2px;
}

.msg-bubble.them .msg-time {
  text-align: left;
}

.msg-system {
  align-self: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 3px 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 100px;
  text-align: center;
  max-width: 90%;
}

.msg-system.msg-system--end {
  color: var(--danger);
  background: rgba(255, 34, 68, 0.1);
  border: 1px solid rgba(255, 34, 68, 0.2);
  font-size: 0.85rem;
  padding: 6px 16px;
  font-weight: 500;
}

/* Typing indicator */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  background: var(--them-bg);
  padding: 10px 14px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  animation: pop-in 0.18s ease-out;
}

.typing-bubble span {
  width: 7px;
  height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: typing-bounce 1.1s infinite ease-in-out;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.18s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.36s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.5; }
  30%            { transform: translateY(-5px); opacity: 1;   }
}

/* Emoji panel */
.emoji-panel {
  display: flex;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  max-height: 148px;
  overflow-y: auto;
  gap: 2px;
  flex-shrink: 0;
  width: 100%;
}
.emoji-panel.hidden { display: none !important; }
.emoji-panel::-webkit-scrollbar { width: 3px; }
.emoji-panel::-webkit-scrollbar-thumb { background: var(--border); }

.emoji-panel button {
  font-size: 1.25rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px 7px;
  border-radius: 7px;
  line-height: 1;
  transition: background 0.14s;
  -webkit-tap-highlight-color: transparent;
}
.emoji-panel button:hover { background: var(--elevated); }

/* Ended-state footer */
.footer-ended {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
}
.footer-ended.hidden { display: none !important; }
.chat-footer.hidden  { display: none !important; }

.ended-online {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
  flex-shrink: 0;
}
.ended-online strong { color: var(--text); }

.ended-btn {
  width: auto !important;
  padding: 11px 20px !important;
  font-size: 0.9rem !important;
  white-space: nowrap;
}

/* Chat footer */
.chat-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 3px 5px;
  flex-shrink: 0;
  line-height: 1;
  border-radius: 8px;
  transition: background 0.14s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--elevated); }

.msg-input {
  flex: 1;
  min-width: 0;
  background: var(--elevated);
  border: 1.5px solid var(--border);
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s;
  caret-color: var(--accent);
}
.msg-input::placeholder { color: var(--muted); }
.msg-input:focus { border-color: var(--accent); }

.send-btn {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s, transform 0.12s;
  box-shadow: 0 2px 12px rgba(255,69,0,0.4);
  -webkit-tap-highlight-color: transparent;
}
.send-btn:hover  { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.9); }

/* =====================
   TOAST
   ===================== */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 0.85rem;
  pointer-events: none;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  text-overflow: ellipsis;
  overflow: hidden;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =====================
   RESPONSIVE TWEAKS
   ===================== */
/* ---- Topic chip in chat header ---- */
.header-topic {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,69,0,0.12);
  border: 1px solid rgba(255,69,0,0.25);
  border-radius: 100px;
  padding: 5px 8px 5px 12px;
  font-size: 0.78rem;
  color: var(--accent);
  max-width: 140px;
  overflow: hidden;
}
.header-topic.hidden { display: none !important; }

#header-topic-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-close-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 2px;
  flex-shrink: 0;
  opacity: 0.7;
  -webkit-tap-highlight-color: transparent;
}
.topic-close-btn:hover { opacity: 1; }

/* ---- Waiting screen topic badge ---- */
.waiting-topic-badge {
  background: rgba(255,69,0,0.12);
  border: 1px solid rgba(255,69,0,0.25);
  border-radius: 100px;
  padding: 6px 18px;
  font-size: 0.85rem;
  color: var(--accent);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.waiting-topic-badge.hidden { display: none !important; }

@media (max-width: 400px) {
  .home-inner { gap: 16px; }
  .home-top   { padding: 48px 20px 16px; }
  .modal-box  { padding: 28px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* =====================
   THEME TOGGLE
   ===================== */
.theme-toggle {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.theme-toggle:hover  { background: var(--border); }
.theme-toggle:active { transform: scale(0.9); }

/* Home screen toggle is positioned inside .home-top via #screen-home .theme-toggle above */

/* =====================
   DESKTOP LAYOUT
   ===================== */
@media (min-width: 1000px) {

  /* Outer zone — slightly darker than surface */
  html, body {
    background: var(--bg);
  }

  /* Center #app as a 640px column */
  #app {
    position: fixed;
    inset: 0 auto;          /* top:0, right:auto, bottom:0, left:auto */
    left: 50%;
    transform: translateX(-50%);
    width: 640px;
  }

  /* Ad panels */
  .ad-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    position: fixed;
    top: 0;
    bottom: 0;
    background: var(--surface);
    border-color: var(--border);
    border-style: solid;
  }

  #ad-left {
    left: 0;
    right: calc(50% + 320px);
    border-right-width: 1px;
    border-left-width: 0;
  }

  #ad-right {
    left: calc(50% + 320px);
    right: 0;
    border-left-width: 1px;
    border-right-width: 0;
  }

  /* Slot placeholder — replace with real ad code */
  .ad-slot {
    width: 160px;
    height: 600px;
    max-height: 80vh;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    writing-mode: horizontal-tb;
    opacity: 0.5;
  }

  /* Modal keeps viewport coverage */
  .modal {
    position: fixed;
    inset: 0;
  }
}
