:root {
  --bg: #000;
  --fg: #f5f5f5;
  --dim: #8a8a8a;
  --accent: #4c8dff;
  --panel: #151515;
  --line: #2a2a2a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- display ---------- */

#stage {
  position: fixed;
  inset: 0;
  padding: calc(var(--safe-t) + 3vmin) calc(var(--safe-r) + 4vmin)
           calc(var(--safe-b) + 3vmin) calc(var(--safe-l) + 4vmin);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

#text {
  width: max-content;
  max-width: none;
  text-align: center;
  white-space: pre;
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 10vmin; /* replaced by fitText() */
}

#text.placeholder {
  color: var(--dim);
  font-weight: 400;
  font-size: 5vmin !important;
  line-height: 1.4;
}

/* ---------- toolbar ---------- */

#bar {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  right: calc(var(--safe-r) + 12px);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  transition: opacity .35s ease;
}

#bar[hidden] { display: flex; opacity: 0; pointer-events: none; }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #c9302c;
  transition: background .3s;
}
.dot.online { background: #3fb950; }

button {
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
button:hover { background: rgba(255,255,255,.18); }
button:active { transform: scale(.97); }

/* ---------- menu ---------- */

#menu {
  position: fixed;
  top: calc(var(--safe-t) + 56px);
  right: calc(var(--safe-r) + 12px);
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-width: 230px;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
#menu button { text-align: left; background: transparent; border-color: transparent; }
#menu button:hover { background: rgba(255,255,255,.08); }
#menu p {
  margin: 6px 4px 2px;
  font-size: 12px;
  color: var(--dim);
  word-break: break-all;
}

/* ---------- editor ---------- */

#editor {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: #0b0b0b;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

#editor header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

#editStatus { font-size: 13px; color: var(--dim); }

#input {
  flex: 1;
  width: 100%;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 17px; /* >=16px so iOS does not zoom on focus */
  line-height: 1.5;
  padding: 16px;
}

/* ---------- gate ---------- */

#gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.card h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.card p { margin: 0; color: var(--dim); font-size: 15px; line-height: 1.5; }
.card button { padding: 12px 16px; }
#signInBtn, #newBoardBtn { background: var(--accent); border-color: transparent; color: #fff; }
#signInBtn:hover, #newBoardBtn:hover { filter: brightness(1.1); }

#picker { display: flex; flex-direction: column; gap: 10px; }

#boardList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 46vh;
  overflow-y: auto;
  text-align: left;
}

#boardList li {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111;
}

#boardList .open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
}
#boardList .open:hover { background: rgba(255,255,255,.06); }

#boardList .bname {
  font-size: 15px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#boardList .bmeta { font-size: 12px; color: var(--dim); }

#boardList .danger {
  border: 0;
  background: transparent;
  color: var(--dim);
  padding: 10px 12px;
  font-size: 14px;
}
#boardList .danger:hover { color: #ff6b6b; background: rgba(255,107,107,.10); }
#boardList li.confirming { border-color: #ff6b6b; }
#boardList li.confirming .bname { color: #ff6b6b; }

#admin { display: flex; flex-direction: column; gap: 12px; text-align: left; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111;
}
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

#userList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 34vh;
  overflow-y: auto;
}
#userList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111;
  font-size: 14px;
}
#userList .uemail { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#userList .tag {
  font-size: 11px;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}
#userList .danger { border: 0; background: transparent; color: var(--dim); padding: 4px 8px; font-size: 13px; }
#userList .danger:hover { color: #ff6b6b; background: rgba(255,107,107,.10); }
#userList li.confirming { border-color: #ff6b6b; }

#adminBack { align-self: flex-start; background: transparent; border-color: var(--line); font-size: 13px; }
#adminBtn { background: transparent; border-color: var(--line); font-size: 13px; align-self: center; }

#gateSignOut { align-self: center; background: transparent; border-color: var(--line); font-size: 13px; }
.row { display: flex; gap: 8px; }
.row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #111;
  color: var(--fg);
}
.row input:focus { outline: none; border-color: var(--accent); }

.hint { font-size: 13px; color: #6c6c6c; }

[hidden]:not(#bar) { display: none !important; }
