/* =========================================================
 * Harmony Talk — 基本スタイル
 * 白背景・濃紺・落ち着いたグリーン。色で良し悪しを表しません。
 * ========================================================= */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f3f5f7;
  --surface-tab: #f1f4f7;

  --text: #17212b;
  --text-soft: #5b6671;

  --line: #e1e6eb;
  --line-soft: #edf0f3;
  --line-strong: #d3d9df;

  --primary: #182b3a;
  --primary-soft: #e9eef2;

  --accent: #3f7168;
  --accent-strong: #2d544d;
  --accent-soft: #e8f2f0;

  /* グラフ */
  --grid: #e7ebee;
  --axis: #aeb7bf;
  --nodata: #eef1f4;
  --series-prev1: #7d93a6;
  --series-prev2: #a9b8c6;
  --series-prev3: #cbd5de;
  --series-ref: #7d8790;

  /* 録音表示 */
  --rec: #b3423f;
  --rec-soft: #f7eceb;

  --danger: #a64343;

  --radius-lg: 16px;
  --radius-md: 12px;

  --shadow: 0 12px 40px rgba(21, 34, 47, 0.07);

  --font: "IBM Plex Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

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

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

[hidden] {
  display: none !important;
}

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

.strong {
  font-weight: 600;
}

/* ---------- レイアウト ---------- */

.app-shell {
  width: 100%;
  max-width: 680px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--surface);
}

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

.screen-body {
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.center-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
}

.bottom-action {
  margin-top: auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.center-screen .bottom-action {
  margin-top: 28px;
  width: 100%;
  max-width: 420px;
  padding-left: 0;
  padding-right: 0;
}

.button-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.text-pair {
  gap: 0;
}

/* ---------- ヘッダー ---------- */

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
}

.brand-sub {
  margin-top: 1px;
  color: var(--text-soft);
  font-size: 11px;
}

.experiment-badge {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 6px 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar-plain {
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
}

.topbar-text {
  flex: 1;
  min-width: 0;
}

.topbar-title {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-sub {
  color: var(--text-soft);
  font-size: 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
}

.icon-button:active {
  background: var(--surface-soft);
}

/* ---------- テキスト ---------- */

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  line-height: 1.4;
}

.lead {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
  line-height: 1.8;
}

.muted {
  color: var(--text-soft);
  line-height: 1.8;
}

.body-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.75;
}

.section-title {
  margin: 8px 0 0;
  font-size: 15px;
  font-weight: 600;
}

.empty-note {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
}

/* ---------- カード ---------- */

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.soft-card {
  border-color: transparent;
  background: var(--surface-soft);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.card-meta {
  color: var(--text-soft);
  font-size: 11.5px;
  text-align: right;
}

.card-note {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.6;
}

.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 8px 16px 0;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
}

.empty-card p {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.7;
}

/* ---------- ボタン ---------- */

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 54px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.primary-button {
  border: 0;
  background: var(--primary);
  color: #ffffff;
}

.secondary-button {
  min-height: 48px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

.text-button {
  width: 100%;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--text-soft);
  font-size: 14px;
}

.small-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 12.5px;
}

.link-button {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.primary-button:active,
.secondary-button:active {
  transform: scale(0.985);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

/* ---------- タブ ---------- */

.tabbar {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-tab);
}

.tabbar button {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
}

.tabbar button[aria-selected="true"],
.tabbar button[aria-current="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(21, 34, 47, 0.12);
}

/* ---------- チップ ---------- */

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11.5px;
  font-weight: 500;
}

.chip-strong {
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

.chip-muted {
  background: var(--surface-soft);
  color: var(--text-soft);
  font-weight: 400;
}

/* ---------- 対象者選択 ---------- */

.subject-list {
  display: flex;
  flex-direction: column;
}

.subject-item,
.session-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 60px;
  padding: 12px 4px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.subject-item:first-child {
  border-top: 1px solid var(--line-soft);
}

.subject-item svg,
.session-row svg {
  flex: 0 0 auto;
  color: #8a949d;
}

.subject-text,
.session-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.subject-name,
.session-title {
  font-size: 14px;
  font-weight: 600;
}

.subject-meta,
.session-meta {
  color: var(--text-soft);
  font-size: 12px;
}

.form-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.field-label {
  padding: 0;
  font-size: 13px;
  font-weight: 600;
}

.req {
  margin-left: 4px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 500;
}

.field input[type="text"] {
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px;
}

.field input[type="text"]:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-tab);
}

.seg-option {
  position: relative;
}

.seg-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg-option span {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 9px;
  color: var(--text-soft);
  font-size: 13px;
  cursor: pointer;
}

.seg-option input:checked + span {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(21, 34, 47, 0.12);
}

.seg-option input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-note {
  margin: 0;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.6;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* ---------- 録音 ---------- */

.rec-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--rec-soft);
  color: #8f3432;
  font-size: 12px;
  font-weight: 600;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--rec);
  animation: pulse 1.2s infinite;
}

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

.record-body {
  gap: 0;
  padding-top: 28px;
  text-align: center;
}

.record-title {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.5;
}

.record-lead {
  margin: 8px 0 0;
  color: var(--text-soft);
  font-size: 13px;
}

.voiced-display {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
  margin-top: 28px;
}

.voiced-number {
  font-size: clamp(72px, 24vw, 96px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.04em;
}

.voiced-unit {
  color: var(--text-soft);
  font-size: 22px;
}

.voiced-caption {
  margin-top: 8px;
  font-size: 14px;
}

.record-sub {
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 12px;
}

.duration-track {
  position: relative;
  height: 60px;
  margin: 26px 8px 0;
}

.duration-bar {
  position: absolute;
  top: 12px;
  right: 0;
  left: 0;
  height: 12px;
  overflow: hidden;
  border-radius: 6px;
  background: #e7ebee;
}

.duration-fill {
  width: 0;
  height: 100%;
  border-radius: 6px;
  background: var(--primary);
  transition: width 0.1s linear;
}

.duration-tick {
  position: absolute;
  top: 6px;
  height: 24px;
  border-left: 2px solid var(--accent);
}

.duration-tick span {
  position: absolute;
  top: 30px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 12px;
}

.tick-4 {
  left: 40%;
}

.tick-4 span {
  color: var(--accent-strong);
  font-weight: 600;
}

.tick-8 {
  left: 80%;
  border-left: 1.5px dashed #8a949d;
}

.tick-8 span {
  color: var(--text-soft);
}

.ready-banner {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
}

.level {
  margin-top: 22px;
  text-align: left;
}

.level-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: var(--text-soft);
  font-size: 12px;
}

.level-head strong.is-ok {
  color: var(--accent-strong);
}

.level-head strong.is-low,
.level-head strong.is-high {
  color: var(--text);
}

.level-track {
  position: relative;
  height: 12px;
  margin-top: 6px;
  overflow: hidden;
  border-radius: 6px;
  background: #e7ebee;
}

/* -30〜-8 dBFS（-60〜0 dBFS表示）。端末上の記録目安であり、発声の良し悪しではない。 */
.level-band {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 36.7%;
  background: #cfe3de;
}

.level-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-radius: 6px;
  background: var(--primary);
  transition: width 80ms linear;
}

.level-scale {
  position: relative;
  height: 18px;
  margin-top: 4px;
  color: var(--text-soft);
  font-size: 11px;
}

.level-scale span {
  position: absolute;
  top: 0;
}

.level-scale span:first-child {
  left: 0;
}

.level-scale .level-scale-ok {
  left: 68.3%;
  transform: translateX(-50%);
  color: var(--accent-strong);
}

.level-scale span:last-child {
  right: 0;
}

.record-message {
  margin: 18px 0 0;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.6;
}

/* ---------- 解析中・エラー ---------- */

.loader {
  width: 46px;
  height: 46px;
  margin-bottom: 24px;
  border: 4px solid var(--primary-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: 20px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 24px;
  font-weight: 700;
}

/* ---------- 4秒未満 ---------- */

.short-hero {
  padding-top: 20px;
  text-align: center;
}

.short-caption {
  margin: 0;
  color: var(--text-soft);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
}

.short-value {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
  margin-top: 10px;
}

.short-value span:first-child {
  font-size: 80px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.04em;
}

.short-value .unit {
  color: var(--text-soft);
  font-size: 20px;
}

.short-track {
  margin: 12px 8px 4px;
}

.short-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 6px;
  background: #e7ebee;
}

.short-fill {
  width: 0;
  height: 100%;
  border-radius: 6px;
  background: var(--primary);
}

.short-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  color: var(--text-soft);
  font-size: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .rec-dot,
  .loader {
    animation-duration: 2.4s;
  }

  .duration-fill,
  .level-fill {
    transition: none;
  }
}

/* ---------- タブレット・PC（中央寄せ） ---------- */

@media (min-width: 681px) {
  body {
    padding: 28px 0;
  }

  .app-shell {
    min-height: calc(100dvh - 56px);
    overflow: clip;
    border-radius: 28px;
    box-shadow: var(--shadow);
  }

  .screen {
    min-height: calc(100dvh - 56px);
  }

  .screen-body {
    padding-right: 24px;
    padding-left: 24px;
  }

  .bottom-action {
    padding-right: 24px;
    padding-left: 24px;
  }
}

/* ---------- PC詳細解析 ---------- */

@media (min-width: 960px) {

  .app-shell {
    max-width: 1180px;
  }

  /*
   * 対象者登録・録音などは
   * これまでどおり読みやすい幅を維持
   */
  #screen-start,
  #screen-home,
  #screen-record,
  #screen-analyzing,
  #screen-short,
  #screen-error {
    width: 100%;
    max-width: 680px;

    margin-right: auto;
    margin-left: auto;
  }

  /*
   * 結果・試行比較は
   * PCの横幅をグラフ／数値表示に利用
   */
  #screen-result .screen-body,
  #screen-compare .screen-body {
    padding-right: 32px;
    padding-left: 32px;
  }

  #screen-result .bottom-action,
  #screen-compare .bottom-action {
    padding-right: 32px;
    padding-left: 32px;
  }

}
