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

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252836;
  --border: #2e3144;
  --text: #e4e5ea;
  --text-dim: #9496a1;
  --text-muted: #6b6d7b;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* Landing */
.landing {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(99,102,241,0.15), transparent 60%),
              var(--bg);
}

.landing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  width: 420px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 8px;
}

.logo h1 {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-dim);
  margin-bottom: 28px;
  font-size: 0.9rem;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--primary);
}

.color-picker {
  display: flex;
  gap: 10px;
}

.color-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.color-btn.active {
  border-color: white;
  transform: scale(1.15);
}

.color-btn:hover {
  transform: scale(1.1);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
  padding: 12px 20px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover { background: var(--border); }

.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.divider span { padding: 0 14px; }

.join-row {
  display: flex;
  gap: 10px;
}

.join-row input { flex: 1; }
.join-row .btn-secondary { flex-shrink: 0; }

/* Auth */
/* File input */
.file-input-styled {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s;
}

.file-input-styled:hover,
.file-input-styled:focus {
  border-color: var(--primary);
}

.file-input-styled::file-selector-button {
  padding: 6px 14px;
  margin-right: 12px;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Lobby */
.lobby-card {
  width: 480px;
}

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

.lobby-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.room-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.room-card:hover {
  border-color: var(--primary);
  background: rgba(99,102,241,0.08);
}

.room-card .room-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(99,102,241,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.room-card .room-meta {
  flex: 1;
  min-width: 0;
}

.room-card .room-meta .room-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-card .room-meta .room-card-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.room-delete-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}

.room-delete-btn:hover {
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.3);
  color: var(--danger);
}

.room-card .room-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}

.room-name-display {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.text-muted { color: var(--text-muted); font-size: 0.85rem; }

/* Waiting */
.waiting-icon { font-size: 3rem; margin-bottom: 16px; }
.loader {
  width: 32px; height: 32px; margin: 20px auto;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pending panel (owner sees join requests) */
.pending-panel {
  position: fixed;
  top: 64px;
  right: 16px;
  width: 320px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1001;
  padding: 16px;
}

.pending-panel h4 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.pending-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.pending-item:last-child { border-bottom: none; }

.pending-item .pending-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.pending-item .pending-actions {
  display: flex;
  gap: 6px;
}

.pending-item .pending-actions button {
  padding: 4px 12px;
  border-radius: 6px;
  border: none;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.pending-item .approve-btn {
  background: rgba(16,185,129,0.2);
  color: var(--success);
}

.pending-item .reject-btn {
  background: rgba(239,68,68,0.15);
  color: var(--danger);
}

.auth-error {
  padding: 10px 14px;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.auth-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 16px;
}

.user-badge {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  color: white;
}

/* Board Page */
.board-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Toolbar */
.toolbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  flex-shrink: 0;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-small { display: flex; }

.room-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* (room-id removed — no longer used) */

.member-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  background: rgba(99,102,241,0.15);
  color: var(--primary);
  border-radius: 20px;
}

.toolbar-center {
  display: flex;
  gap: 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.tool-btn:hover {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

.toolbar-right {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}

/* Board */
.board {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  cursor: default;
}

/* Dot grid rendered on the transform layer so it pans/zooms with content */
.items-layer::before {
  content: '';
  position: absolute;
  /* cover a huge area so dots are always visible when panning */
  left: -10000px; top: -10000px;
  width: 20000px; height: 20000px;
  background:
    radial-gradient(circle at 1px 1px, rgba(99,102,241,0.07) 1px, transparent 0);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: -1;
}

.cursors-layer,
.items-layer {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
  /* no fixed size — items positioned absolutely inside */
}

.cursors-layer {
  pointer-events: none;
  z-index: 9999;
}

.board.panning {
  cursor: grab;
}

/* Zoom controls in toolbar */
.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.zoom-controls .icon-btn {
  width: 30px;
  height: 30px;
  font-size: 1rem;
}

.zoom-level {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  min-width: 40px;
  text-align: center;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: all 0.15s;
}

.zoom-level:hover {
  background: var(--surface2);
  color: var(--text);
}

/* Board Items */
.board-item {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: grab;
  transition: box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}

.board-item:hover {
  box-shadow: 0 0 0 2px var(--primary), var(--shadow);
}

.board-item.dragging {
  cursor: grabbing;
  opacity: 0.9;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.item-header .item-type {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.item-header .item-actions {
  display: flex;
  gap: 4px;
}

.item-header .item-actions button {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  transition: all 0.15s;
}

.item-header .item-actions button:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text);
}

.item-header .item-actions button.delete-btn:hover {
  background: rgba(239,68,68,0.2);
  color: var(--danger);
}

.item-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* YouTube items: body holds the player, controls sit below */
.board-item .youtube-controls ~ .item-body,
.board-item .item-body + .youtube-controls { /* handled by flex order */ }

/* YouTube */
.item-body iframe,
.yt-player-container {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.yt-player-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* YouTube controls bar — always visible below the video */
.youtube-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.sync-btn {
  padding: 4px 10px;
  background: rgba(99,102,241,0.2);
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: 4px;
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.sync-btn:hover {
  background: rgba(99,102,241,0.35);
  border-color: var(--primary);
}

.sync-seek {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}

.seek-input {
  width: 64px;
  padding: 3px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.75rem;
  font-family: 'Inter', monospace;
  outline: none;
  transition: border-color 0.15s;
}

.seek-input:focus {
  border-color: var(--primary);
}

.seek-input::placeholder {
  color: var(--text-muted);
}

.sync-seek-btn {
  background: rgba(245,158,11,0.2);
  border-color: rgba(245,158,11,0.3);
  color: var(--warning);
}

.sync-seek-btn:hover {
  background: rgba(245,158,11,0.35);
  border-color: var(--warning);
}

.yt-current-time {
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'Inter', monospace;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}

/* Image */
.item-body img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: var(--bg);
}

/* Note */
.item-body textarea {
  width: 100%;
  height: 100%;
  padding: 12px;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  font-family: inherit;
}

/* Link */
.link-card {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.link-card .link-url {
  color: var(--primary);
  font-size: 0.85rem;
  word-break: break-all;
  text-decoration: none;
}

.link-card .link-url:hover { text-decoration: underline; }

.link-card .link-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.link-card .link-desc {
  color: var(--text-dim);
  font-size: 0.8rem;
  flex: 1;
  overflow: hidden;
}

/* File card */
.file-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  height: 100%;
}

.file-icon {
  width: 48px;
  height: 48px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.file-ext {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.file-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.file-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.file-download {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(99,102,241,0.15);
  border-radius: 8px;
  color: var(--primary);
  text-decoration: none;
  flex-shrink: 0;
  transition: all 0.15s;
}

.file-download:hover {
  background: rgba(99,102,241,0.3);
}

/* PDF */
.item-body .pdf-embed {
  width: 100%;
  height: 100%;
  border: none;
}

/* Resize Handle */
.resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
  z-index: 2;
}

.resize-handle::after {
  content: '';
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s;
}

.board-item:hover .resize-handle::after { opacity: 1; }

/* Cursors */
.remote-cursor {
  position: absolute;
  pointer-events: none;
  transition: all 0.1s ease-out;
  z-index: 10000;
}

.remote-cursor svg {
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

.cursor-label {
  position: absolute;
  left: 18px;
  top: 16px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  color: white;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 10001;
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10002;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 440px;
  max-width: 90vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

.modal-content h3 {
  font-size: 1.1rem;
  margin-bottom: 20px;
}

.modal-content .form-group { margin-bottom: 16px; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

.modal-actions .btn-primary {
  width: auto;
  padding: 10px 24px;
}

.modal-actions .btn-secondary {
  padding: 10px 20px;
}

/* Drop Overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 10003;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: fade-in 0.2s ease;
}

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

.drop-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--primary);
  text-align: center;
}

.drop-overlay-content svg {
  color: var(--primary);
  animation: pulse-icon 1.5s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.08); opacity: 1; }
}

.drop-overlay-content p {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.drop-overlay-content span {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Touch: prevent rubber-band / pull-to-refresh on board */
.board {
  touch-action: none;
  -webkit-overflow-scrolling: auto;
  outline: none;
}

.board-item.dragging {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Touch-specific: larger hit targets */
@media (pointer: coarse) {
  .item-header {
    padding: 12px 14px;
    min-height: 44px;
  }

  .item-header .item-actions button {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
  }

  .resize-handle {
    width: 28px;
    height: 28px;
  }

  .resize-handle::after {
    opacity: 0.6;
    width: 12px;
    height: 12px;
    bottom: 6px;
    right: 6px;
  }

  .sync-btn {
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  .seek-input {
    padding: 6px 10px;
    font-size: 0.85rem;
    width: 72px;
  }

  .tool-btn {
    padding: 10px 12px;
  }

  .icon-btn {
    width: 40px;
    height: 40px;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .toolbar-center .tool-btn span { display: none; }
  .tool-btn { padding: 8px 10px; }
  .toolbar { padding: 0 8px; }
  .zoom-controls { margin-left: 6px; padding-left: 6px; }
}

/* Added by user indicator */
.added-by {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-left: 8px;
}
