:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-soft: #f0f4f1;
  --surface-warm: #f7f1e8;
  --ink: #16211d;
  --muted: #66736d;
  --line: #d9e0dc;
  --green: #2f8f6f;
  --green-strong: #24745a;
  --green-soft: #dff1e9;
  --coral: #c85f4b;
  --coral-soft: #f8e4df;
  --amber: #c78a26;
  --amber-soft: #f6ead4;
  --blue: #326c9c;
  --blue-soft: #e3edf5;
  --shadow-soft: 0 16px 42px rgba(28, 43, 36, 0.1);
  --shadow-menu: 0 24px 60px rgba(28, 43, 36, 0.18);
  --radius: 8px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(245, 246, 244, 0.98) 260px),
    var(--bg);
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.app-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(22, 33, 29, 0.14);
  flex: 0 0 auto;
}

.brand-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.brand-title {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand-titlebar {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 8px;
  min-width: 0;
}

.brand-version {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand-version:empty {
  display: none;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.profile-shell {
  position: relative;
}

.profile-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(28, 43, 36, 0.08);
}

.profile-button:hover,
.profile-button[aria-expanded="true"] {
  border-color: rgba(47, 143, 111, 0.28);
  background: var(--green-soft);
}

.profile-button:focus-visible,
.room-tab:focus-visible,
.send-button:focus-visible {
  outline: 3px solid rgba(47, 143, 111, 0.28);
  outline-offset: 2px;
}

.profile-avatar {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--surface-soft);
  border: 1px solid rgba(47, 143, 111, 0.24);
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  display: block;
}

.profile-summary {
  display: grid;
  gap: 2px;
  min-width: 44px;
  text-align: left;
  line-height: 1.05;
}

.profile-summary span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.profile-summary strong {
  font-size: 13px;
  font-weight: 900;
}

.profile-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 92px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-menu);
  padding: 12px;
}

.profile-panel[hidden] {
  display: none;
}

.profile-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.profile-section + .profile-section {
  margin-top: 10px;
}

.profile-score {
  background: linear-gradient(180deg, var(--green-soft), #fff);
  border-color: rgba(47, 143, 111, 0.22);
}

.profile-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.profile-section-head.compact {
  margin-bottom: 10px;
}

.profile-section-head p,
.room-label,
.mission-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.15;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-section-head strong {
  font-size: 25px;
  line-height: 1;
  letter-spacing: 0;
}

.app-main {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow: hidden;
}

.mobile-room-tabs {
  display: none;
}

.rooms-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 18px;
  min-width: 0;
  min-height: 0;
}

.room-panel {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

/* 固定エリア: 上から ヘッダー / (謎解きの)ヒント / 入力欄 はスクロールせず固定 */
.room-header,
.mission-strip,
.composer {
  flex: 0 0 auto;
}

.room-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  min-height: 96px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.room-header h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: 0;
}

.room-metrics {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.room-metrics span,
.unlock-list span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.normal-room .room-metrics span:first-child {
  background: var(--green-soft);
  color: var(--green-strong);
  border-color: rgba(47, 143, 111, 0.2);
}

.mission-room .room-metrics span:first-child {
  background: var(--coral-soft);
  color: #9d3f31;
  border-color: rgba(200, 95, 75, 0.22);
}

.mission-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 74px;
  gap: 14px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-warm);
}

.mission-strip h2 {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.mission-strip p {
  margin: 0;
  color: #5f5345;
  font-size: 14px;
  line-height: 1.55;
}

.mission-score {
  width: 74px;
  min-height: 74px;
  border: 1px solid rgba(199, 138, 38, 0.24);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  display: grid;
  place-items: center;
  align-content: center;
}

.mission-score span {
  display: block;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  color: var(--amber);
}

.mission-score small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.feed {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.message-mark {
  width: 10px;
  height: 10px;
  margin-top: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.message-mark.blue {
  background: var(--blue);
  box-shadow: 0 0 0 4px var(--blue-soft);
}

.message-mark.coral {
  background: var(--coral);
  box-shadow: 0 0 0 4px var(--coral-soft);
}

.message-mark.amber {
  background: var(--amber);
  box-shadow: 0 0 0 4px var(--amber-soft);
}

.message-content {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.message.is-self .message-content {
  background: #ecf6f1;
  border-color: rgba(47, 143, 111, 0.24);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.message-meta span:first-child {
  color: var(--ink);
}

.message-content p {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.composer textarea {
  width: 100%;
  min-width: 0;
  max-height: 132px;
  min-height: 52px;
  resize: vertical;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  line-height: 1.45;
  outline: none;
}

.composer textarea:focus {
  border-color: rgba(47, 143, 111, 0.62);
  box-shadow: 0 0 0 3px rgba(47, 143, 111, 0.13);
}

.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 92px;
  height: 52px;
  padding: 0 16px;
  border: 1px solid rgba(47, 143, 111, 0.34);
  border-radius: var(--radius);
  background: var(--green);
  color: #fff;
  font-size: 14px;
  font-weight: 850;
  cursor: pointer;
}

.send-button:hover {
  background: var(--green-strong);
}

.mission-send {
  border-color: rgba(200, 95, 75, 0.34);
  background: var(--coral);
}

.mission-send:hover {
  background: #a84b3a;
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.progress-fill {
  display: block;
  width: 64%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber));
}

.unlock-copy {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  line-height: 1.45;
}

.rank-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 14px 0 0;
  list-style: none;
}

.rank-list li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  font-size: 13px;
}

.rank-list li.is-me {
  border-color: rgba(47, 143, 111, 0.25);
  background: var(--green-soft);
}

.rank-list li.rank-empty {
  display: block;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  background: var(--surface-soft);
}

.rank-list span {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-weight: 900;
}

.rank-list b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-list time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.unlock-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.unlock-list span {
  min-height: 32px;
  background: var(--surface-soft);
}

.mission-log ul {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.mission-log li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.mission-log b {
  color: var(--ink);
}

.mission-log span {
  text-align: right;
  font-weight: 800;
}

@media (max-width: 940px) {
  .rooms-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }

  .room-panel {
    height: 100%;
  }
}

@media (max-width: 720px) {
  .app-header {
    min-height: auto;
    padding: 11px 12px;
  }

  .brand-icon {
    width: 38px;
    height: 38px;
  }

  .brand-subtitle,
  .profile-summary {
    display: none;
  }

  .profile-button {
    padding: 4px;
  }

  .app-main {
    padding: 10px;
    gap: 10px;
  }

  .mobile-room-tabs {
    flex: 0 0 auto;
    z-index: 30;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
  }

  .room-tab {
    height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-weight: 850;
    cursor: pointer;
  }

  .room-tab.is-active {
    border-color: rgba(47, 143, 111, 0.24);
    background: var(--green-soft);
    color: var(--green-strong);
  }

  .rooms-grid {
    grid-template-rows: minmax(0, 1fr);
  }

  .room-panel {
    display: none;
    height: 100%;
    min-height: 0;
  }

  .room-panel.is-active-mobile {
    display: flex;
  }

  .room-header {
    min-height: 84px;
    padding: 14px;
  }

  .room-header h1 {
    font-size: 19px;
  }

  .room-metrics {
    max-width: 130px;
  }

  .mission-strip {
    grid-template-columns: minmax(0, 1fr) 62px;
    padding: 13px 14px;
  }

  .mission-score {
    width: 62px;
    min-height: 62px;
  }

  .feed {
    padding: 14px;
  }

  .composer {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .send-button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .brand-title {
    font-size: 15px;
  }

  .room-header {
    flex-direction: column;
    gap: 10px;
  }

  .room-metrics {
    max-width: none;
    justify-content: flex-start;
  }

  .rank-list li {
    grid-template-columns: 28px minmax(0, 1fr);
  }

  .rank-list time {
    display: none;
  }
}
