:root {
  --ink: #191b1a;
  --muted: #737875;
  --surface: #f7f7f5;
  --white: #ffffff;
  --line: #d9dcda;
  --accent: #1f5a4b;
  --accent-hover: #17473b;
  --soft: #edf1ef;
  --danger: #b33f3a;
  font-family: Inter, Avenir, "Helvetica Neue", "Yu Gothic", YuGothic, Meiryo, sans-serif;
  color: var(--ink);
  background: var(--surface);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--surface); }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--surface);
  line-height: 1.5;
}

button,
input,
select { font: inherit; color: inherit; }

button { cursor: pointer; }

a { color: inherit; }

.hidden { display: none !important; }

.shell {
  width: min(1080px, calc(100% - 40px));
  margin-inline: auto;
}

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

/* Entry */
.entry-body { min-height: 100dvh; }

.entry-page {
  width: min(420px, calc(100% - 40px));
  min-height: 100dvh;
  margin-inline: auto;
  padding: clamp(60px, 12vh, 116px) 0 48px;
  text-align: center;
}

.app-title {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

.entry-panel {
  width: 100%;
  margin-top: clamp(72px, 16vh, 150px);
}

.entry-form {
  display: grid;
  gap: 8px;
}

.field-label {
  margin-top: 2px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: left;
}

.field-label-spaced { margin-top: 10px; }

.entry-form .button { margin-top: 4px; }

.room-tabs {
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.room-tab {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.room-tab[aria-selected="true"] {
  border-bottom-color: var(--accent);
  color: var(--ink);
}

.room-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.room-fields {
  display: grid;
  gap: 8px;
}

input,
select {
  width: 100%;
  min-height: 56px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--white);
  transition: border-color 150ms ease, background-color 150ms ease;
}

input::placeholder { color: #8b908d; opacity: 1; }

input:focus,
select:focus { border-color: var(--accent); }

.button {
  min-height: 56px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 700;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.button.primary { background: var(--accent); color: var(--white); }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary { background: var(--soft); color: var(--ink); }
.button.tertiary { border-color: var(--line); background: transparent; }
.button.full { width: 100%; }
.button.compact { min-width: 96px; }
.button:disabled { cursor: wait; opacity: 0.55; }

.form-error {
  min-height: 1.5em;
  margin: 4px 0 0;
  color: var(--danger);
  font-size: 0.8rem;
  text-align: left;
}

.text-button {
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.logout-button {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(20px, env(safe-area-inset-right));
  z-index: 5;
}

.offline-label { margin: 0 0 24px; color: var(--muted); }

/* Shared header */
.site-header {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* Room entry */
.room-body { background: var(--surface); }
.room-main { padding: 24px 0 56px; }

.start-card {
  width: min(420px, 100%);
  margin: clamp(40px, 10vh, 96px) auto 0;
}

.start-card h1 {
  margin: 0 0 32px;
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.04em;
}

.field { margin: 0 0 12px; }
.field label { display: block; margin-bottom: 7px; font-size: 0.82rem; font-weight: 700; }

/* Active call */
.call-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 32px;
  align-items: start;
}

.call-primary { min-width: 0; }

.room-meta {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.meta-label {
  margin-right: 8px;
  color: var(--muted);
  font-size: 0.64rem;
  letter-spacing: 0.14em;
}

.copy-button {
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

.voice-stage {
  min-height: 570px;
  padding: 48px 28px;
  border-radius: 18px;
  background: #173e34;
  color: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  text-align: center;
}

.connection-art {
  width: 200px;
  height: 200px;
  margin-bottom: 20px;
  display: grid;
  place-items: center;
  position: relative;
}

.ring {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
}

.ring-one { inset: 20px; }
.ring-two { inset: 0; }

.voice-stage[data-state="connecting"] .ring,
.voice-stage[data-state="reconnecting"] .ring { animation: pulse 2s infinite; }

.avatar {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  background: #cbdcd4;
  color: #173e34;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: 2.5rem;
}

.status-pill {
  margin: 0;
  color: #d7e3de;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.status-pill span {
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #e4bd70;
  display: inline-block;
}

.participant-list {
  width: min(640px, 100%);
  margin: 30px 0 26px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.participant-person {
  min-width: 0;
  padding: 12px 14px;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.participant-person.is-speaking {
  border-color: #4a9eff;
  background: rgba(74, 158, 255, 0.14);
}

.participant-person.is-muted { opacity: 0.64; }

.participant-initial {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #cbdcd4;
  color: #173e34;
  font-weight: 700;
}

.participant-name {
  min-width: 0;
  overflow: hidden;
  font-size: 0.82rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-stage h1 {
  margin: 14px 0 4px;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 500;
}

.voice-stage > p:not(.status-pill) { margin: 0; color: #b9cbc4; font-size: 0.82rem; }

.route-row {
  margin: 20px 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.route-row span {
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font-size: 0.7rem;
}

.call-controls {
  margin-top: 12px;
  display: flex;
  gap: 18px;
  position: relative;
  z-index: 1;
}

.round-control {
  min-width: 70px;
  border: 0;
  background: transparent;
  color: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  font-size: 0.7rem;
}

.control-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
}

.round-control[aria-pressed="true"] .control-icon { background: #e3d6aa; color: #173e34; }
.round-control.danger .control-icon { background: #ad403c; font-size: 1.5rem; }

.call-sidebar { padding-top: 52px; }

.side-section {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}

.side-section:last-child { border-bottom: 1px solid var(--line); }

.side-section h2 {
  margin: 0 0 14px;
  font-size: 0.82rem;
}

.audio-settings select { margin-bottom: 22px; }

.volume-field {
  margin: 14px 0 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

.volume-field output { color: var(--ink); font-variant-numeric: tabular-nums; }

.volume-range {
  width: 100%;
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  accent-color: var(--accent);
}

.side-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mini-status { color: var(--accent); font-size: 0.64rem; }
.summary-list { margin: 0; }

.summary-list > div {
  padding: 9px 0;
  border-top: 1px solid #e5e7e6;
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
}

.summary-list dt { color: var(--muted); }
.summary-list dd { margin: 0; font-weight: 700; text-align: right; }

.diagnostics-card summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
}

.diagnostics-card summary span { color: var(--muted); font-size: 0.68rem; }

.diagnostics-grid {
  margin: 14px 0;
  overflow-wrap: anywhere;
  font: 11px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.diag-row {
  padding: 5px 0;
  border-bottom: 1px solid #e5e7e6;
  display: grid;
  grid-template-columns: 1fr 1.2fr;
}

.diag-row span:first-child { color: var(--muted); }

.error-banner {
  margin-top: 14px;
  padding: 12px 0;
  border-top: 1px solid #e2b8b5;
  color: #7f3e3a;
}

.error-banner strong { font-size: 0.8rem; }
.error-banner p { margin: 2px 0 0; font-size: 0.74rem; }

.notice {
  margin-top: 14px;
  padding: 12px 0;
  border-top: 1px solid #dec888;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #745f26;
  font-size: 0.78rem;
}

.notice-icon {
  width: 22px;
  height: 22px;
  border: 1px solid currentColor;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
}

/* Diagnostics */
.debug-main { padding: 30px 0 70px; }
.debug-card { width: min(720px, 100%); }

.debug-result {
  margin: 22px 0 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 700;
}

.code-panel {
  min-height: 130px;
  max-height: 330px;
  padding: 15px;
  overflow: auto;
  background: #142c26;
  color: #d5e8df;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

.meter {
  height: 10px;
  margin-top: 24px;
  overflow: hidden;
  background: #dfe6e1;
}

.meter span {
  width: 0;
  height: 100%;
  display: block;
  background: #389677;
  transition: width 100ms linear;
}

@keyframes pulse {
  0%, 100% { transform: scale(0.94); opacity: 0.45; }
  50% { transform: scale(1.03); opacity: 1; }
}

@media (max-width: 820px) {
  .shell { width: min(100% - 28px, 620px); }
  .site-header { height: 68px; }
  .room-main { padding-top: 12px; }
  .call-layout { grid-template-columns: 1fr; gap: 0; }
  .voice-stage { min-height: 520px; padding: 32px 18px; }
  .call-sidebar { padding-top: 24px; }
}

@media (max-width: 430px) {
  .entry-page { width: calc(100% - 32px); padding-top: 72px; }
  .entry-panel { margin-top: 96px; }
  .shell { width: calc(100% - 20px); }
  .room-header .brand { font-size: 0.88rem; }
  .start-card { margin-top: 44px; }
  .voice-stage { min-height: 500px; border-radius: 14px; }
  .connection-art { width: 170px; height: 170px; margin-bottom: 8px; }
  .call-controls { gap: 8px; }
  .round-control { min-width: 66px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
