*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #08080f;
  --bg2:     #0d0d1a;
  --card:    #10101e;
  --card2:   #14142a;
  --border:  rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --accent:  #6366f1;
  --accent2: #818cf8;
  --grad:    linear-gradient(135deg, #5b5bd6, #7c6cf0);
  --danger:  #e05454;
  --success: #4ade80;
  --text:    #ececf5;
  --text2:   #7878a0;
  --text3:   #3a3a5c;
  --r:       8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, 'Segoe UI', 'Helvetica Neue', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; font-family: inherit; font-size: 14px; }
input, textarea { font-family: inherit; font-size: 16px; /* iOS zoom 防止 */ }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--text3); border-radius: 2px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--r);
  font-weight: 600; letter-spacing: 0.02em;
  transition: opacity .15s, transform .1s;
}
.btn-primary  { background: var(--grad); color: #fff; }
.btn-primary:hover { opacity: .88; transform: translateY(-1px); }
.btn-secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover { background: rgba(255,255,255,0.06); }
.btn-danger   { background: rgba(224,84,84,0.15); color: var(--danger); border: 1px solid rgba(224,84,84,0.3); }
.btn-danger:hover { background: rgba(224,84,84,0.25); }
.btn-ghost    { background: transparent; color: var(--text2); padding: 8px 14px; border-radius: var(--r); }
.btn-ghost:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ── Form ────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 7px; }
.form-label {
  font-size: 11px; color: var(--text2); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.form-input {
  background: var(--bg2); border: 1px solid var(--border2);
  color: var(--text); border-radius: var(--r);
  padding: 11px 14px; width: 100%;
  font-size: 16px; /* iOS zoom 防止 */
  transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--accent2); }
.form-input::placeholder { color: var(--text3); }
.form-error { color: var(--danger); font-size: 12px; min-height: 16px; }

/* ── Auth ────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 36px 32px;
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo h1 {
  font-size: 22px; font-weight: 700; letter-spacing: -0.02em;
  background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-logo p { color: var(--text2); margin-top: 6px; font-size: 13px; letter-spacing: 0.01em; }
.auth-tabs { display: flex; background: var(--bg2); border-radius: var(--r); padding: 3px; margin-bottom: 26px; }
.auth-tab {
  flex: 1; text-align: center; padding: 8px;
  border-radius: 6px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text2);
  transition: all .15s;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-hint { text-align: center; margin-top: 18px; color: var(--text3); font-size: 12px; }

/* 登録完了IDモーダル */
.id-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.8);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  backdrop-filter: blur(6px);
}
.id-modal-overlay.hidden { display: none; }
.id-modal {
  background: var(--card); border: 1px solid var(--border2);
  border-radius: 14px; padding: 36px 32px; text-align: center;
  max-width: 340px; width: 100%;
}
.id-modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text2); }
.id-display {
  font-size: 40px; font-weight: 700; letter-spacing: 0.1em;
  background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  margin: 16px 0;
}
.id-modal p { color: var(--text2); font-size: 13px; margin-bottom: 24px; line-height: 1.6; }

/* ── Lobby ───────────────────────────────────────────── */
.lobby-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 54px;
  background: var(--card); border-bottom: 1px solid var(--border);
  gap: 8px; flex-wrap: nowrap; min-width: 0;
}
.site-name {
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
  color: var(--text); flex-shrink: 0;
}
.header-right {
  display: flex; align-items: center; gap: 6px;
  min-width: 0; overflow: hidden;
}
.user-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg2); padding: 5px 10px; border-radius: 100px;
  border: 1px solid var(--border); font-size: 13px;
  min-width: 0; overflow: hidden;
}
.user-chip-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 100px;
}
.user-id { color: var(--text2); font-size: 11px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.admin-tag {
  background: rgba(99,102,241,0.2); color: var(--accent2);
  padding: 2px 6px; border-radius: 100px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.04em; flex-shrink: 0;
}
.lobby-body { padding: 24px; max-width: 900px; margin: 0 auto; }
.lobby-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.lobby-toolbar h2 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.room-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  transition: border-color .15s, transform .1s;
}
.room-card:hover { border-color: var(--border2); transform: translateY(-2px); }
.room-card-name { font-size: 15px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.01em; }
.room-card-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 12px; color: var(--text2); }
.count-tag {
  padding: 2px 9px; border-radius: 100px; font-size: 12px; font-weight: 600;
}
.count-ok   { background: rgba(74,222,128,0.12); color: var(--success); }
.count-full { background: rgba(224,84,84,0.12);  color: var(--danger); }
.room-actions { display: flex; gap: 8px; }
.empty-state { text-align: center; padding: 70px 20px; color: var(--text2); }
.empty-state h3 { color: var(--text); font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.empty-state p  { font-size: 13px; }

/* ── Modal ───────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; backdrop-filter: blur(4px); }
.modal-overlay.hidden { display: none; }
.modal { background: var(--card); border: 1px solid var(--border2); border-radius: 12px; padding: 28px; width: 100%; max-width: 400px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close { background: var(--bg2); border: none; color: var(--text2); width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 14px; }
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

/* ── Room ────────────────────────────────────────────── */
.room-page { display: flex; flex-direction: column; height: 100vh; }
.room-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 54px;
  background: var(--card); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.room-title { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.room-meta { display: flex; align-items: center; gap: 10px; }
.room-count-tag { background: var(--bg2); padding: 3px 10px; border-radius: 100px; font-size: 12px; color: var(--text2); border: 1px solid var(--border); }
.my-name-tag { font-size: 12px; color: var(--text2); }

.peer-grid { flex: 1; display: flex; flex-wrap: wrap; gap: 10px; padding: 16px; align-content: flex-start; overflow-y: auto; }
.peer-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px 14px;
  width: 140px; display: flex; flex-direction: column; align-items: center; gap: 10px;
  transition: border-color .25s;
}
.peer-card.self    { border-color: rgba(99,102,241,0.4); }
.peer-card.speaking{ border-color: rgba(74,222,128,0.5); box-shadow: 0 0 0 3px rgba(74,222,128,0.08); }
.peer-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: #fff;
  letter-spacing: 0;
}
.peer-name { font-size: 13px; font-weight: 600; text-align: center; word-break: break-all; }
.peer-sub  { font-size: 11px; color: var(--text2); }
.muted-tag { font-size: 11px; color: var(--danger); font-weight: 600; letter-spacing: 0.04em; }

.room-controls {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 16px; background: var(--card); border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.ctrl-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card2); border: 1px solid var(--border2);
  border-radius: 12px; padding: 12px 20px; cursor: pointer;
  transition: all .15s; color: var(--text);
}
.ctrl-btn:hover { background: rgba(255,255,255,0.06); }
.ctrl-btn.active { background: rgba(99,102,241,0.2); border-color: rgba(99,102,241,0.5); color: var(--accent2); }
.ctrl-btn.leave  { background: rgba(224,84,84,0.1); border-color: rgba(224,84,84,0.3); color: var(--danger); }
.ctrl-btn.leave:hover { background: rgba(224,84,84,0.2); }
.ctrl-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.ctrl-icon  { font-size: 18px; line-height: 1; }

/* ── Admin ───────────────────────────────────────────── */
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 58px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
.admin-header h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.admin-body { padding: 24px; max-width: 1000px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 130px; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; text-align: center;
}
.stat-num  { font-size: 36px; font-weight: 700; letter-spacing: -0.02em; background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-label{ font-size: 12px; color: var(--text2); margin-top: 4px; }
.section-title { font-size: 14px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text2); margin-bottom: 12px; }
.data-table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; padding: 10px 16px; background: var(--bg2); color: var(--text2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.data-table td { padding: 12px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table .id-cell { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text2); }
.empty-row td { text-align: center; padding: 28px; color: var(--text2); }

/* ── Toast ───────────────────────────────────────────── */
.toast-box { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 999; pointer-events: none; }
.toast {
  background: var(--card2); border: 1px solid var(--border2);
  border-radius: var(--r); padding: 10px 16px; font-size: 13px;
  max-width: 300px; animation: tIn .2s ease; pointer-events: auto;
}
.toast.err  { border-left: 3px solid var(--danger); }
.toast.ok   { border-left: 3px solid var(--success); }
.toast.info { border-left: 3px solid var(--accent2); }
@keyframes tIn { from { opacity:0; transform: translateX(10px); } to { opacity:1; transform: none; } }

/* ── Misc ────────────────────────────────────────────── */
.flex-row { display: flex; align-items: center; gap: 8px; }
.divider  { height: 1px; background: var(--border); margin: 4px 0; }

@media (max-width: 480px) {
  .peer-card { width: calc(50% - 5px); }
  .auth-card { padding: 28px 20px; }
}
