/* Bluetoothセンサースピードメーター v1.2.2 */
:root {
  --bg-a: #07111f;
  --bg-b: #0d2342;
  --panel: rgba(11, 20, 35, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.07);
  --panel-line: rgba(148, 163, 184, 0.22);
  --text: #f8fafc;
  --muted: #aebbd0;
  --blue: #2f8cff;
  --blue-dark: #1565c0;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #facc15;
  --footer-blue: #1d4ed8;
  --footer-bg: transparent;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, #173b68 0%, var(--bg-a) 55%, #030712 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 10px calc(10px + var(--safe-bottom));
  touch-action: manipulation;
}

button, select, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 430px);
  margin: 0 auto;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

.app-screen {
  width: 100%;
  min-height: calc(100svh - 88px - var(--safe-bottom));
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(8, 18, 33, 0.99), rgba(4, 9, 18, 0.99));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  overflow: hidden;
  position: relative;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  cursor: pointer;
}

.app-title { min-width: 0; text-align: center; }

.app-title h1 {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.25;
  letter-spacing: 0.04em;
}

.status-line {
  margin-top: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 3px rgba(100, 116, 139, 0.12);
}

.status-dot.live {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.14), 0 0 18px rgba(34, 197, 94, 0.45);
}

.status-dot.warn {
  background: var(--yellow);
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.12);
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.12);
}

.page {
  display: none;
  min-height: calc(100svh - 148px - var(--safe-bottom));
  padding: 14px 14px 78px;
}

#pageSpeed.is-active,
#pageStats.is-active,
#pageSettings.is-active {
  display: flex;
  flex-direction: column;
}

.speed-panel {
  margin-top: 0;
  min-height: 0;
  flex: 1 1 auto;
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  background: radial-gradient(circle at 50% 26%, rgba(47, 140, 255, 0.22), rgba(12, 30, 56, 0.78) 50%, rgba(5, 11, 22, 0.94) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 16px 14px;
}

.display-view { display: none; width: 100%; }
.display-view.is-active { display: block; }

.digital-readout {
  min-height: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.readout-label {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
}

.speed-value {
  font-size: clamp(5.6rem, 24vw, 7.7rem);
  line-height: 0.92;
  font-weight: 900;
  letter-spacing: -0.06em;
  color: #66c7ff;
  text-shadow: 0 0 30px rgba(47, 140, 255, 0.62);
  font-variant-numeric: tabular-nums;
}

.speed-unit {
  margin-top: 8px;
  font-size: 1.35rem;
  font-weight: 800;
  color: #8bd7ff;
  letter-spacing: 0.03em;
}

.sub-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 26px;
}

.metric-chip {
  min-height: 88px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  padding: 12px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.metric-chip .label {
  display: block;
  color: var(--muted);
  font-size: 0.70rem;
  line-height: 1.2;
}

.metric-chip .num {
  display: block;
  margin-top: 4px;
  font-size: 1.02rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.metric-chip .unit {
  display: block;
  color: var(--muted);
  font-size: 0.67rem;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 0;
  padding-top: 8px;
  padding-bottom: 8px;
}

.primary-action,
.secondary-action,
.outline-action {
  border: 0;
  min-height: 58px;
  border-radius: 20px;
  font-weight: 900;
  color: #fff;
  cursor: pointer;
}

.primary-action {
  background: linear-gradient(180deg, #34d466, #16a34a);
  box-shadow: 0 12px 24px rgba(34, 197, 94, 0.25);
  font-size: 1.12rem;
  letter-spacing: 0.03em;
}

.primary-action.is-connected {
  background: linear-gradient(180deg, #5aa6ff, #2563eb);
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.25);
}

.primary-action.is-disconnecting {
  background: linear-gradient(180deg, #ff5b5b, #dc2626);
  box-shadow: 0 12px 24px rgba(239, 68, 68, 0.25);
}

.stat-header {
  margin: 2px 0 10px;
  text-align: center;
}

.stat-header h2,
.settings-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

.settings-card p,
.note-text {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

.stats-grid {
  flex: 0 0 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, auto);
  gap: 12px;
  margin-top: 8px;
}

.grid-stat-card {
  min-height: 118px;
  border: 1px solid var(--panel-line);
  border-radius: 22px;
  background: radial-gradient(circle at 50% 18%, rgba(47, 140, 255, 0.16), rgba(15, 23, 42, 0.90) 64%, rgba(2, 6, 23, 0.96) 100%);
  padding: 11px 10px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 14px 28px rgba(0,0,0,0.18);
}

.grid-stat-card h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.grid-stat-card.avg h3,
.grid-stat-card.avg .grid-stat-number { color: #4ade80; }

.grid-stat-card.max h3,
.grid-stat-card.max .grid-stat-number { color: #fde047; }

.grid-stat-card.elapsed h3,
.grid-stat-card.elapsed .grid-stat-time { color: #c4b5fd; }

.grid-stat-card.distance h3,
.grid-stat-card.distance .grid-stat-number { color: #60a5fa; }

.grid-stat-number {
  font-size: clamp(2.15rem, 10vw, 2.9rem);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.grid-stat-time {
  font-size: clamp(1.48rem, 6.6vw, 1.95rem);
  line-height: 1.05;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.grid-stat-unit {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.record-actions {
  margin-top: auto;
  padding-top: 14px;
  padding-bottom: 18px;
}

.record-actions .outline-action {
  margin-top: 0;
  min-height: 50px;
  border-radius: 18px;
  font-size: 1rem;
  width: 100%;
  background: transparent;
  color: #93c5fd;
  border: 1px solid rgba(96, 165, 250, 0.54);
}

.settings-card {
  border: 1px solid var(--panel-line);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.06);
  padding: 18px;
}

.setting-row {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.16);
}

.setting-row label {
  display: block;
  color: #dbeafe;
  font-size: 0.88rem;
  font-weight: 850;
  margin-bottom: 8px;
}

.setting-row select,
.setting-row input[type="number"],
.setting-row input[type="checkbox"] {
  accent-color: var(--blue);
}

.setting-row select,
.setting-row input[type="number"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.72);
  color: #f8fafc;
  padding: 0 12px;
}

.setting-row input[type="number"] {
  margin-top: 8px;
}

.check-label {
  display: flex !important;
  align-items: flex-start;
  gap: 9px;
  line-height: 1.45;
  color: #dbeafe;
}

.setting-hint {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.5;
}

.message-box {
  margin-top: 12px;
  border: 1px solid rgba(250, 204, 21, 0.28);
  border-radius: 18px;
  background: rgba(250, 204, 21, 0.08);
  color: #fef3c7;
  padding: 10px 12px;
  font-size: 0.78rem;
  line-height: 1.55;
}

.message-box[hidden] { display: none; }

.bottom-nav {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(7px + var(--safe-bottom));
  height: 58px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 3px;
}

.bottom-nav button {
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.70rem;
  font-weight: 850;
  line-height: 1.1;
}

.bottom-nav button span {
  display: block;
  font-size: 1.08rem;
  line-height: 1;
  margin-bottom: 1px;
}

.bottom-nav button.is-active {
  color: #ffffff;
  background: rgba(47, 140, 255, 0.17);
}

.help-sheet {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: none;
  align-items: flex-end;
  z-index: 50;
}

.help-sheet.is-open { display: flex; }

.help-card {
  width: 100%;
  border-radius: 28px 28px 0 0;
  background: #0b1423;
  border: 1px solid rgba(148, 163, 184, 0.22);
  padding: 20px 18px calc(22px + var(--safe-bottom));
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.35);
}

.help-card h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.help-card ul {
  margin: 0;
  padding-left: 1.2em;
  color: #dbeafe;
  line-height: 1.72;
  font-size: 0.86rem;
}

.help-card button {
  width: 100%;
  margin-top: 16px;
  min-height: 46px;
  border: 0;
  border-radius: 16px;
  background: var(--blue-dark);
  color: #fff;
  font-weight: 900;
}

.app-footer {
  width: min(100%, 430px);
  flex: 0 0 auto;
  margin: 8px auto 0;
  min-height: 30px;
  border-top: 0;
  border-radius: 12px;
  background: var(--footer-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-footer p {
  margin: 0;
  padding: 6px 10px;
  font-size: 0.78rem;
  line-height: 1.2;
  text-align: center;
  color: var(--footer-blue);
}

.app-footer a {
  color: var(--footer-blue);
  text-decoration: none;
  font-weight: 800;
}

.app-footer a:hover { text-decoration: underline; }

.ad-panel {
  width: min(100%, 430px);
  margin: 8px auto 0;
  border: 1px solid #d7e6f8;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;
  color: #1f2937;
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 29px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: #4f6f91;
  line-height: 1;
}

.ad-notice {
  flex: 1 1 auto;
  text-align: right;
  font-size: 0.70rem;
  color: #64748b;
  line-height: 1.2;
}

.ad-close-btn {
  flex: 0 0 auto;
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border: none;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 800;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.ad-close-btn:hover { background: #0d47a1; }

.ad-body {
  padding: 8px;
  min-height: 64px;
  background: #ffffff;
}

@media (max-width: 360px) {
  body {
    padding-left: 6px;
    padding-right: 6px;
  }

  .app-screen { border-radius: 24px; }

  .page {
    padding-left: 10px;
    padding-right: 10px;
    padding-bottom: 66px;
  }

  .sub-metrics {
    gap: 7px;
    margin-top: 20px;
  }

  .metric-chip {
    min-height: 78px;
    padding-left: 3px;
    padding-right: 3px;
  }

  .stats-grid { gap: 10px; }

  .grid-stat-card {
    min-height: 106px;
    padding: 10px 8px;
  }

  .grid-stat-card h3 { font-size: 0.88rem; }
}


/* v1.1.4 start-stop and settings connection refinement */
.connect-grid.single{grid-template-columns:1fr;}
.primary-action.is-running{background:linear-gradient(180deg,#ff5b5b,#dc2626);box-shadow:0 12px 26px rgba(239,68,68,.28);}
.primary-action:disabled,.connect-tile:disabled{opacity:.48;cursor:not-allowed;}


/* v1.1.4 sensor-type guidance */
.setting-hint strong {
  color: #dbeafe;
}
.connect-tile.cadence {
  border-color: rgba(96, 165, 250, 0.34);
  background: rgba(96, 165, 250, 0.12);
  color: #dbeafe;
}
.connect-tile.cadence.is-connected {
  border-color: rgba(34, 197, 94, 0.46);
  background: rgba(34, 197, 94, 0.16);
  color: #bbf7d0;
}

/* v1.2.0：端末保存・再接続・走行履歴 */
#pageStats.is-active,
#pageSettings.is-active {
  overflow-y: auto;
  max-height: calc(100svh - 64px - var(--safe-bottom));
  scrollbar-width: thin;
}

.setting-reset-btn,
.history-clear-btn {
  width: 100%;
  min-height: 40px;
  margin-top: 9px;
  border: 1px solid rgba(96, 165, 250, 0.45);
  border-radius: 13px;
  background: rgba(47, 140, 255, 0.12);
  color: #bfdbfe;
  font-weight: 800;
}

.history-panel {
  margin: 2px 0 18px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.20);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.045);
}

.history-head,
.history-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-head h3 {
  margin: 0;
  font-size: 1rem;
}

.history-head span {
  color: var(--muted);
  font-size: 0.72rem;
}

.history-list {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.history-empty {
  margin: 8px 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.history-item {
  padding: 10px;
  border: 1px solid rgba(96, 165, 250, 0.22);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.42);
}

.history-item-head strong {
  font-size: 0.78rem;
}

.history-item-head span {
  color: #bfdbfe;
  font-size: 0.82rem;
  font-weight: 900;
}

.history-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 8px;
}

.history-metrics div {
  min-width: 0;
  padding: 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.history-metrics span,
.history-metrics b {
  display: block;
}

.history-metrics span {
  color: var(--muted);
  font-size: 0.64rem;
}

.history-metrics b {
  margin-top: 2px;
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.history-clear-btn {
  border-color: rgba(239, 68, 68, 0.38);
  background: rgba(239, 68, 68, 0.10);
  color: #fecaca;
}
