:root {
  --code-bg: #1b2e1f;
  --code-fg: #a5d6a7;
  --warn-bg: #fff8e1;
  --warn-border: #f9a825;
  --danger-bg: #fce8e6;
  --danger-border: #c62828;
  --ok-bg: #e8f5e9;
  --ok-border: #2e7d32;
  --radius: 16px;
  --radius-sm: 8px;
  --radius-lg: 24px;
  --font: "Roboto", "Ubuntu", "Cantarell", "Noto Sans", "DejaVu Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "Roboto Mono", "Ubuntu Mono", "Noto Sans Mono", "DejaVu Sans Mono", ui-monospace, Menlo, Consolas, monospace;
  --transition: 200ms cubic-bezier(0.2, 0, 0, 1);}

body.dark {
  --code-bg: #0a140e;
  --code-fg: #a5d6a7;
  --warn-bg: #332b00;
  --warn-border: #fdd663;
  --danger-bg: #3c1518;
  --danger-border: #ef9a9a;
  --ok-bg: #1b3a24;
  --ok-border: #81c784;}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  padding: 12px;
  transition: background 0.25s, color 0.25s;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 24px);
  max-height: calc(100vh - 24px);
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--bg) 40%, var(--card));
  position: relative;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

a.icon-btn {
  text-decoration: none;
  color: inherit;
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  background: color-mix(in srgb, var(--bg) 60%, var(--card));
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.timer-box.warn {
  color: #d97706;
  border-color: var(--warn-border);
  background: var(--warn-bg);
}

.timer-box.danger {
  color: #dc2626;
  border-color: var(--danger-border);
  background: var(--danger-bg);
}

.btn-extend {
  border: none;
  background: var(--accent);
  color: var(--on-primary);
  font-size: 0.75rem;
  font-weight: 650;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
  transition: filter 0.15s, transform 0.12s;
}

.btn-extend:hover {
  filter: brightness(1.08);
}

.btn-extend:active {
  transform: scale(0.96);
}

.btn-extend:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.menu-panel {
  position: absolute;
  top: 56px;
  left: 16px;
  z-index: 100;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  padding: 8px;
  min-width: 200px;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.menu-panel.open {
  display: flex;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.12s;
}

.menu-item:hover {
  background: var(--accent-soft);
}

.menu-item.danger {
  color: #dc2626;
}

body.dark .menu-item.danger {
  color: #f87171;
}

.menu-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 28px;
  max-width: 100%;
  min-height: 0;
}

.screen.active {
  display: flex;
}

.screen-center {
  justify-content: flex-start;
  align-items: stretch;
  text-align: center;
  gap: 14px;
  padding-top: 12px;
  padding-bottom: 28px;
}

.screen h1 {
  font-size: 1.85rem;
  font-weight: 750;
  letter-spacing: -0.5px;
  color: var(--accent);
  margin-bottom: 4px;
}

.banner {
  padding: 12px 16px;
  border-radius: 12px;
  margin: 0 0 16px;
  font-weight: 500;
  font-size: 0.92rem;
  border-left: 5px solid;
  text-align: left;
  max-width: 480px;
  width: 100%;
}

.banner.warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--text);
}

body.dark .banner.warn {
  color: #f5e6b8;
}

.banner.ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}

.banner.danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 360px;
  margin-top: 8px;
  align-self: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: 14px;
  font-weight: 650;
  font-size: 0.98rem;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: transform 0.12s, filter 0.15s, box-shadow 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--on-primary);
  box-shadow: 0 4px 12px rgba(46, 125, 50, 0.25);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-secondary:hover {
  filter: brightness(0.96);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--accent);
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 70%, var(--card));
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
}

.field-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-align: left;
  margin-bottom: 4px;
  width: 100%;
  max-width: 360px;
}

.spoiler {
  width: 100%;
  max-width: 480px;
  margin-top: 12px;
  text-align: left;
  align-self: center;
}

.spoiler-toggle {
  width: 100%;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: left;
  color: var(--accent);
  background: color-mix(in srgb, var(--bg) 55%, var(--card));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.spoiler-toggle .arrow {
  transition: transform 0.2s;
  font-size: 0.75rem;
}

.spoiler.open .spoiler-toggle .arrow {
  transform: rotate(180deg);
}

.spoiler-body {
  display: none;
  padding: 12px 14px;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.6;
  border-left: 3px solid var(--accent);
  margin-top: 8px;
  background: color-mix(in srgb, var(--bg) 50%, var(--card));
  border-radius: 0 10px 10px 0;
}

.spoiler.open .spoiler-body {
  display: block;
}

.spoiler-body p {
  margin: 0 0 10px;
}

.spoiler-body p:last-child {
  margin-bottom: 0;
}

.spoiler-body ol {
  padding-left: 1.2rem;
  margin: 6px 0 10px;
}

.spoiler-body li {
  margin-bottom: 6px;
}

.code-box {
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 10px 12px;
  border-radius: 10px;
  word-break: break-all;
  overflow-wrap: anywhere;
  margin: 8px 0;
  user-select: all;
  max-width: min(480px, 100%);
  align-self: center;
}

.code-box-sm { font-size: 0.75rem; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
}

.status-dot.online {
  background: #10b981;
  box-shadow: 0 0 0 3px color-mix(in srgb, #10b981 30%, transparent);
}

.status-dot.offline {
  background: #ef4444;
}

.peer-status {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

#screen-room {
  padding: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
}

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

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

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 4px 10px;
  max-width: 95%;
  text-align: center;
}

.msg .time {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
  opacity: 0.8;
}

.msg .link-plain {
  color: var(--accent);
  word-break: break-all;
  cursor: text;
  text-decoration: underline;
  text-decoration-style: dotted;
}

.msg img.chat-img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  display: block;
  margin-top: 4px;
  cursor: zoom-in;
}

.compose {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 35%, var(--card));
  flex-shrink: 0;
  align-items: flex-end;
  position: relative;
  z-index: 2;
}

.compose textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  border-radius: 14px;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 0.95rem;
}

.compose .icon-btn {
  flex-shrink: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0);
  visibility: hidden;
  pointer-events: none;
  transition: background 0.3s, visibility 0.3s;
}

.modal-overlay.visible {
  background: rgba(15, 23, 42, 0.55);
  visibility: visible;
  pointer-events: auto;
}

body.dark .modal-overlay.visible {
  background: rgba(0, 0, 0, 0.7);
}

.modal-card {
  background: var(--card);
  border-radius: 20px;
  padding: 28px 24px 22px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
  text-align: center;
  transform: scale(0.94) translateY(10px);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.25s;
}

.modal-overlay.visible .modal-card {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.modal-card h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-card p {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 18px;
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.modal-actions .btn {
  min-width: 100px;
}

#screen-unsupported {
  padding: 40px 28px;
}

@media (max-width: 560px) {
  body {
    padding: 0;
  }
  .container {
    border-radius: 0;
    min-height: 100vh;
    max-height: 100vh;
  }
  .screen {
    padding: 18px 16px;
  }
  .screen h1 {
    font-size: 1.55rem;
  }
  .home-title h1 {
    font-size: 1.35rem;
  }
  .home-title svg {
    width: 24px;
    height: 24px;
  }
  .timer-box {
    font-size: 0.75rem;
    padding: 5px 8px;
  }
  .btn-extend {
    font-size: 0.7rem;
    padding: 4px 8px;
  }
}

.chat-topbar[hidden], .password-extra[hidden], .password-wrap[hidden], .join-password-wrap[hidden], .sr-only, #fileInput {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.turn-badge {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: -1.4rem;
  z-index: 5;
  font-size: 0.7rem;
  opacity: 0.9;
  background: var(--warn-bg);
  color: var(--text);
  border: 1px solid var(--warn-border);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  display: none;
}

.home-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas:
    "home . actions"
    "title title title";
  align-items: center;
  column-gap: 12px;
  row-gap: 18px;
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  align-self: stretch;
}

.home-bar > a.icon-btn {
  grid-area: home;
  justify-self: start;
}

.home-title {
  grid-area: title;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--accent);
  min-width: 0;
}

.home-title svg {
  flex: 0 0 auto;
  color: var(--accent);
}

.home-title h1 {
  margin: 0;
  padding: 0;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-actions {
  grid-area: actions;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.home-actions .lang-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
}

.home-actions .lang-chip:hover {
  filter: brightness(0.97);
}

.home-actions .icon-btn {
  width: 38px;
  height: 38px;
  font-size: 1.05rem;
  flex: 0 0 auto;
}

.paranoid-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 0.5rem auto 0;
  max-width: 420px;
  width: 100%;
  text-align: left;
  font-size: 0.85rem;
  opacity: 0.95;
  box-sizing: border-box;
  padding: 0 4px;
  align-self: center;
}

.paranoid-row > span {
  min-width: 0;
  flex: 1 1 auto;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: left;
}

.paranoid-row input[type="checkbox"] {
  margin-top: 0.25rem;
  flex: 0 0 auto;
  width: 1.05rem;
  height: 1.05rem;
}

.password-extra, .join-password-wrap {
  width: 100%;
  max-width: 420px;
  margin: 0.35rem auto 0;
  box-sizing: border-box;
  padding: 0;
  align-self: center;
}

.join-password-wrap { margin-top: 10px; }
.invite-result { margin-top: 16px; }
.password-wrap { margin-top: 0.5rem; }

#passwordInput, #joinPasswordInput, #inputRoomId {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  box-sizing: border-box;
  font-family: inherit;
}

#passwordInput::placeholder, #joinPasswordInput::placeholder, #inputRoomId::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

#passwordInput:focus,
#joinPasswordInput:focus,
#inputRoomId:focus,
#inputNtfyTopic:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-color: var(--accent);
}

.banner, .actions, .spoiler, .code-box {
  max-width: min(480px, 100%);
  box-sizing: border-box;
  align-self: center;
}

.actions {
  width: 100%;
}

.code-box {
  overflow-wrap: anywhere;
  word-break: break-all;
}

.sas-code {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  letter-spacing: 0.15em;
  font-weight: 600;
}

.actions-spaced { margin-top: 14px; }

.hint-muted { opacity: 0.8; }
.btn-block { margin-top: 10px; width: 100%; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  display: inline-block;
  box-shadow: 0 0 0 0 transparent;
  transition: background 0.25s, box-shadow 0.25s;
}
.status-dot.waiting,
.status-dot.connecting {
  background: #f9a825;
  animation: pulse-dot 1.4s ease-in-out infinite;
}
.status-dot.online {
  background: #2e7d32;
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.25);
}
.status-dot.offline {
  background: #c62828;
}
body.dark .status-dot.online {
  background: #81c784;
  box-shadow: 0 0 0 3px rgba(129, 199, 132, 0.3);
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

.compose textarea {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.compose textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
.compose .icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.compose .icon-btn:hover {
  background: var(--surface-variant);
  color: var(--primary);
}
.compose .icon-btn:active {
  transform: scale(0.96);
}
#btnSend {
  background: var(--primary);
  color: var(--on-primary);
}
#btnSend:hover {
  filter: brightness(1.08);
  color: var(--on-primary);
}

.messages {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.peer-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.chat-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
}

input[type="file"].sr-only {
  display: none !important;
}

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 48px;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  flex: 0 0 auto;
  transition: background 0.15s;
}
.tb-btn:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  text-decoration: none;
  color: var(--text);
}
.tb-btn:active {
  background: color-mix(in srgb, var(--text) 16%, transparent);
}
.tb-btn svg {
  width: 24px;
  height: 24px;
  flex: none;
}
.tb-lang {
  border-radius: 24px;
  padding: 0 1rem;
  min-width: 56px;
  border: 1px solid var(--border);
  background: var(--card);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  height: 40px;
  min-height: 40px;
}
.tb-lang:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.home-bar > a.tb-btn {
  grid-area: home;
  justify-self: start;
}
.home-actions .tb-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
}
.home-actions .tb-lang {
  width: auto;
  min-width: 56px;
  height: 40px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, filter 0.15s, background 0.15s;
  font-family: var(--font);
  line-height: 1;
}

.icon-btn:hover { filter: brightness(0.96); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.tagline {
  color: var(--muted);
  font-size: 0.98rem;
  max-width: 420px;
  margin: 0 auto 8px;
}
.banner,
.tagline,
.actions,
.spoiler,
.code-box {
  max-width: min(480px, 100%);
  box-sizing: border-box;
  align-self: center;
}
.tagline-sm { margin-top: 12px; font-size: 0.85rem; }
