:root {
  --bg: #1e2530;
  --panel: #2a3242;
  --panel-light: #343e52;
  --border: #454f63;
  --text: #e8ecf3;
  --text-dim: #9aa5b8;
  --accent: #4a90d9;
  --danger: #d9534f;
  --ok: #5cb85c;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
}

/* ---------- 認証ページ ---------- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 28px 24px;
  border: 1px solid var(--border);
}

.logo {
  text-align: center;
  margin: 0 0 4px;
  font-size: 1.6rem;
  letter-spacing: 0.05em;
}

.tagline {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 20px;
}

.tabs {
  display: flex;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  background: var(--panel);
  color: var(--text-dim);
  border: none;
  font-size: 0.9rem;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
}

.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

.tab-panel label {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tab-panel input, .field-row select {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
  font-size: 1rem;
}

.primary-btn {
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  margin-top: 4px;
}
.primary-btn:active { opacity: 0.85; }

.ghost-btn {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}

.danger-btn {
  background: var(--danger);
  color: #fff;
  border: none;
}

.avatar-picker { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.avatar-picker-label { font-size: 0.78rem; color: var(--text-dim); }

.group-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.group-tab-btn {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text-dim);
  font-size: 0.76rem;
}
.group-tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.avatar-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
  padding: 2px;
  /* グループごとに件数が違っても、切り替えでページの高さが動かないよう内側だけスクロールさせる */
}
.avatar-thumb-btn {
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--panel-light);
  padding: 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
}
.avatar-thumb-btn canvas, .avatar-thumb-btn img { display: block; width: 68px; height: 68px; image-rendering: pixelated; object-fit: contain; }
.avatar-thumb-btn.room-thumb canvas, .avatar-thumb-btn.room-thumb img { width: 140px; height: 105px; }
.avatar-thumb-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(74,144,217,0.4); }
.avatar-thumb-btn .avatar-thumb-label { display: block; font-size: 0.6rem; color: var(--text-dim); text-align: center; margin-top: 2px; }

.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-top: 12px;
  text-align: center;
}

/* ---------- ダッシュボード ---------- */

.dash-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.dash-header h1 { font-size: 1.3rem; margin: 0; }

.me-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.avatar-dot {
  width: 18px; height: 18px;
  border-radius: 4px;
  display: inline-block;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.15);
}

.notif-banner {
  background: #3a3320;
  border: 1px solid #6b5c1f;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.notif-banner .notif-item { margin-bottom: 6px; }
.notif-banner .notif-item:last-child { margin-bottom: 0; }
.notif-banner a { color: #ffd54a; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 1rem;
  margin: 0 0 12px;
  color: var(--text-dim);
}

.field-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.field-row input {
  flex: 1;
  min-width: 140px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
}

.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel-light);
  border-radius: 8px;
  padding: 12px;
  text-decoration: none;
  color: var(--text);
}

.room-item .room-name { font-weight: bold; }
.room-item .room-sub { font-size: 0.78rem; color: var(--text-dim); }
.room-badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.7rem;
  padding: 2px 8px;
}

.empty-hint { color: var(--text-dim); font-size: 0.85rem; }

/* ---------- ルーム画面 ---------- */

.room-body { height: 100%; overflow: hidden; }

.room-wrap {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.stage-col {
  flex: 1 1 60%;
  display: flex;
  flex-direction: column;
  background: #10141c;
  min-width: 0;
}

.stage-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
}

.stage-topbar .room-title { font-weight: bold; font-size: 0.95rem; }
.stage-topbar .peer-status { font-size: 0.78rem; color: var(--text-dim); }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.icon-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.bell.rung { animation: bell-flash 0.6s ease 2; }

@keyframes bell-flash {
  0%, 100% { background: var(--panel-light); }
  50% { background: #ffd54a; color: #222; }
}

#theme-select {
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-light);
  color: var(--text);
  font-size: 0.8rem;
}

.chat-bg-swatches { display: flex; gap: 5px; }
.chat-bg-swatch {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.chat-bg-swatch.selected { border-color: var(--chat-text-dim, #888); box-shadow: 0 0 0 1px rgba(0,0,0,0.15); }

.stage-canvas-holder {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
  background:
    radial-gradient(ellipse at center, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0) 60%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.02) 0 2px, transparent 2px 18px),
    #171c28;
}

#stage {
  background: #26314a;
  image-rendering: pixelated;
  width: min(100%, 860px);
  height: auto;
  max-height: 100%;
  aspect-ratio: 4 / 3;
  touch-action: none;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.05);
}

.dpad {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 4px;
  opacity: 0.85;
}

.dpad button {
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
}
.dpad button:active { background: var(--accent); }
.dpad .dpad-up { grid-column: 2; grid-row: 1; }
.dpad .dpad-left { grid-column: 1; grid-row: 2; }
.dpad .dpad-down { grid-column: 2; grid-row: 3; }
.dpad .dpad-right { grid-column: 3; grid-row: 2; }

.mic-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}

/* ---- チャット：LINE風（背景も含めて明るいトーン） ---- */
:root {
  --line-green: #8de055;
  --line-green-text: #0c3d0f;
  --line-bubble-light: #ffffff;
  --line-bubble-light-text: #1a1f29;
  --chat-bg: #e5e5e5;
  --chat-header-bg: #ffffff;
  --chat-text: #1a1f29;
  --chat-text-dim: #7a828c;
  --chat-border: #d9dbdd;
  --chat-field-bg: #f0f1f2;
}

.chat-col {
  flex: 1 1 40%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  border-left: 1px solid var(--chat-border);
  min-width: 260px;
  color: var(--chat-text);
}

.chat-header {
  flex-shrink: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--chat-header-bg);
  color: var(--chat-text);
}

.chat-header select {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--chat-border);
  background: #ffffff;
  color: var(--chat-text);
  font-size: 0.78rem;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--chat-bg);
}
.chat-messages:empty::before {
  content: "まだメッセージがありません。\A最初のひとことを送ってみましょう。";
  white-space: pre-line;
  margin: auto;
  text-align: center;
  color: var(--chat-text-dim);
  font-size: 0.82rem;
  line-height: 1.7;
}

.msg {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 88%;
  align-self: flex-start;
}
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }

.msg .avatar-circle {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--panel-light);
}
.msg .avatar-circle canvas { width: 100%; height: 100%; image-rendering: pixelated; }

.msg .bubble-col { display: flex; flex-direction: column; min-width: 0; }
.msg.mine .bubble-col { align-items: flex-end; }
.msg.theirs .bubble-col { align-items: flex-start; }

.msg .bubble-row { display: flex; align-items: flex-end; gap: 5px; }
.msg.mine .bubble-row { flex-direction: row-reverse; }

.msg .bubble {
  padding: 8px 12px;
  border-radius: 17px;
  font-size: 0.9rem;
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 100%;
}
.msg.mine .bubble { background: var(--line-green); color: var(--line-green-text); border-bottom-right-radius: 4px; }
.msg.theirs .bubble { background: var(--line-bubble-light); color: var(--line-bubble-light-text); border-bottom-left-radius: 4px; }
.msg.deleted .bubble { background: transparent; border: 1px dashed var(--chat-border); color: var(--chat-text-dim); font-style: italic; border-radius: 14px; }

.msg .bubble.image { background: transparent; padding: 0; border-radius: 12px; overflow: hidden; line-height: 0; }
.msg .bubble-image { display: block; max-width: 200px; max-height: 260px; width: auto; height: auto; border-radius: 12px; cursor: pointer; }

.msg .bubble a { color: inherit; text-decoration: underline; }

.link-preview {
  font-size: 0.72rem;
  color: var(--chat-text-dim);
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  padding: 4px 8px;
  margin-top: 2px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg .msg-time { font-size: 0.65rem; color: var(--chat-text-dim); white-space: nowrap; margin-bottom: 3px; }
.msg .msg-edited-tag { font-size: 0.62rem; color: var(--chat-text-dim); margin-top: 2px; }

.msg .msg-actions { display: none; gap: 6px; margin-top: 3px; }
.msg.mine:hover .msg-actions, .msg.mine.editing .msg-actions { display: flex; }
.msg .msg-actions button {
  border: 1px solid var(--chat-border);
  background: #ffffff;
  color: var(--chat-text-dim);
  border-radius: 4px;
  font-size: 0.68rem;
  padding: 2px 6px;
}

.chat-input-row {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-header-bg);
}

.chat-input-row {
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  resize: vertical;
  border-radius: 16px;
  border: 1px solid var(--chat-border);
  background: var(--chat-field-bg);
  color: var(--chat-text);
  padding: 14px 18px;
  font-size: 1rem;
  line-height: 1.5;
  min-height: 100px;
  max-height: 220px;
}

.chat-input-row button[type="submit"] { background: var(--line-green); color: var(--line-green-text); border-radius: 18px; }

.notes-panel {
  flex-shrink: 0;
  border-top: 1px solid var(--chat-border);
  padding: 10px 12px;
  max-height: 34%;
  overflow-y: auto;
  background: var(--chat-bg);
}

.notes-panel h3 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--chat-text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.notes-panel .ghost-btn, .chat-input-row .ghost-btn { border-color: var(--chat-border); color: var(--chat-text); background: #ffffff; }

.note-item {
  background: #fff8e1;
  border: 1px solid #f0dfa0;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.82rem;
  margin-bottom: 6px;
  position: relative;
  color: #5a4a1f;
}
.note-item .note-meta { font-size: 0.68rem; color: #9a7d2e; margin-bottom: 4px; }
.note-item button {
  border: none;
  background: rgba(0,0,0,0.08);
  color: inherit;
  border-radius: 4px;
  font-size: 0.68rem;
  padding: 2px 6px;
  margin-top: 4px;
}

/* ---------- モバイル ---------- */

@media (max-width: 760px) {
  .room-wrap { flex-direction: column; }
  .stage-col { flex: 0 1 auto; max-height: 40vh; max-height: 40dvh; }
  .chat-col {
    flex: 1 1 auto;
    min-height: 0;
    max-width: none;
    border-left: none;
    border-top: 1px solid var(--chat-border, var(--border));
    min-width: 0;
  }
  .dpad {
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 52px);
  }
  .stage-topbar { padding: 6px 8px; gap: 6px; }
  .stage-topbar .icon-btn { padding: 7px 8px; font-size: 0.76rem; }
  .stage-topbar .room-title { font-size: 0.88rem; }
  #theme-select { padding: 6px; font-size: 0.72rem; max-width: 92px; }
  .chat-header { padding: 8px 10px; flex-wrap: wrap; gap: 6px; }
  .notes-panel { max-height: 22vh; max-height: 22dvh; padding: 8px 10px; }
  .chat-input-row textarea {
    font-size: 16px; /* iOSの自動ズームを防ぐ */
    min-height: 64px;
    max-height: 120px;
  }
  .msg { max-width: 92%; }

  .dash-wrap { padding: 12px; }
  .dash-header { flex-wrap: wrap; gap: 8px; }
  .me-badge { flex-wrap: wrap; font-size: 0.8rem; }
  .avatar-grid { justify-content: center; }
}

@media (max-width: 420px) {
  .stage-topbar .icon-btn span.btn-label { display: none; }
}
