:root {
  --ink: #16202b;
  --muted: #5b6b7c;
  --bg: #eef2f7;
  --card: #ffffff;
  --line: #dbe2ea;
  --brand: #1f3a5f;
  --brand-soft: #e8eef6;
  --accent: #b45309;
  --accent-soft: #fdf3e3;
  --ok: #0f766e;
  --danger: #b91c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 48, 0.06), 0 6px 20px rgba(16, 32, 48, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans",
    "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

/* hidden 属性は必ず効かせる（display指定より優先） */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body.participant {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ── 起動・エラー画面 ─────────────────────────── */
.boot-screen,
.fatal {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.fatal h1 {
  font-size: 20px;
  color: var(--ink);
  margin: 0;
}

.fatal p {
  margin: 0;
  line-height: 1.7;
}

/* ── アプリ全体 ───────────────────────────────── */
.app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  background: var(--card);
  box-shadow: 0 0 0 1px rgba(22, 32, 43, 0.04);
}

.app-header {
  flex: none;
  background: var(--brand);
  color: #fff;
  padding: 12px 16px 10px;
}

.app-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
}

.event-name {
  margin: 2px 0 0;
  font-size: 19px;
  line-height: 1.35;
  font-weight: 700;
  word-break: break-word;
  white-space: pre-wrap;
}

.app-header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  white-space: nowrap;
}

.pill.pill-before {
  background: #fde68a;
  color: #713f12;
}

.pill.pill-active {
  background: #bbf7d0;
  color: #14532d;
}

.pill.pill-ended {
  background: #e2e8f0;
  color: #334155;
}

.pill.pill-expired {
  background: #fecaca;
  color: #7f1d1d;
}

.event-time {
  font-size: 12px;
  opacity: 0.85;
  line-height: 1.5;
}

.banner {
  flex: none;
  padding: 9px 16px;
  font-size: 13px;
  line-height: 1.6;
  background: var(--accent-soft);
  color: #7c4a03;
  border-bottom: 1px solid #f3ddb8;
}

.banner.banner-error {
  background: #fef2f2;
  color: #991b1b;
  border-bottom-color: #fecaca;
}

.banner.banner-ok {
  background: #ecfdf5;
  color: #065f46;
  border-bottom-color: #a7f3d0;
}

/* ── レイアウト ───────────────────────────────── */
.layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.announcements {
  flex: none;
  max-height: 34vh;
  border-bottom: 1px solid var(--line);
  background: #fffdf8;
}

.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px 8px;
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.chat .panel-title {
  color: var(--brand);
}

.count {
  font-size: 11.5px;
  color: var(--muted);
}

.ann-list {
  overflow-y: auto;
  padding: 0 16px 12px;
  min-height: 0;
}

.announcements.collapsed .ann-list {
  display: none;
}

.announcements.collapsed {
  max-height: none;
}

.ann-item {
  border-left: 3px solid #f0c27b;
  background: #fff;
  border-radius: 0 10px 10px 0;
  padding: 8px 12px;
  margin: 0 0 8px;
  box-shadow: 0 1px 1px rgba(16, 32, 48, 0.04);
}

.ann-item:last-child {
  margin-bottom: 0;
}

.ann-body {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.ann-time {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
}

/* ── チャット ─────────────────────────────────── */
.chat {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--bg);
}

.chat-head {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 12px 6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.empty {
  margin: 8px 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-bottom: 10px;
}

.msg-meta {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0 0 2px 4px;
  font-size: 11px;
  color: var(--muted);
}

.msg-nick {
  font-weight: 700;
  color: var(--brand);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.msg-bubble {
  max-width: 88%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px 14px 14px 14px;
  padding: 8px 12px;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(16, 32, 48, 0.04);
}

.msg.is-new .msg-bubble {
  animation: pop 160ms ease-out;
}

@keyframes pop {
  from {
    transform: translateY(3px);
    opacity: 0.4;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.jump-new {
  position: absolute;
  right: 14px;
  bottom: 104px;
  z-index: 3;
  border: 0;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  box-shadow: 0 6px 16px rgba(16, 32, 48, 0.25);
}

/* ── 入力欄 ───────────────────────────────────── */
.composer {
  flex: none;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

.field {
  display: block;
}

.nickname-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.field-label {
  font-size: 11.5px;
  color: var(--muted);
  flex: none;
}

input[type="text"],
textarea {
  font-family: inherit;
  font-size: 16px; /* iOS で拡大されないように 16px 以上 */
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  width: 100%;
  min-width: 0;
}

input[type="text"]:focus,
textarea:focus,
.btn:focus-visible,
.btn-ghost:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.message-field {
  flex: 1;
  min-width: 0;
}

textarea {
  resize: none;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
}

.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  min-height: 44px;
  background: var(--brand);
  color: #fff;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  flex: none;
}

.btn-secondary {
  background: #fff;
  color: var(--brand);
  border-color: var(--line);
}

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

.btn-ghost {
  font-family: inherit;
  font-size: 12px;
  color: var(--brand);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
}

.composer-note {
  margin: 6px 2px 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
  min-height: 1em;
}

.composer-note.is-error {
  color: var(--danger);
}

.app-footer {
  flex: none;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 6px 16px;
  font-size: 11.5px;
  color: var(--muted);
}

.app-footer summary {
  cursor: pointer;
  padding: 2px 0;
}

.app-footer ul {
  margin: 6px 0 8px;
  padding-left: 18px;
  line-height: 1.7;
}

/* 終了・期限切れ時の中央メッセージ */
.locked-note {
  margin: 0;
  padding: 18px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}

@media (min-width: 720px) {
  body.participant {
    background: #e3e9f1;
  }
  .app {
    margin: 0 auto;
    height: 100dvh;
  }
  .announcements {
    max-height: 38vh;
  }
}

/* 既読（自分の投稿のみ） */
.msg-read {
  font-size: 10.5px;
  color: var(--ok);
  font-weight: 700;
  margin-left: 2px;
}
