html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}
.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.main-content {
  /* Shared <main> container: keep block flow for normal pages. */
  flex: 1;
  min-height: 0;
  padding-bottom: 0.75rem;
}

.vrm-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 1rem;
}

.vrm-section-home {
  gap: 0;
}

.vrm-select {
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.vrm-select-nav {
  margin-left: auto;
}

.vrm-action-button {
  white-space: nowrap;
}

.vrm-viewer {
  width: 100%;
  flex: 1;
  min-height: 65vh;
  margin-bottom: 0.75rem;
  border-radius: 16px;
  border: 1px solid rgba(13, 110, 253, 0.2);
  background: radial-gradient(circle at top, rgba(13, 110, 253, 0.15), transparent 60%),
    #0b0f1a;
  overflow: hidden;
  position: relative;
}

.viewer-chat {
  position: absolute;
  left: 8px;
  bottom: 8px;
  width: min(360px, 90%);
  min-width: 240px;
  max-width: min(520px, 95%);
  min-height: 200px;
  max-height: min(520px, 80vh);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.35rem 0.75rem 0.2rem;
  border-radius: 16px;
  background: rgba(10, 15, 26, 0.45);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #e2e8f0;
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.35);
}

.viewer-chat--resizing {
  user-select: none;
}

.viewer-chat__toggle {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background: rgba(15, 23, 42, 0.7);
  color: #e2e8f0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.viewer-chat__resize-handle {
  position: absolute;
  top: -0.1rem;
  right: -0.1rem;
  width: 6px;
  height: 6px;
  border-radius: 2px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: repeating-linear-gradient(
    135deg,
    rgba(148, 163, 184, 0.7) 0,
    rgba(148, 163, 184, 0.7) 2px,
    rgba(15, 23, 42, 0.8) 2px,
    rgba(15, 23, 42, 0.8) 4px
  );
  cursor: nesw-resize;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.35);
  z-index: 2;
  touch-action: none;
}

.viewer-chat__toggle:hover {
  background: rgba(59, 130, 246, 0.65);
}

.viewer-chat--collapsed .viewer-chat__toggle {
  transform: rotate(-90deg);
}

.viewer-chat--collapsed {
  min-height: 0;
}

.viewer-chat--collapsed .viewer-chat__panels,
.viewer-chat--collapsed .viewer-chat__composer {
  display: none;
}

.viewer-chat--collapsed .viewer-chat__resize-handle {
  display: none;
}

.viewer-chat__tab-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.viewer-chat__tablist {
  display: inline-flex;
  align-self: flex-start;
  position: absolute;
  top: -0.9rem;
  left: 0.75rem;
  background: transparent;
  padding: 0;
}

.viewer-chat__tab {
  text-align: center;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.3rem 0.7rem;
  border-radius: 9px 9px 5px 5px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-bottom: 0;
  background: rgba(15, 23, 42, 0.75);
  color: rgba(226, 232, 240, 0.9);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

#chat-tab-nearby:checked ~ .viewer-chat__tablist label[for="chat-tab-nearby"] {
  background: rgba(59, 130, 246, 0.8);
  color: #fff;
}

.viewer-chat__panels {
  min-height: 0;
  flex: 1;
  display: flex;
}

.viewer-chat__panel {
  display: none;
  flex: 1;
  min-height: 0;
}

#chat-tab-nearby:checked ~ .viewer-chat__panels .viewer-chat__panel--nearby {
  display: flex;
  flex-direction: column;
}

.viewer-chat__messages {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding-right: 0.2rem;
  font-size: 0.78rem;
}

.viewer-chat__message {
  font-size: 0.78rem;
  line-height: 1.3;
  background: transparent;
  border-radius: 0;
  padding: 0;
}

.viewer-chat__message--self {
  color: #fcd34d;
}

.viewer-chat__message--self .viewer-chat__author {
  color: #fbbf24;
}

.viewer-chat__messages:empty::before {
  content: "No messages yet.";
  display: block;
  text-align: center;
  color: rgba(226, 232, 240, 0.7);
  background: transparent;
  border-radius: 0;
  padding: 0;
}

.viewer-chat__message--system {
  background: transparent;
  color: #bfdbfe;
}

.viewer-chat__author {
  font-weight: 600;
  margin-right: 0.35rem;
  color: #93c5fd;
}

.viewer-chat__composer {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0;
}

.viewer-chat__input {
  flex: 1;
  min-width: 0;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.7);
  color: #f8fafc;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

.viewer-chat__input::placeholder {
  color: rgba(226, 232, 240, 0.6);
}

.viewer-chat__send {
  border-radius: 999px;
  border: 0;
  background: rgba(59, 130, 246, 0.9);
  color: #fff;
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.viewer-chat__send:disabled,
.viewer-chat__input:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.viewer-chat__hint {
  margin: 0;
  font-size: 0.65rem;
  color: rgba(226, 232, 240, 0.7);
}

.vrm-status {
  position: absolute;
  inset: auto 16px 16px 16px;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.85);
  color: #e2e8f0;
  font-size: 0.85rem;
  letter-spacing: 0.01em;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.35);
}

.viewer-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
}

.live-status {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(25, 135, 84, 0.15);
  color: #198754;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.fullscreen-toggle {
  font-size: 0.75rem;
  padding: 0.25rem 0.7rem;
}

.vrm-viewer:fullscreen {
  width: 100%;
  height: 100%;
  margin: 0;
  border-radius: 0;
}

.vrm-upload input {
  display: none;
}

.footer-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.viewer-controls-footer {
  margin-left: auto;
}

.vrm-section-home .vrm-viewer {
  height: calc(100vh - 170px);
  min-height: clamp(420px, calc(100vh - 170px), 92vh);
  margin-bottom: 0;
}

.character-card {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  justify-content: space-between;
}

.character-card__details {
  flex: 1 1 60%;
}

.vrm-preview {
  flex: 0 0 180px;
  width: 180px;
  height: 220px;
  border-radius: 16px;
  border: 1px solid rgba(13, 110, 253, 0.2);
  background: radial-gradient(circle at top, rgba(13, 110, 253, 0.2), transparent 65%),
    #0b0f1a;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.vrm-preview__expand {
  position: absolute;
  bottom: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 0;
  padding: 0;
  background: rgba(11, 15, 26, 0.85);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
  z-index: 2;
}

.vrm-preview__expand::before {
  content: "";
  display: block;
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-left: 0;
  border-bottom: 0;
  transform: rotate(45deg);
}

.vrm-preview__expand:hover {
  background: rgba(13, 110, 253, 0.85);
}

.vrm-preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 13, 0.65);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1040;
}

.vrm-preview-overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

.vrm-preview--expanded {
  position: fixed;
  inset: 10vh 8vw;
  width: auto;
  height: auto;
  flex: none;
  z-index: 1050;
  cursor: grab;
}

.vrm-preview:active {
  cursor: grabbing;
}

.vrm-preview canvas {
  display: block;
}

.vrm-preview__fallback {
  font-size: 0.85rem;
  text-align: center;
  padding: 0 0.5rem;
}

@media (max-width: 767.98px) {
  .character-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .vrm-preview {
    width: 100%;
    max-width: 260px;
    align-self: flex-end;
  }

  .vrm-preview--expanded {
    inset: 8vh 4vw;
  }
}
