:root {
  --bg: #050a08;
  --panel: #0a1410;
  --panel-2: #0d1a14;
  --border: #1a3d2a;
  --ink: #b8f0c8;
  --ink-dim: #5a9a6e;
  --accent: #3dff8a;
  --accent-2: #7fffaa;
  --enter: #6fcf97;
  --leave: #e8a0a0;
  --phosphor: #3dff8a;
  --phosphor-dim: rgba(61, 255, 138, 0.35);
  --mono: "Cascadia Code", "Consolas", "SFMono-Regular", "Menlo", "Noto Sans JP",
    monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: #000;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
}

/* CRT ラッパー */
.cb-crt {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.cb-crt::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background: radial-gradient(
    ellipse at center,
    transparent 55%,
    rgba(0, 0, 0, 0.45) 100%
  );
}

.cb-scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.18) 2px,
    rgba(0, 0, 0, 0.18) 4px
  );
  opacity: 0.55;
}

.cb-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.65);
}

/* 起動シーケンス */
.cb-boot {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 24px 28px;
  background: var(--bg);
  color: var(--phosphor);
  text-shadow: 0 0 8px var(--phosphor-dim);
  cursor: pointer;
}

.cb-boot.is-active,
.cb-boot:not([hidden]) {
  display: flex;
}

.cb-boot.is-active {
  animation: cb-boot-in 0.25s ease;
}

.cb-boot__hint {
  position: absolute;
  right: 20px;
  bottom: 16px;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  pointer-events: none;
}

.cb-crt.is-booting .cb-app {
  filter: blur(2px) brightness(0.45);
  pointer-events: none;
  user-select: none;
}

@keyframes cb-boot-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.cb-boot.is-done {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.cb-boot__text {
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.cb-boot__cursor {
  animation: cb-blink 0.9s step-end infinite;
  color: var(--phosphor);
  text-shadow: 0 0 10px var(--phosphor);
}

@keyframes cb-blink {
  50% {
    opacity: 0;
  }
}

.cb-app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.cb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(61, 255, 138, 0.08);
}

.cb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cb-brand strong {
  letter-spacing: 0.12em;
  color: var(--phosphor);
  text-shadow: 0 0 12px var(--phosphor-dim);
}

.cb-sub {
  color: var(--ink-dim);
  font-size: 12px;
}

.cb-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #333;
  box-shadow: 0 0 6px #000 inset;
}

.cb-led.is-online {
  background: var(--phosphor);
  box-shadow: 0 0 10px var(--phosphor), 0 0 20px var(--phosphor-dim);
  animation: cb-led-pulse 2s ease-in-out infinite;
}

.cb-led.is-connecting {
  background: #d8b450;
  box-shadow: 0 0 8px #d8b450;
  animation: cb-led-blink 0.5s step-end infinite;
}

@keyframes cb-led-pulse {
  50% {
    opacity: 0.75;
  }
}

@keyframes cb-led-blink {
  50% {
    opacity: 0.3;
  }
}

.cb-handle-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cb-handle-box label {
  color: var(--ink-dim);
  font-size: 12px;
}

.cb-handle-box input {
  width: 160px;
}

input,
button {
  font-family: var(--mono);
  font-size: 14px;
}

.cb-handle-box input,
.cb-form input {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 6px 10px;
  outline: none;
  caret-color: var(--phosphor);
}

.cb-handle-box input:focus,
.cb-form input:focus {
  border-color: var(--phosphor);
  box-shadow: 0 0 8px var(--phosphor-dim);
}

.cb-top-link,
.cb-admin-link {
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 2px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.cb-top-link:hover,
.cb-admin-link:hover {
  color: var(--phosphor);
  background: var(--panel-2);
  border-color: var(--phosphor);
  text-shadow: 0 0 6px var(--phosphor-dim);
}

.cb-admin-link {
  font-size: 16px;
  padding: 4px 6px;
  border: none;
}

.cb-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.cb-side {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cb-panel h2 {
  margin: 4px 6px 8px;
  font-size: 12px;
  color: var(--ink-dim);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cb-panel h2::before {
  content: "┌─ ";
  color: var(--border);
}

.cb-count {
  color: var(--phosphor);
  text-shadow: 0 0 6px var(--phosphor-dim);
}

.cb-channels,
.cb-who {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cb-channels li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 2px;
  cursor: pointer;
  color: var(--ink);
}

.cb-channels li:hover {
  background: var(--panel-2);
  color: var(--phosphor);
}

.cb-channels li.is-active {
  background: var(--panel-2);
  border-left: 3px solid var(--phosphor);
  color: var(--phosphor);
  text-shadow: 0 0 6px var(--phosphor-dim);
}

.cb-channels li.is-locked {
  opacity: 0.72;
}

.cb-ch-lock {
  font-size: 0.75rem;
}

.cb-ch-no {
  color: var(--accent-2);
  margin-right: 8px;
}

.cb-ch-online {
  color: var(--ink-dim);
  font-size: 12px;
}

.cb-who li {
  padding: 4px 10px;
  color: var(--ink);
}

.cb-who li::before {
  content: "●";
  color: var(--phosphor);
  font-size: 9px;
  margin-right: 8px;
  vertical-align: middle;
  text-shadow: 0 0 6px var(--phosphor-dim);
}

.cb-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cb-channel-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 13px;
}

.cb-channel-title::before {
  content: "╔══ ";
  color: var(--border);
  letter-spacing: -0.05em;
}

.cb-channel-title::after {
  content: " ══╗";
  color: var(--border);
  letter-spacing: -0.05em;
  margin-left: auto;
}

.cb-channel-title #cb-current-ch {
  color: var(--phosphor);
  font-weight: 700;
  margin-right: 4px;
  text-shadow: 0 0 8px var(--phosphor-dim);
}

.cb-channel-name {
  color: var(--ink-dim);
}

.cb-channel-mode {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.06em;
}

.cb-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--bg);
  text-shadow: 0 0 4px var(--phosphor-dim);
}

.cb-log.is-connecting {
  animation: cb-flicker 0.15s ease 3;
}

@keyframes cb-flicker {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.92;
  }
}

.cb-line {
  display: flex;
  gap: 8px;
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.cb-line.is-typing .cb-text::after {
  content: "█";
  animation: cb-blink 0.9s step-end infinite;
  color: var(--phosphor);
  margin-left: 1px;
}

.cb-line.is-new {
  animation: cb-line-in 0.25s ease;
}

@keyframes cb-line-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cb-line .cb-time {
  color: #3d6b50;
  font-size: 12px;
  flex-shrink: 0;
}

.cb-line .cb-name {
  color: var(--accent-2);
  flex-shrink: 0;
}

.cb-line .cb-name::after {
  content: " :";
  color: var(--ink-dim);
}

.cb-line.cb-welcome .cb-text {
  color: var(--phosphor);
  font-style: normal;
  text-shadow: 0 0 8px var(--phosphor-dim);
}

.cb-line.cb-system {
  color: var(--ink-dim);
  font-style: italic;
}

.cb-line.cb-enter .cb-text {
  color: var(--enter);
  text-shadow: 0 0 6px rgba(111, 207, 151, 0.3);
}

.cb-line.cb-leave .cb-text {
  color: var(--leave);
}

.cb-line.cb-self .cb-name {
  color: var(--phosphor);
  text-shadow: 0 0 6px var(--phosphor-dim);
}

.cb-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.cb-prompt {
  color: var(--phosphor);
  font-weight: 700;
  text-shadow: 0 0 8px var(--phosphor-dim);
  animation: cb-blink 1.2s step-end infinite;
}

.cb-form input {
  flex: 1;
}

.cb-form button {
  background: transparent;
  color: var(--phosphor);
  border: 1px solid var(--phosphor);
  border-radius: 2px;
  padding: 7px 16px;
  font-weight: 700;
  cursor: pointer;
  text-shadow: 0 0 6px var(--phosphor-dim);
  letter-spacing: 0.05em;
}

.cb-form button:hover:not(:disabled) {
  background: rgba(61, 255, 138, 0.12);
  box-shadow: 0 0 12px var(--phosphor-dim);
}

.cb-form button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cb-status {
  margin: 0;
  padding: 0 16px 6px;
  min-height: 18px;
  font-size: 12px;
  color: var(--ink-dim);
  background: var(--panel);
}

.cb-status.is-error {
  color: var(--leave);
}

/* 回線ステータスバー */
.cb-statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 6px 16px 10px;
  font-size: 11px;
  color: var(--ink-dim);
  background: var(--panel);
  border-top: 1px dashed var(--border);
  letter-spacing: 0.06em;
}

.cb-statusbar__sep {
  color: var(--border);
}

.cb-statusbar__item.is-online {
  color: var(--phosphor);
  text-shadow: 0 0 6px var(--phosphor-dim);
}

.cb-statusbar__blink {
  animation: cb-blink 1.4s step-end infinite;
}

/* モバイル下部ナビ（デスクトップでは非表示） */
.cb-mobile-nav {
  display: none;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom, 0px));
}

.cb-mobile-nav__btn {
  flex: 1;
  min-height: 44px;
  margin: 0 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cb-mobile-nav__btn.is-active {
  color: var(--phosphor);
  border-color: var(--phosphor);
  background: rgba(61, 255, 138, 0.1);
  text-shadow: 0 0 6px var(--phosphor-dim);
}

.cb-log,
.cb-side {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

@media (max-width: 720px) {
  body {
    font-size: 13px;
  }

  .cb-app {
    max-width: none;
    border-left: none;
    border-right: none;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .cb-boot {
    padding: 16px;
    font-size: 12px;
  }

  .cb-boot__text {
    font-size: 12px;
    line-height: 1.6;
    max-width: 100%;
    overflow-x: auto;
  }

  .cb-boot__hint {
    left: 16px;
    right: 16px;
    text-align: center;
    font-size: 10px;
  }

  .cb-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .cb-brand {
    flex: 1;
    min-width: 0;
    gap: 8px;
  }

  .cb-brand strong {
    font-size: 13px;
    letter-spacing: 0.06em;
  }

  .cb-sub {
    display: none;
  }

  .cb-handle-box {
    width: 100%;
    order: 3;
  }

  .cb-handle-label {
    flex-shrink: 0;
  }

  .cb-handle-box input {
    flex: 1;
    width: auto;
    min-width: 0;
    min-height: 40px;
    font-size: 16px;
  }

  input,
  button {
    font-size: 16px;
  }

  .cb-top-link {
    padding: 6px 10px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .cb-body {
    position: relative;
    flex: 1;
    min-height: 0;
  }

  .cb-side {
    position: absolute;
    inset: 0;
    z-index: 6;
    width: 100%;
    border-right: none;
    padding: 10px 12px 16px;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    background: var(--panel);
  }

  .cb-app[data-mobile-view="channels"] .cb-side,
  .cb-app[data-mobile-view="who"] .cb-side {
    transform: translateX(0);
  }

  .cb-app[data-mobile-view="channels"] .cb-main,
  .cb-app[data-mobile-view="who"] .cb-main {
    visibility: hidden;
    pointer-events: none;
  }

  .cb-app[data-mobile-view="channels"] .cb-panel--who {
    display: none;
  }

  .cb-app[data-mobile-view="who"] .cb-panel--channels {
    display: none;
  }

  .cb-panel h2::before {
    content: none;
  }

  .cb-channels li,
  .cb-who li {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
  }

  .cb-channels li {
    justify-content: space-between;
  }

  .cb-ch-no {
    margin-right: 6px;
  }

  .cb-channel-title {
    padding: 8px 12px;
    font-size: 12px;
    gap: 4px;
  }

  .cb-channel-title::before,
  .cb-channel-title::after {
    content: none;
  }

  .cb-channel-mode {
    display: none;
  }

  .cb-channel-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cb-log {
    padding: 10px 12px;
  }

  .cb-line {
    flex-wrap: wrap;
    gap: 2px 8px;
    padding: 6px 0;
  }

  .cb-line .cb-time {
    width: 100%;
    font-size: 11px;
  }

  .cb-line .cb-name {
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .cb-line .cb-text {
    flex: 1;
    min-width: 55%;
  }

  .cb-form {
    gap: 6px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .cb-form input {
    min-height: 44px;
    font-size: 16px;
  }

  .cb-form button {
    flex-shrink: 0;
    min-height: 44px;
    min-width: 64px;
    padding: 8px 12px;
  }

  .cb-prompt {
    display: none;
  }

  .cb-status {
    padding: 0 12px 4px;
    font-size: 11px;
  }

  .cb-statusbar {
    font-size: 10px;
    gap: 6px;
    flex-wrap: wrap;
    padding: 4px 12px 6px;
  }

  .cb-mobile-nav {
    display: flex;
    gap: 0;
  }
}

@media (max-width: 720px) {
  .cb-scanlines {
    opacity: 0.35;
  }

  .cb-vignette {
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cb-scanlines,
  .cb-led.is-online,
  .cb-led.is-connecting,
  .cb-prompt,
  .cb-statusbar__blink,
  .cb-boot__cursor,
  .cb-line.is-typing .cb-text::after {
    animation: none;
  }

  .cb-boot.is-done,
  .cb-app,
  .cb-line.is-new {
    transition: none;
    animation: none;
  }
}
