:root {
  color-scheme: light;
  --bg: #f5f7ff;
  --panel: #ffffff;
  --panel-soft: #eef2ff;
  --panel-warm: #fff4dd;
  --ink: #0b1234;
  --heading: #030a2f;
  --muted: #64708f;
  --line: #d9def0;
  --line-strong: #c5cde6;
  --teal: #3527e8;
  --teal-dark: #16106f;
  --blue: #11766f;
  --blue-dark: #07594f;
  --amber: #a27417;
  --rose: #d2495d;
  --soft: #fbfcff;
  --soft-teal: #eef2ff;
  --violet: #7b35f6;
  --pair-accent: #11766f;
  --brand-gradient: linear-gradient(135deg, #030a2f 0%, #3325e8 48%, #8a38f5 100%);
  --shadow: 0 14px 36px rgba(7, 14, 45, 0.09);
  font-family: Inter, "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: linear-gradient(180deg, #fbfcff 0%, var(--bg) 100%);
  color: var(--ink);
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  -webkit-text-size-adjust: 100%;
  touch-action: pan-y;
}

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

.app-shell {
  width: min(1740px, calc(100vw - 28px));
  min-height: 100svh;
  margin: 14px auto;
}

.topbar,
.panel,
.quick-status > div {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  min-height: 112px;
  padding: 22px 26px;
  border-radius: 8px;
  backdrop-filter: blur(18px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-block > div {
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(53, 39, 232, 0.18);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 26px rgba(53, 39, 232, 0.12);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.4);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: var(--heading);
  font-size: 2.85rem;
  line-height: 1.05;
}

.hero-copy {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 750;
  line-height: 1.45;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  line-height: 1.15;
}

.topbar-actions,
.panel-heading,
.button-row,
.block-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.button {
  border: 0;
  border-radius: 7px;
  padding: 13px 18px;
  color: #fff;
  background: var(--brand-gradient);
  box-shadow: 0 10px 22px rgba(53, 39, 232, 0.18);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.button:hover {
  filter: brightness(0.95);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button.secondary {
  background: var(--brand-gradient);
}

.button.secondary:hover {
  filter: brightness(0.95);
}

.button.danger {
  background: #fff0ed;
  border: 1px solid #efc1bb;
  color: #a7342e;
  box-shadow: none;
}

.button.ghost {
  color: var(--heading);
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: none;
}

.button.full {
  width: 100%;
}

.status-pill,
.small-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fff;
  font-weight: 900;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #84918e;
}

[data-state="live"] .status-dot,
[data-state="ready"] .status-dot {
  background: var(--blue);
}

[data-state="connecting"] .status-dot,
[data-state="warn"] .status-dot {
  background: var(--amber);
}

[data-state="error"] .status-dot {
  background: #d12f5f;
}

.quick-status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.quick-status > div {
  min-height: 78px;
  padding: 16px;
  border-radius: 8px;
}

.quick-status span,
.field > span,
.caption-card span,
.block-heading span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.quick-status strong {
  display: block;
  margin-top: 5px;
  word-break: keep-all;
}

.trip-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(480px, 1.1fr) minmax(420px, 0.9fr);
  grid-template-areas:
    "control stage caption"
    "control log caption";
  gap: 14px;
  align-items: start;
}

.panel {
  border-radius: 8px;
  padding: 20px;
}

.control-panel {
  grid-area: control;
  min-height: 640px;
}

.stage-panel {
  grid-area: stage;
  min-height: 0;
}

.caption-panel {
  grid-area: caption;
  min-height: 0;
}

.log-panel {
  grid-area: log;
  min-height: 270px;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

select {
  min-height: 54px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  font-weight: 850;
  touch-action: manipulation;
}

.pair-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.pair-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--soft);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
}

.pair-chip.is-active {
  border-color: var(--pair-accent);
  background: var(--soft-teal);
  color: var(--teal-dark);
}

.tip-box,
.quick-phrases {
  margin-top: 18px;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--soft);
}

.tip-box {
  background: var(--panel-warm);
}

.tip-box p,
.phrase-preview {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.phrase-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 12px 0;
}

.phrase-buttons button {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--heading);
  font-weight: 850;
  cursor: pointer;
  padding: 9px 12px;
  text-align: left;
  touch-action: manipulation;
}

.phrase-buttons button strong {
  min-width: 46px;
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 950;
  text-align: right;
  text-transform: uppercase;
}

.phrase-buttons button.is-speaking {
  border-color: rgba(53, 39, 232, 0.35);
  background: #eef2ff;
}

.signal-frame {
  position: relative;
  overflow: hidden;
  margin-top: 20px;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 3.05 / 1;
  border: 1px solid rgba(53, 39, 232, 0.16);
  border-radius: 8px;
  background: #030a2f;
}

.signal-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.signal-overlay {
  position: absolute;
  inset: auto 16px 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: rgba(255, 255, 255, 0.86);
  font-weight: 900;
}

.signal-overlay span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.5;
}

.talk-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.talk-card {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 230px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 18px 42px rgba(53, 39, 232, 0.18);
  touch-action: pan-y;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.talk-card.me {
  background: var(--brand-gradient);
}

.talk-card.partner {
  background: linear-gradient(135deg, #07594f 0%, #11766f 55%, #1ea79b 100%);
}

.talk-card span {
  font-size: 2.05rem;
  font-weight: 1000;
}

.talk-card strong {
  font-size: 1.05rem;
}

.talk-card small {
  opacity: 0.86;
  font-weight: 850;
}

.talk-card:disabled {
  cursor: not-allowed;
  filter: grayscale(0.35);
  opacity: 0.5;
}

.talk-card.is-active {
  background: linear-gradient(135deg, #871f38 0%, #d2495d 100%);
  transform: translateY(1px);
}

.caption-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 18px;
}

.caption-card {
  min-height: 118px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
}

.caption-card.translated {
  border-color: rgba(53, 39, 232, 0.24);
  background: #f1f3ff;
}

.caption-card p {
  margin: 10px 0 0;
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 390px;
  overflow: auto;
  margin-top: 16px;
}

.history-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
}

.history-item strong {
  color: var(--teal-dark);
}

.history-item p {
  margin: 0;
  line-height: 1.45;
}

.event-log {
  display: grid;
  gap: 8px;
  max-height: 170px;
  overflow: auto;
  margin-top: 14px;
}

.event-item {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f7faf8;
  color: var(--muted);
}

.event-item strong {
  color: var(--ink);
}

.event-item[data-level="error"] {
  background: #fff0f4;
  color: #9a2851;
}

@media (max-width: 1260px) {
  .trip-grid {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    grid-template-areas:
      "control stage"
      "caption caption"
      "log log";
  }

  .caption-panel,
  .log-panel {
    min-height: auto;
  }

  .caption-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 840px) {
  h1 {
    font-size: 2.15rem;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: 0;
    padding: 20px;
    backdrop-filter: none;
  }

  .topbar-actions {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .topbar-actions .status-pill {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .topbar-actions .button {
    width: 100%;
  }

  .quick-status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trip-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "stage"
      "caption"
      "control"
      "log";
  }

  .caption-grid,
  .talk-grid {
    grid-template-columns: 1fr;
  }

  .control-panel,
  .stage-panel,
  .caption-panel,
  .log-panel {
    min-height: auto;
  }

  .app-shell {
    width: min(100% - 16px, 1740px);
    margin: 8px auto;
  }

  .button,
  .pair-chip,
  .phrase-buttons button {
    min-height: 48px;
  }

  .history-list,
  .event-log {
    max-height: none;
    overflow: visible;
  }

  .signal-frame {
    aspect-ratio: 2 / 1;
  }

  .talk-card {
    min-height: 156px;
  }

  .talk-card span {
    font-size: 1.65rem;
  }

  .caption-card p {
    font-size: 1.18rem;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: 100%;
    margin: 0;
  }

  .topbar,
  .panel,
  .quick-status > div {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .topbar {
    gap: 14px;
  }

  .brand-block {
    align-items: flex-start;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .quick-status,
  .trip-grid {
    gap: 10px;
  }

  .quick-status {
    grid-template-columns: 1fr;
    margin: 10px 0;
  }

  .topbar-actions {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.82rem;
  }

  h2 {
    font-size: 1.12rem;
  }

  .hero-copy {
    font-size: 0.94rem;
  }

  .panel {
    padding: 17px;
  }

  .signal-overlay {
    inset: auto 12px 12px 12px;
    font-size: 0.88rem;
  }

  .talk-card {
    min-height: 146px;
    box-shadow: none;
  }

  .caption-card {
    min-height: 104px;
  }
}
