/* ==================== Unified Modal Layer (Strictly Below Fixed Red .risk Banner) ==================== */
.modal-backdrop {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--risk-height);
  bottom: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(3, 6, 14, 0.8);
  backdrop-filter: blur(4px);
  overflow: hidden;
}

.modal-dialog {
  position: relative;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 0.85rem;
  width: min(36rem, calc(100vw - 2rem));
  max-width: 100%;
  max-height: calc(100dvh - var(--risk-height) - 2rem);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.25rem 1.38rem;
  box-shadow: 0 22px 64px rgba(0, 0, 0, 0.65);
  outline: none;
}

.modal-dialog.tone-risk {
  border-color: rgba(240, 188, 94, 0.52);
  background: linear-gradient(180deg, #1d170b 0%, #110f0c 100%);
}

.modal-dialog.tone-ban {
  border-color: rgba(224, 114, 134, 0.5);
  background: linear-gradient(180deg, #1f1119 0%, #120d13 100%);
}

.modal-dialog.tone-deleted {
  border-color: rgba(236, 98, 116, 0.56);
  background: linear-gradient(180deg, #220f15 0%, #120c10 100%);
}

#dialog-content {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  min-width: 0;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0.15rem 0 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.dialog-head .quiet {
  padding: 0.25rem 0.55rem;
  min-height: 1.9rem;
  flex-shrink: 0;
}

.dialog-copy {
  color: #cbd6ea;
  line-height: 1.7;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.dialog-copy li {
  margin-bottom: 0.65rem;
}

.ann-popup-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
}

.ann-popup-progress {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0.12rem 0.48rem;
  border-radius: 0.34rem;
  background: rgba(230, 192, 123, 0.14);
  border: 1px solid rgba(230, 192, 123, 0.34);
  color: var(--gold-bright);
}

.dialog-form {
  display: grid;
  gap: 0.68rem;
}

.dialog-form textarea {
  min-height: 4.2rem;
  resize: vertical;
}

.dialog-form .primary {
  justify-self: start;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1rem;
  max-width: 100%;
}

.dialog-actions button {
  max-width: 100%;
}

.checkline {
  display: flex !important;
  flex-direction: row;
  align-items: start !important;
  color: var(--ink) !important;
  gap: 0.45rem;
}

.checkline input {
  width: auto;
  accent-color: var(--gold);
  margin: 0.26rem 0 0;
}

/* ==================== Toast Notice (Above Modals & Banner) ==================== */
.notice {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 70;
  padding: 0.72rem 1rem;
  max-width: min(380px, calc(100% - 2.5rem));
  border: 1px solid rgba(230, 192, 123, 0.35);
  background: #10192b;
  color: var(--ink);
  border-radius: 0.6rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.52);
  font-size: 0.875rem;
}

/* ==================== Triple Box, Mod Workbench & User Notices ==================== */
.triple-box {
  background: var(--input-bg);
  border: 1px solid var(--line-strong);
  border-radius: 0.62rem;
  padding: 0.9rem;
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}

.triple-box code {
  background: rgba(139, 185, 248, 0.12);
  color: var(--accent-bright);
  padding: 0.14rem 0.42rem;
  border-radius: 0.3rem;
  font-family: var(--font-mono);
}

.mod-tabs {
  display: flex;
  gap: 0.65rem;
  padding: 3px;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.mod-tabs button[aria-pressed="true"] {
  background: var(--gold);
  color: var(--gold-ink);
  border-color: transparent;
  outline: 1.5px solid rgba(230, 192, 123, 0.65);
  outline-offset: 2px;
  font-weight: 600;
}

.mod-card {
  border: 1px solid var(--line);
  background: var(--input-bg);
  border-radius: 0.6rem;
  padding: 0.8rem;
  margin-bottom: 0.7rem;
  display: grid;
  gap: 0.48rem;
}

.mod-card pre {
  margin: 0;
  background: rgba(13, 21, 37, 0.8);
  border: 1px solid var(--line);
  padding: 0.55rem 0.65rem;
  border-radius: 0.42rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  font-size: 0.85rem;
}

.notice-badge {
  display: inline-block;
  margin-left: 0.34rem;
  padding: 0.04rem 0.38rem;
  border-radius: 0.32rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  background: #e05d6d;
  color: #fff6f7;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.user-notice-card {
  border: 1px solid var(--line);
  background: var(--input-bg);
  border-radius: 0.58rem;
  padding: 0.78rem 0.9rem;
  margin-bottom: 0.65rem;
  display: grid;
  gap: 0.35rem;
}

.user-notice-card.unread {
  border-color: rgba(230, 192, 123, 0.45);
  background: rgba(23, 28, 44, 0.9);
}

.user-notice-card pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  color: var(--ink);
  line-height: 1.6;
}

/* ==================== Restricted Auth Entry & Modal Details ==================== */
.restricted-entry {
  display: grid;
  gap: 0.42rem;
  padding: 0.62rem 0.72rem;
  margin-bottom: 0.85rem;
  border-radius: 0.55rem;
  border: 1px solid rgba(224, 114, 134, 0.42);
  background: rgba(36, 18, 28, 0.72);
  min-width: 0;
}

.restricted-entry.tone-risk {
  border-color: rgba(240, 188, 94, 0.42);
  background: rgba(38, 29, 13, 0.72);
}

.restricted-entry.tone-deleted {
  border-color: rgba(236, 98, 116, 0.48);
  background: rgba(40, 16, 22, 0.78);
}

.restricted-entry-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.restricted-entry-badge {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.08rem 0.42rem;
  border-radius: 0.3rem;
  background: rgba(98, 34, 52, 0.75);
  color: #fecdd3;
  border: 1px solid rgba(224, 114, 134, 0.45);
}

.restricted-entry.tone-risk .restricted-entry-badge {
  background: rgba(78, 56, 18, 0.8);
  color: #fde68a;
  border-color: rgba(240, 188, 94, 0.45);
}

.restricted-entry-label {
  font-size: 0.81rem;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.restricted-entry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.55rem;
}

.restricted-entry-actions button {
  padding: 0.18rem 0.38rem;
  border-radius: 0.32rem;
  min-height: auto;
  font-size: 0.8rem;
  color: var(--accent-bright);
}

.restricted-modal-grid {
  display: grid;
  gap: 0.85rem;
  min-width: 0;
}

.restricted-kv-list {
  display: grid;
  gap: 0.48rem;
  padding: 0.78rem 0.92rem;
  border-radius: 0.58rem;
  background: rgba(6, 10, 19, 0.72);
  border: 1px solid var(--line);
  min-width: 0;
}

.restricted-kv {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.3rem 0.75rem;
  font-size: 0.87rem;
  min-width: 0;
}

.restricted-kv span {
  color: var(--muted);
  flex-shrink: 0;
}

.restricted-kv strong {
  color: var(--ink);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.restricted-reason-box {
  margin: 0;
  padding: 0.82rem 0.94rem;
  border-radius: 0.58rem;
  background: rgba(6, 10, 19, 0.82);
  border: 1px solid rgba(245, 148, 158, 0.28);
  color: #ffe4e6;
  font-size: 0.9rem;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-height: 16rem;
  overflow-y: auto;
  overflow-x: hidden;
}

.modal-dialog.tone-risk .restricted-reason-box {
  border-color: rgba(240, 188, 94, 0.36);
  color: #fef3c7;
}

.restricted-modal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding-top: 0.2rem;
}

.restricted-modal-actions .quiet {
  margin-left: auto;
}

.connection-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1.65rem;
  border-bottom: 1px solid rgba(224, 114, 134, 0.42);
  background: #23121b;
  color: #fecdd3;
  font-size: 0.84rem;
}

.recovery-guide {
  display: grid;
  gap: 0.52rem;
  padding: 0.8rem 0.92rem;
  margin-bottom: 0.9rem;
  border-radius: 0.58rem;
  background: var(--input-bg);
  border: 1px solid var(--line);
  font-size: 0.84rem;
  line-height: 1.6;
  color: #c6d3ea;
}

.recovery-guide strong {
  color: var(--gold-bright);
}

.recovery-guide p {
  margin: 0;
}

/* ==================== Desktop Sticky Rails ==================== */
@media (min-width: 1061px) {
  .identity,
  .sidebar {
    position: sticky;
    top: var(--risk-height);
    height: calc(100dvh - var(--risk-height));
    overflow: auto;
  }

  .main {
    min-height: calc(100dvh - var(--risk-height));
  }
}

/* ==================== Medium Breakpoint ==================== */
@media (max-width: 1060px) {
  .layout {
    grid-template-columns: 232px minmax(0, 1fr) 210px;
  }

  .identity,
  .sidebar {
    padding-inline: 0.9rem;
  }

  .main-header {
    padding-inline: 1.1rem;
  }

  .composer {
    margin-inline: 1.1rem;
  }

  .landing {
    padding-inline: 2rem;
  }
}

/* ==================== Mobile Navigation & Reflow (<= 780px) ==================== */
.mobile-tabs {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  background: var(--input-bg);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.24rem;
}

.mobile-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.4rem 0.78rem;
  border-radius: 0.38rem;
  min-height: 2.15rem;
}

.mobile-tabs button[aria-current="true"] {
  background: var(--panel-elevated);
  color: var(--gold-bright);
  outline: 1px solid rgba(230, 192, 123, 0.48);
  outline-offset: 1px;
  font-weight: 600;
}

@media (max-width: 780px) {
  .risk-toggle {
    display: inline-flex;
  }

  .risk:not(.expanded) > div {
    align-items: center;
    padding-block: 0.44rem;
  }

  .risk:not(.expanded) .risk-symbol {
    margin-top: 0;
  }

  .risk:not(.expanded) p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .risk.expanded p {
    white-space: normal;
  }

  .layout {
    display: flex;
    flex-direction: column;
  }

  .mobile-bar {
    position: sticky;
    top: var(--risk-height);
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    background: rgba(9, 15, 28, 0.96);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
  }

  .mobile-brand .logo {
    width: 2rem;
    height: 2rem;
    font-size: 1.1rem;
    border-radius: 0.5rem;
  }

  .mobile-brand strong {
    font-family: var(--font-display);
    font-size: 1.02rem;
    letter-spacing: 0.1em;
  }

  /* Avoid duplicate brand banner on mobile since .mobile-bar already renders it */
  .identity > .brand {
    display: none;
  }

  .layout[data-mobile-pane="identity"] > .main,
  .layout[data-mobile-pane="identity"] > .sidebar,
  .layout[data-mobile-pane="main"] > .identity,
  .layout[data-mobile-pane="main"] > .sidebar,
  .layout[data-mobile-pane="sidebar"] > .identity,
  .layout[data-mobile-pane="sidebar"] > .main {
    display: none;
  }

  .identity,
  .sidebar {
    border: 0;
    gap: 0.9rem;
    padding: 0.95rem 0.95rem 1.5rem;
  }

  .identity {
    display: flex;
    flex-direction: column;
  }

  .phase {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.25rem 0.75rem;
  }

  .phase strong {
    font-size: 1rem;
  }

  .identity-panel {
    padding: 0.9rem;
  }

  .identity-panel form {
    grid-template-columns: 1fr;
  }

  .identity-panel #welcome {
    display: none;
  }

  .account-area {
    grid-template-columns: 1fr;
  }

  .account-logout {
    width: 100%;
    justify-self: stretch;
  }

  .quota {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 0.85rem;
  }

  .quota-line span,
  .quota-line strong,
  .quota-line label {
    font-size: 0.78rem;
  }

  .main {
    min-height: 420px;
  }

  .landing {
    min-height: 360px;
    padding: 2.2rem 1.15rem;
  }

  .landing h1 {
    font-size: 2.3rem;
  }

  .landing p {
    margin-bottom: 1.25rem;
  }

  .main-header {
    padding: 1rem 1rem 0.75rem;
    align-items: start;
    flex-wrap: wrap;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .field {
    display: none;
  }

  #toggle-list {
    display: none;
  }

  .topic-list,
  .ocean.list-mode .topic-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
    padding: 0.4rem 0.95rem 0.9rem;
  }

  .locked-floor {
    margin: 0.5rem 0.95rem 0;
    max-height: 28dvh;
  }

  .room-scroll {
    padding-inline: 0.95rem;
    max-height: 56dvh;
  }

  .topic-fields {
    grid-template-columns: 1fr;
  }

  .md-hint {
    display: none;
  }

  .sidebar {
    border-top: 0;
    min-height: 420px;
  }

  .site-tools {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    border: 0;
    padding-top: 0.5rem;
  }

  .composer {
    margin: 0.5rem 0.9rem 1rem;
  }

  .connection-banner {
    padding: 0.55rem 0.95rem;
    flex-wrap: wrap;
  }

  .modal-backdrop {
    padding: 0.75rem;
  }

  .modal-dialog {
    width: min(36rem, calc(100vw - 1.5rem));
    max-height: calc(100dvh - var(--risk-height) - 1.5rem);
    padding: 1.05rem 1.05rem;
  }

  .restricted-kv {
    flex-direction: column;
    align-items: flex-start;
  }

  .restricted-kv strong {
    text-align: left;
  }

  .restricted-modal-actions .quiet {
    margin-left: 0;
  }

  .primary,
  .secondary {
    min-height: 2.5rem;
  }
}

@media (max-width: 385px) {
  .risk p {
    font-size: 0.78rem;
  }

  .compose-foot {
    flex-wrap: wrap;
  }

  .compose-foot .error {
    order: 3;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    transform: none !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-reduced-motion: no-preference) {
  #compose-form {
    animation: rise 0.18s ease-out both;
  }
}

@keyframes rise {
  from {
    clip-path: inset(100% 0 -8px);
    opacity: 0.62;
  }
  to {
    clip-path: none;
    opacity: 1;
  }
}

/* ==================== User Settings & Management Hub ==================== */
.user-hub {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-hub-head {
  border-bottom: 1px solid var(--line);
}

.user-hub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding: 0.85rem 1.65rem 0.2rem;
}

.user-hub-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.44rem 0.9rem;
  min-height: 2.15rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: rgba(13, 21, 37, 0.72);
  color: var(--muted);
  font-size: 0.855rem;
  font-weight: 500;
}

.user-hub-tab:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--panel-elevated);
}

.user-hub-tab[aria-selected="true"] {
  background: rgba(230, 192, 123, 0.14);
  border-color: transparent;
  outline: 1.5px solid rgba(230, 192, 123, 0.62);
  outline-offset: 2px;
  color: var(--gold-bright);
  font-weight: 600;
}

.user-hub-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem 1.65rem 2rem;
  display: grid;
  gap: 1rem;
  align-content: start;
}

.hub-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  padding: 1.05rem 1.18rem;
  display: grid;
  gap: 0.75rem;
}

.hub-card h2,
.hub-card h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.hub-card.danger-zone {
  border-color: rgba(236, 114, 134, 0.4);
  background: linear-gradient(180deg, rgba(44, 18, 28, 0.56) 0%, var(--panel) 100%);
}

.hub-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.hub-kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.65rem;
}

.hub-kv {
  background: rgba(7, 13, 24, 0.72);
  border: 1px solid var(--line);
  border-radius: 0.52rem;
  padding: 0.62rem 0.78rem;
  display: grid;
  gap: 0.2rem;
}

.hub-kv span {
  font-size: 0.76rem;
  color: var(--muted);
}

.hub-kv strong {
  font-size: 0.9rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.hub-warning-list {
  margin: 0;
  padding-left: 1.15rem;
  display: grid;
  gap: 0.35rem;
  font-size: 0.855rem;
  color: #f8cfd5;
  line-height: 1.6;
}

.ai-download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  justify-self: start;
}

@media (max-width: 780px) {
  .user-hub-tabs {
    padding-inline: 0.95rem;
  }

  .user-hub-body {
    padding: 0.95rem 0.95rem 1.5rem;
  }
}
