:root {
  color-scheme: dark;
  --bg: #07080b;
  --panel: #10131a;
  --panel-strong: #171b24;
  --line: #354052;
  --line-hot: #99ffd7;
  --text: #edf7f2;
  --muted: #8da39b;
  --green: #72ffc8;
  --amber: #ffd166;
  --red: #ff6b6b;
  --violet: #a48cff;
  --shadow: rgba(114, 255, 200, 0.24);
  --marebito-primary: #72ffc8;
  --marebito-glow: rgba(114, 255, 200, 0.45);
  --marebito-faint: rgba(114, 255, 200, 0.12);
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(114, 255, 200, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(114, 255, 200, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 20% 12%, rgba(255, 209, 102, 0.12), transparent 26rem),
    radial-gradient(circle at 86% 28%, rgba(164, 140, 255, 0.13), transparent 30rem),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto, auto, auto;
  color: var(--text);
}

body.intro-active {
  background: #000;
}

body.intro-active .gate-shell {
  visibility: hidden;
  pointer-events: none;
}

button,
input {
  font: inherit;
}

select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  align-items: center;
  justify-items: center;
  min-height: 100dvh;
  padding: clamp(28px, 7vh, 72px) 16px 88px;
  overflow: hidden;
  background: #000;
  color: #64ff7a;
}

.intro-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(100, 255, 122, 0.055) 0,
      rgba(100, 255, 122, 0.055) 1px,
      transparent 1px,
      transparent 4px
    );
  opacity: 0.28;
}

.intro-overlay.is-glitching {
  animation: introGlitch 180ms steps(2, end) 2;
}

.intro-overlay.is-gate-ready {
  padding-block: clamp(28px, 7vh, 72px);
}

.intro-terminal {
  position: relative;
  z-index: 1;
  width: min(820px, calc(100vw - 32px));
  height: min(620px, calc(100dvh - 140px));
  min-height: min(620px, calc(100dvh - 140px));
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-content: start;
  gap: 18px;
  font-family: "IBM Plex Mono", "Roboto Mono", "JetBrains Mono", "Cascadia Code", monospace;
  text-shadow: 0 0 10px rgba(100, 255, 122, 0.35);
}

.intro-overlay.is-gate-ready .intro-terminal {
  grid-template-rows: auto auto;
  align-content: center;
  gap: clamp(18px, 4vh, 34px);
}

.intro-log {
  min-height: 0;
  overflow: hidden auto;
  padding-top: 4px;
  padding-bottom: clamp(150px, 32vh, 240px);
  padding-inline: clamp(0px, 3vw, 42px);
  scrollbar-width: none;
}

.intro-log::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.intro-log.is-gate-ready {
  display: flex;
  min-height: auto;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  padding-bottom: 0;
  text-align: center;
}

.intro-line {
  margin: 0 0 9px;
  color: #64ff7a;
  font-size: clamp(0.92rem, 1.8vw, 1.08rem);
  line-height: 1.65;
  letter-spacing: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.intro-line.title {
  margin: 0 0 5px;
  color: #e9fff0;
  font-size: clamp(1.85rem, 8vw, 4rem);
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  text-shadow: 0 0 18px rgba(100, 255, 122, 0.52);
}

.intro-line.subtitle {
  margin: 0 0 18px;
  color: rgba(233, 255, 240, 0.84);
  font-size: clamp(0.78rem, 2.2vw, 1rem);
  line-height: 1.45;
  text-align: center;
}

.intro-log.is-gate-ready .intro-line:not(.title, .subtitle) {
  text-align: center;
}

.intro-line.origin {
  color: #e6fff1;
  font-size: clamp(1.08rem, 2.8vw, 1.42rem);
}

.intro-cursor {
  width: fit-content;
  animation: introCursor 680ms steps(1, end) infinite;
}

.intro-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.intro-overlay.is-gate-ready .intro-choices {
  justify-content: center;
}

.intro-choice-button,
.intro-skip {
  min-height: 44px;
  border: 1px solid rgba(100, 255, 122, 0.72);
  border-radius: 4px;
  color: #64ff7a;
  background: rgba(100, 255, 122, 0.045);
  font-family: "IBM Plex Mono", "Roboto Mono", "JetBrains Mono", "Cascadia Code", monospace;
  letter-spacing: 0;
}

.intro-choice-button {
  min-width: 144px;
  display: inline-grid;
  gap: 2px;
  justify-items: center;
  padding: 9px 16px;
}

.intro-choice-button small {
  color: rgba(233, 255, 240, 0.78);
  font-size: 0.76rem;
}

.intro-choice-button:hover,
.intro-choice-button:focus-visible,
.intro-skip:hover,
.intro-skip:focus-visible {
  outline: 0;
  border-color: #e9fff0;
  color: #e9fff0;
  background: rgba(100, 255, 122, 0.12);
  box-shadow: 0 0 0 3px rgba(100, 255, 122, 0.13);
}

.intro-skip {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  padding: 0 12px;
  color: rgba(100, 255, 122, 0.76);
  background: rgba(0, 0, 0, 0.72);
}

.gate-shell {
  width: min(1120px, calc(100% - 24px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(280px, 1fr) auto auto;
  gap: 14px;
  padding: 16px 0;
}

.gate-controls {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 10px;
}

.friend-panel {
  display: grid;
  gap: 10px;
}

.settings-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.panel-note {
  grid-column: 1 / -1;
  margin: -2px 2px 2px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.mobile-bottom-nav {
  display: none;
}

.control-group,
.user-talk-panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: rgba(16, 19, 26, 0.82);
}

.control-group {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.invite-control {
  grid-template-columns: auto auto minmax(0, 1fr) auto;
}

.invite-link-output {
  grid-column: 2 / -2;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-group label,
.talk-header label {
  color: var(--muted);
  font-size: 0.88rem;
}

.control-group select,
.control-group input,
.control-group output,
.talk-header select,
.user-talk-form input,
#marebitoForm input,
#marebitoForm select,
#marebitoForm textarea {
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 10px;
  color: var(--text);
  background: rgba(7, 8, 11, 0.88);
}

.control-group output {
  display: flex;
  align-items: center;
  color: var(--amber);
  font-family: ui-monospace, "Cascadia Code", monospace;
  letter-spacing: 0;
}

.control-group input[type="text"] {
  text-transform: uppercase;
}

.inline-toggle {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.inline-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.notification-control output {
  font-size: 0.82rem;
}

.quiet-control {
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
}

.admin-shell {
  width: min(1120px, calc(100% - 24px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px 0;
}

.gate-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  background: rgba(16, 19, 26, 0.86);
  box-shadow: 0 0 26px rgba(0, 0, 0, 0.35);
}

.system-label {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 0.78rem;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 4vw, 2.1rem);
  font-weight: 700;
  letter-spacing: 0;
}

.status-panel,
.limit-panel,
.user-panel {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(114, 255, 200, 0.55);
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--green);
  background: rgba(114, 255, 200, 0.06);
  font-size: 0.92rem;
  white-space: nowrap;
}

.limit-panel {
  border-color: rgba(255, 209, 102, 0.4);
  color: var(--amber);
  background: rgba(255, 209, 102, 0.06);
}

.limit-panel strong {
  color: var(--text);
  font-size: 1rem;
}

.user-panel {
  border-color: rgba(164, 140, 255, 0.4);
  color: var(--text);
  background: rgba(164, 140, 255, 0.08);
}

.active-marebito {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--text);
}

.marebito-avatar {
  position: relative;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.95) 0 18%, var(--marebito-primary) 36%, rgba(164, 140, 255, 0.28) 62%, transparent 74%);
  box-shadow: 0 0 18px var(--marebito-glow);
  animation: floatMini 4s ease-in-out infinite;
}

.marebito-avatar[data-icon-style="ring"] {
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 12%, transparent 22%),
    radial-gradient(circle, transparent 34%, var(--marebito-primary) 38% 48%, transparent 58%);
}

.marebito-avatar[data-icon-style="spark"] {
  background:
    radial-gradient(circle at 50% 50%, #ffffff 0 14%, transparent 18%),
    conic-gradient(from 12deg, transparent 0 18%, var(--marebito-primary) 20% 23%, transparent 25% 48%, var(--marebito-primary) 50% 54%, transparent 56% 100%);
}

.marebito-avatar[data-icon-style="quiet"] {
  opacity: 0.82;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.88) 0 16%, var(--marebito-primary) 34%, transparent 68%);
  box-shadow: 0 0 10px var(--marebito-glow);
}

.marebito-avatar[data-display-type="image"] {
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background-color: rgba(7, 8, 11, 0.62);
  background-repeat: no-repeat;
  background-position: var(--marebito-image-position, center center);
  background-size: auto var(--marebito-image-size, 100%);
  box-shadow: 0 0 14px var(--marebito-glow);
}

.marebito-avatar.state-thinking {
  animation: floatMini 4s ease-in-out infinite, pulse 1.4s ease-in-out infinite;
}

.marebito-avatar.state-talking {
  animation: talkMini 0.5s ease-in-out 4;
}

.marebito-avatar.state-bounce {
  animation: bounceMini 0.64s ease-out;
}

.marebito-avatar.state-confused {
  transform: scale(0.86);
  box-shadow: 0 0 16px rgba(255, 107, 107, 0.38);
}

#activeMarebitoName {
  font-weight: 700;
}

#mobileOriginStatus {
  color: var(--amber);
  font-size: 0.82rem;
}

.mobile-tools-button {
  display: none;
  min-height: 40px;
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--amber);
  background: rgba(255, 209, 102, 0.07);
}

.small-button {
  min-height: 28px;
  border: 1px solid rgba(164, 140, 255, 0.5);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--text);
  background: rgba(7, 8, 11, 0.55);
  font-size: 0.82rem;
}

.small-button.danger {
  border-color: rgba(255, 107, 107, 0.5);
  color: #ffb5b5;
  background: rgba(255, 107, 107, 0.08);
}

.admin-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(114, 255, 200, 0.48);
  border-radius: 4px;
  padding: 8px 12px;
  color: var(--green);
  background: rgba(114, 255, 200, 0.06);
  text-decoration: none;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px var(--green);
}

.origin-stage {
  position: relative;
  min-height: 300px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(18, 23, 31, 0.92), rgba(9, 10, 14, 0.96)),
    repeating-linear-gradient(0deg, transparent, transparent 9px, rgba(114, 255, 200, 0.05) 10px);
}

.origin-stage::before,
.origin-stage::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(141, 163, 155, 0.32);
  pointer-events: none;
}

.origin-stage::after {
  inset: 42px;
  border-color: rgba(255, 209, 102, 0.22);
}

.scanline {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(114, 255, 200, 0.08), transparent);
  height: 28%;
  animation: scan 6s linear infinite;
}

.origin-orb {
  position: relative;
  width: clamp(132px, 25vw, 220px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 0 36px var(--shadow));
  animation: float 5.4s ease-in-out infinite;
}

.origin-orb::before,
.origin-orb::after,
.orb-core {
  content: "";
  position: absolute;
  border-radius: 50%;
}

.origin-orb::before {
  inset: 0;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.96) 0 12%, var(--marebito-primary) 24%, rgba(164, 140, 255, 0.28) 48%, var(--marebito-faint) 66%, transparent 74%);
  filter: blur(2px);
}

.origin-orb::after {
  inset: 14%;
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 0 28px rgba(255, 255, 255, 0.36), 0 0 28px var(--marebito-glow);
}

.orb-core {
  width: 38%;
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 38px #ffffff, 0 0 64px var(--marebito-primary);
}

.origin-orb[data-icon-style="ring"]::after {
  inset: 5%;
  border-width: 3px;
}

.origin-orb[data-icon-style="spark"]::before {
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.96) 0 10%, var(--marebito-primary) 18%, transparent 34%),
    conic-gradient(from 12deg, transparent 0 16%, var(--marebito-primary) 18% 22%, transparent 24% 49%, var(--marebito-primary) 51% 55%, transparent 57% 100%);
}

.origin-orb[data-icon-style="quiet"] {
  filter: drop-shadow(0 0 20px var(--marebito-glow));
}

.origin-orb[data-icon-style="quiet"]::before {
  opacity: 0.72;
}

.origin-orb[data-display-type="image"] {
  width: clamp(170px, 32vw, 280px);
  max-height: min(66dvh, 360px);
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  background-color: rgba(7, 8, 11, 0.42);
  background-repeat: no-repeat;
  background-position: var(--marebito-image-position, center center);
  background-size: auto var(--marebito-image-size, 100%);
  box-shadow: 0 0 30px var(--marebito-glow);
}

.origin-orb[data-display-type="image"]::before,
.origin-orb[data-display-type="image"]::after,
.origin-orb[data-display-type="image"] .orb-core {
  display: none;
}

.origin-status {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  min-width: 9em;
  margin: 0;
  border: 1px solid rgba(255, 209, 102, 0.38);
  border-radius: 4px;
  padding: 7px 12px;
  background: rgba(7, 8, 11, 0.72);
  color: var(--amber);
  text-align: center;
  font-size: 0.92rem;
}

.origin-orb.state-thinking {
  animation: float 5.4s ease-in-out infinite, pulse 1.5s ease-in-out infinite;
}

.origin-orb.state-talking {
  animation: float 5.4s ease-in-out infinite, talk 0.52s ease-in-out 4;
}

.origin-orb.state-bounce {
  animation: bounce 0.72s ease-out;
}

.origin-orb.state-confused {
  animation: confused 0.72s ease-in-out;
  filter: drop-shadow(0 0 26px rgba(255, 107, 107, 0.28));
}

.communication-panel {
  display: grid;
  grid-template-rows: minmax(150px, 28vh) auto;
  gap: 12px;
}

.user-talk-panel {
  display: grid;
  gap: 10px;
}

.talk-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.friend-actions {
  display: inline-flex;
  gap: 6px;
}

.user-talk-log {
  min-height: 70px;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid rgba(141, 163, 155, 0.2);
  border-radius: 5px;
  padding: 10px;
  background: rgba(7, 8, 11, 0.45);
}

.talk-message {
  margin: 0 0 7px;
  color: var(--text);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.talk-message.mine {
  color: #fff3c4;
}

.talk-empty {
  margin: 0;
  color: var(--muted);
}

.user-talk-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px;
  gap: 8px;
}

.user-talk-form button,
#marebitoForm button {
  min-height: 38px;
  border: 1px solid rgba(114, 255, 200, 0.55);
  border-radius: 5px;
  padding: 0 12px;
  color: var(--green);
  background: rgba(114, 255, 200, 0.08);
}

.chat-log {
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  background: rgba(16, 19, 26, 0.86);
}

.message {
  width: fit-content;
  max-width: min(76ch, 88%);
  margin: 0 0 10px;
  border: 1px solid rgba(141, 163, 155, 0.28);
  border-radius: 6px;
  padding: 10px 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(23, 27, 36, 0.9);
}

.message.user {
  margin-left: auto;
  border-color: rgba(255, 209, 102, 0.38);
  color: #fff3c4;
}

.message.origin {
  border-color: rgba(114, 255, 200, 0.38);
  color: #d9fff2;
}

.message.system {
  margin-inline: auto;
  color: var(--muted);
  font-size: 0.92rem;
}

.speaker {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.message-stamp {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  border: 1px solid rgba(255, 209, 102, 0.42);
  border-radius: 5px;
  padding: 4px 7px;
  color: var(--amber);
  background: rgba(255, 209, 102, 0.08);
  font-size: 0.82rem;
  line-height: 1.3;
}

.message-stamp-icon {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 209, 102, 0.5);
  border-radius: 50%;
  object-fit: contain;
  background: rgba(7, 8, 11, 0.5);
  font-size: 0.72rem;
  line-height: 1;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
}

.stamp-tray {
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}

.stamp-button,
.chat-form button,
.end-button {
  min-height: 46px;
  border: 1px solid rgba(114, 255, 200, 0.48);
  border-radius: 5px;
  color: var(--text);
  background: rgba(16, 19, 26, 0.92);
}

.stamp-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  color: var(--amber);
}

.stamp-icon {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border: 1px solid var(--amber);
  border-radius: 50%;
  font-size: 0.7rem;
  line-height: 1;
}

.stamp-image {
  border-radius: 6px;
  object-fit: contain;
  background: rgba(7, 8, 11, 0.5);
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 10px;
}

.chat-form input {
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 13px;
  color: var(--text);
  background: rgba(7, 8, 11, 0.88);
  outline: none;
}

.chat-form input:focus {
  border-color: var(--line-hot);
  box-shadow: 0 0 0 3px rgba(114, 255, 200, 0.15);
}

.chat-form button {
  color: var(--green);
}

.end-button {
  min-width: 104px;
  padding: 0 12px;
  border-color: rgba(255, 107, 107, 0.42);
  color: #ffb5b5;
}

.stamp-button:hover,
.chat-form button:hover,
.end-button:hover,
.small-button:hover {
  background: rgba(114, 255, 200, 0.1);
}

.stamp-button:disabled,
.chat-form button:disabled,
.chat-form input:disabled,
.end-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  background: rgba(7, 8, 11, 0.78);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.registration-box {
  width: min(420px, 100%);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  border: 1px solid rgba(114, 255, 200, 0.48);
  border-radius: 6px;
  padding: 20px;
  background: rgba(16, 19, 26, 0.96);
  box-shadow: 0 0 36px rgba(0, 0, 0, 0.5), 0 0 28px rgba(114, 255, 200, 0.12);
}

.registration-box h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0;
}

.registration-copy {
  margin: 8px 0 16px;
  color: var(--muted);
}

.registration-status {
  min-height: 1.4em;
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.registration-status:empty {
  display: none;
}

.registration-status[data-type="success"] {
  color: var(--green);
}

.registration-status[data-type="error"] {
  color: #ffb5b5;
}

#registrationForm,
#registrationInviteForm,
#marebitoForm,
.secondary-form,
.admin-form {
  display: grid;
  gap: 10px;
}

.form-section-label {
  margin: 0;
  color: var(--green);
  font-size: 0.84rem;
  font-weight: 700;
}

.form-section {
  min-width: 0;
  display: grid;
  gap: 10px;
  border: 1px solid rgba(141, 163, 155, 0.2);
  border-radius: 6px;
  padding: 10px;
}

.form-section legend {
  padding: 0 6px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 600;
}

#registrationForm label,
#registrationInviteForm label,
#marebitoForm label,
.secondary-form label,
.admin-form label {
  color: var(--muted);
  font-size: 0.9rem;
}

#registrationForm input,
#registrationInviteForm input,
.secondary-form input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(7, 8, 11, 0.88);
}

#registrationInviteForm input,
.secondary-form input {
  text-transform: uppercase;
}

#registrationForm button,
#registrationInviteForm button,
.secondary-form button {
  min-height: 44px;
  border: 1px solid rgba(114, 255, 200, 0.55);
  border-radius: 5px;
  color: var(--green);
  background: rgba(114, 255, 200, 0.08);
}

.secondary-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(141, 163, 155, 0.2);
}

#marebitoForm textarea {
  min-height: 76px;
  resize: vertical;
}

#marebitoForm input[type="color"],
#adminMarebitoForm input[type="color"],
.admin-table input[type="color"] {
  width: 100%;
  min-height: 38px;
  padding: 3px;
}

.admin-form {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.admin-form label,
.admin-form input,
.admin-form textarea,
.admin-form button,
.checkbox-label {
  grid-column: span 1;
}

.admin-form textarea,
.admin-form button,
.checkbox-label {
  grid-column: 1 / -1;
}

.admin-form input[type="text"],
.admin-form input[type="url"],
.admin-form input[type="number"],
.admin-form input[type="file"],
.admin-form select,
.admin-form textarea {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 10px;
  color: var(--text);
  background: rgba(7, 8, 11, 0.88);
}

.admin-form textarea {
  min-height: 76px;
  resize: vertical;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.checkbox-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.admin-auth,
.admin-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  background: rgba(16, 19, 26, 0.9);
}

.admin-auth h2,
.admin-card h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  letter-spacing: 0;
}

#adminTokenForm {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

#adminTokenForm label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.9rem;
}

#adminTokenForm input,
#adminTokenForm button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 12px;
  color: var(--text);
  background: rgba(7, 8, 11, 0.88);
}

#adminTokenForm button {
  border-color: rgba(114, 255, 200, 0.55);
  color: var(--green);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.admin-card.wide {
  grid-column: 1 / -1;
}

.metric-list {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}

.metric-list dt {
  color: var(--muted);
}

.metric-list dd {
  margin: 0;
  color: var(--text);
}

.admin-table {
  overflow-x: auto;
}

.admin-table table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1100px;
}

.admin-table.compact table {
  min-width: 760px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid rgba(141, 163, 155, 0.18);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--green);
  font-weight: 600;
}

.admin-table td {
  color: var(--text);
}

.admin-table input[type="text"],
.admin-table input[type="url"],
.admin-table input[type="number"],
.admin-table select,
.admin-table textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 7px 9px;
  color: var(--text);
  background: rgba(7, 8, 11, 0.88);
}

.icon-editor {
  min-width: 170px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
}

.icon-editor select,
.icon-editor input[type="url"],
.icon-editor input[type="file"],
.icon-editor input[type="number"] {
  grid-column: 1 / -1;
}

.admin-table textarea {
  min-height: 76px;
  resize: vertical;
}

.profile-editor {
  min-width: 360px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px 8px;
}

.profile-editor label {
  color: var(--muted);
  font-size: 0.78rem;
}

.profile-editor textarea {
  min-height: 64px;
}

.profile-editor label,
.profile-editor textarea {
  min-width: 0;
}

.compact-checkbox {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.compact-checkbox input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.stamp-permission-editor {
  min-width: 180px;
  display: grid;
  gap: 7px;
}

.stamp-editor {
  min-width: 210px;
  display: grid;
  gap: 7px;
}

.stamp-permission {
  justify-content: start;
  gap: 7px;
  color: var(--text);
  white-space: nowrap;
}

.admin-stamp-preview {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 209, 102, 0.45);
  border-radius: 6px;
  object-fit: contain;
  background: rgba(7, 8, 11, 0.55);
  color: var(--amber);
  font-size: 0.72rem;
}

.table-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  min-width: 96px;
}

.table-actions button {
  min-height: 34px;
  border: 1px solid rgba(114, 255, 200, 0.5);
  border-radius: 5px;
  color: var(--green);
  background: rgba(114, 255, 200, 0.08);
}

.table-actions button.danger {
  border-color: rgba(255, 107, 107, 0.5);
  color: #ffb5b5;
  background: rgba(255, 107, 107, 0.08);
}

.table-meta {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-16px) scale(1.035);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

@keyframes talk {
  0%,
  100% {
    transform: translateY(-8px) scale(1);
  }
  50% {
    transform: translateY(-8px) scale(1.08);
  }
}

@keyframes bounce {
  0% {
    transform: translateY(0) scale(1);
  }
  36% {
    transform: translateY(-34px) scale(1.1);
  }
  72% {
    transform: translateY(4px) scale(0.96);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes confused {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(0.82);
  }
}

@keyframes scan {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(360%);
  }
}

@keyframes floatMini {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-3px) scale(1.04);
  }
}

@keyframes talkMini {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.12);
  }
}

@keyframes bounceMini {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(-7px) scale(1.08);
  }
}

@keyframes introCursor {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

@keyframes introGlitch {
  0% {
    transform: translateX(0);
    opacity: 1;
    text-shadow: 0 0 10px rgba(100, 255, 122, 0.35);
  }
  35% {
    transform: translateX(-3px);
    opacity: 0.86;
    text-shadow: 3px 0 0 rgba(255, 107, 107, 0.45), -3px 0 0 rgba(114, 255, 200, 0.35);
  }
  70% {
    transform: translateX(3px);
    opacity: 0.92;
    text-shadow: -3px 0 0 rgba(255, 209, 102, 0.4), 3px 0 0 rgba(100, 255, 122, 0.42);
  }
  100% {
    transform: translateX(0);
    opacity: 1;
    text-shadow: 0 0 10px rgba(100, 255, 122, 0.35);
  }
}

@media (prefers-reduced-motion: reduce) {
  .intro-overlay.is-glitching,
  .intro-cursor {
    animation: none;
  }
}

@media (max-width: 680px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .gate-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 0;
    padding: 0;
  }

  .intro-overlay {
    z-index: 20;
    align-items: center;
    padding: 18px 14px 82px;
    overflow-y: auto;
  }

  .intro-terminal {
    width: 100%;
    height: calc(100dvh - 112px);
    min-height: calc(100dvh - 112px);
  }

  .intro-log {
    overflow: hidden auto;
    padding-bottom: clamp(140px, 32vh, 240px);
    padding-inline: 0;
  }

  .intro-choices {
    display: grid;
    grid-template-columns: 1fr;
  }

  .intro-choice-button {
    width: 100%;
    min-width: 0;
  }

  .gate-header {
    position: sticky;
    top: 0;
    z-index: 4;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    border-inline: 0;
    border-top: 0;
    border-radius: 0;
    padding: 8px 10px;
  }

  .gate-header h1 {
    display: none;
  }

  .system-label {
    margin-bottom: 2px;
    font-size: 0.72rem;
  }

  .active-marebito {
    margin-top: 2px;
  }

  .marebito-avatar {
    width: 34px;
    height: 34px;
  }

  .status-panel,
  .limit-panel,
  .user-panel {
    display: none;
  }

  .mobile-tools-button {
    display: none;
  }

  .origin-stage {
    display: none;
  }

  .mobile-panel {
    display: none;
  }

  .mobile-panel.is-active {
    display: grid;
  }

  .gate-controls,
  .friend-panel,
  .settings-panel {
    align-content: start;
    gap: 10px;
    min-height: 0;
    overflow-y: auto;
    padding: 10px;
  }

  .settings-panel {
    display: none;
  }

  .settings-panel.is-active {
    display: grid;
  }

  .friend-panel.is-active {
    overflow-y: auto;
  }

  .communication-panel {
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 0;
  }

  .communication-panel:not(.is-active) {
    display: none;
  }

  .user-talk-panel {
    min-height: 0;
  }

  .gate-controls,
  .control-group,
  .composer,
  .chat-form,
  .talk-header,
  .user-talk-form,
  #adminTokenForm,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .invite-link-output {
    grid-column: auto;
  }

  .friend-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chat-log {
    min-height: 0;
    border-inline: 0;
    border-radius: 0;
    padding: 12px 10px;
    background: rgba(16, 19, 26, 0.72);
  }

  .message {
    max-width: 86%;
    padding: 9px 11px;
    line-height: 1.58;
  }

  .composer {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
    border-top: 1px solid var(--line);
    background: rgba(7, 8, 11, 0.94);
  }

  .stamp-tray {
    min-width: 42px;
  }

  .chat-form {
    grid-template-columns: minmax(0, 1fr) 58px;
    gap: 8px;
  }

  .stamp-button {
    min-width: 42px;
    padding: 0;
  }

  .stamp-button span:last-child {
    display: none;
  }

  .end-button {
    display: none;
  }

  .stamp-button,
  .chat-form button,
  .chat-form input {
    width: 100%;
  }

  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    border-top: 1px solid var(--line);
    background: rgba(7, 8, 11, 0.96);
  }

  .mobile-tab {
    min-height: 54px;
    border: 0;
    border-right: 1px solid rgba(141, 163, 155, 0.14);
    border-radius: 0;
    color: var(--muted);
    background: transparent;
    font-size: 0.78rem;
  }

  .mobile-tab:last-child {
    border-right: 0;
  }

  .mobile-tab.is-active {
    color: var(--green);
    background: rgba(114, 255, 200, 0.08);
    box-shadow: inset 0 2px 0 var(--green);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
