* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;

  --background: #07111f;
  --panel: #101c2e;
  --panel-light: #16263d;
  --border: rgba(255, 255, 255, 0.1);

  --text: #f7fbff;
  --muted: #9eafc5;

  --accent: #5ee6b5;
  --accent-dark: #062e23;

  --blue: #67a8ff;
  --pink: #ff7db8;
  --yellow: #ffd166;
  --red: #ff6b7d;
}


html {
  background: var(--background);
}


body {
  min-height: 100vh;
  margin: 0;

  background:
    radial-gradient(
      circle at 90% 0%,
      rgba(94, 230, 181, 0.14),
      transparent 32%
    ),
    var(--background);

  color: var(--text);

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


button,
input,
select {
  font: inherit;
}


button {
  color: inherit;

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


.app {
  width: min(100%, 760px);
  min-height: 100vh;

  margin: 0 auto;

  padding:
    max(18px, env(safe-area-inset-top))
    16px
    max(30px, env(safe-area-inset-bottom));
}


/* =========================================================
   ヘッダー
========================================================= */

.topbar,
.view-toolbar,
.dialog-card header,
.dialog-actions,
.setting-column-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}


.topbar {
  margin-bottom: 24px;
}


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


h1 {
  margin-bottom: 0;

  font-size:
    clamp(1.3rem, 5vw, 2rem);
}


h2 {
  margin-bottom: 8px;

  font-size:
    clamp(1.5rem, 6vw, 2.2rem);
}


.eyebrow {
  margin-bottom: 5px;

  color: var(--accent);

  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}


.icon-button {
  width: 44px;
  height: 44px;

  flex-shrink: 0;

  border: 1px solid var(--border);
  border-radius: 14px;

  background: var(--panel);

  cursor: pointer;
}


/* =========================================================
   画面切り替え
========================================================= */

.view {
  display: none;
}


.view.is-active {
  display: block;

  animation:
    show-view 180ms ease-out;
}


@keyframes show-view {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}


/* =========================================================
   共通カード
========================================================= */

.intro-card,
.mode-card,
.camera-panel,
.recognized-question,
.recognized-number,
.connection-card,
.result-panel {
  border: 1px solid var(--border);
  border-radius: 22px;

  background:
    rgba(16, 28, 46, 0.94);

  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.2);
}


/* =========================================================
   モード選択
========================================================= */

.intro-card {
  display: flex;
  align-items: flex-start;
  gap: 13px;

  padding: 20px;
  margin-bottom: 16px;
}


.intro-card p {
  margin: 5px 0 0;

  color: var(--muted);

  line-height: 1.55;
}


.ready-dot {
  width: 10px;
  height: 10px;

  flex-shrink: 0;

  margin-top: 6px;

  border-radius: 50%;

  background: var(--accent);

  box-shadow:
    0 0 18px var(--accent);
}


.mode-list {
  display: grid;
  gap: 13px;
}


.mode-card {
  width: 100%;

  display: grid;

  grid-template-columns:
    auto minmax(0, 1fr) auto;

  align-items: center;
  gap: 14px;

  padding: 20px;

  text-align: left;

  cursor: pointer;

  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease;
}


.mode-card:hover,
.mode-card:focus-visible {
  transform: translateY(-2px);

  border-color:
    rgba(94, 230, 181, 0.6);

  background: var(--panel-light);
}


.mode-card > span:nth-child(2) {
  min-width: 0;

  display: grid;
  gap: 5px;
}


.mode-card small,
.connection-card small {
  color: var(--muted);

  line-height: 1.5;
}


.mode-icon {
  font-size: 2rem;
}


.mode-card b {
  color: var(--muted);

  font-size: 1.8rem;
}


/* =========================================================
   ナビゲーション
========================================================= */

.back-button {
  padding: 9px 0;

  border: 0;

  background: transparent;
  color: var(--muted);

  font-weight: 800;

  cursor: pointer;
}


.section-title {
  margin: 26px 0 16px;
}


.section-title.compact {
  margin-top: 16px;
}


.badge {
  flex-shrink: 0;

  padding: 8px 12px;

  border-radius: 999px;

  background:
    rgba(94, 230, 181, 0.13);

  color: var(--accent);

  font-size: 0.78rem;
  font-weight: 900;
}


/* =========================================================
   カメラ
========================================================= */

.camera-panel {
  width: 100%;
  max-width: 520px;

  margin: 0 auto;

  overflow: hidden;

  /*
    カメラ映像部分の再描画を
    外側へ波及させにくくする。
  */
  contain: paint;
}


.video-stage {
  position: relative;

  width: 100%;

  aspect-ratio: 16 / 9;

  overflow: hidden;

  background: #020711;

  touch-action: none;
  user-select: none;

  -webkit-user-select: none;
  -webkit-touch-callout: none;

  /*
    Safariでの再合成時の
    位置ずれを抑える。
  */
  transform: translateZ(0);
  backface-visibility: hidden;
}


#cameraVideo {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: cover;

  /*
    表示する切り抜き位置。
    35%で少し上寄せ。
  */
  object-position: center 35%;

  touch-action: none;
  user-select: none;

  -webkit-user-select: none;
  -webkit-touch-callout: none;

  /*
    GPU合成レイヤーを固定して、
    ズーム後の描画の揺れを抑える。
  */
  transform: translateZ(0);
  backface-visibility: hidden;

  will-change: transform;
}


.camera-placeholder {
  position: absolute;
  inset: 0;
  z-index: 4;

  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;

  background: #050b15;
  color: var(--muted);

  text-align: center;
}


.camera-placeholder span {
  font-size: 2.7rem;
}


.camera-placeholder[hidden] {
  display: none;
}


/* =========================================================
   ズーム倍率
========================================================= */

.zoom-badge {
  position: absolute;
  top: 11px;
  left: 11px;
  z-index: 3;

  padding: 7px 10px;

  border-radius: 999px;

  background:
    rgba(4, 10, 20, 0.8);

  font-size: 0.72rem;
  font-weight: 900;

  pointer-events: none;

  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}


/* =========================================================
   判定結果
========================================================= */

.camera-result-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  padding: 20px;

  background:
    rgba(3, 9, 19, 0.76);

  text-align: center;

  opacity: 0;
  pointer-events: none;

  cursor: pointer;

  transition:
    opacity 160ms ease,
    background 160ms ease;

  touch-action: manipulation;
}


.camera-result-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}


.camera-result-overlay > span {
  color:
    rgba(255, 255, 255, 0.75);

  font-size: 0.78rem;
  font-weight: 900;
}


.camera-result-overlay > strong {
  display: block;

  max-width: 100%;

  margin: 5px 0;

  overflow: hidden;

  font-size:
    clamp(2.2rem, 14vw, 5rem);

  line-height: 1.05;

  text-overflow: ellipsis;
  white-space: nowrap;
}


.camera-result-overlay > small {
  max-width: 100%;

  color:
    rgba(255, 255, 255, 0.82);

  font-weight: 700;

  overflow-wrap: anywhere;
}


.camera-result-overlay.left {
  background:
    rgba(38, 91, 168, 0.84);
}


.camera-result-overlay.right {
  background:
    rgba(157, 45, 107, 0.84);
}


.camera-result-overlay.both {
  background:
    rgba(18, 125, 91, 0.86);
}


.camera-result-overlay.none {
  background:
    rgba(136, 98, 18, 0.86);
}


.camera-result-overlay.error {
  background:
    rgba(138, 38, 51, 0.86);
}


/* =========================================================
   撮影ボタン
========================================================= */

.capture-button {
  width: 100%;
  max-width: 520px;
  min-height: 64px;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;

  margin: 14px auto 0;
  padding: 14px 20px;

  border: 0;
  border-radius: 19px;

  background:
    linear-gradient(
      135deg,
      var(--accent),
      #3fcca0
    );

  color: var(--accent-dark);

  cursor: pointer;

  box-shadow:
    0 16px 40px
    rgba(94, 230, 181, 0.18);

  transition:
    transform 120ms ease,
    background 150ms ease,
    opacity 150ms ease;
}


.capture-button:active {
  transform: scale(0.985);
}


.capture-button > span {
  font-size: 1.5rem;
}


.capture-button strong {
  font-size: 1.12rem;
}


.capture-button:disabled {
  opacity: 0.48;

  cursor: not-allowed;
}


.capture-button.is-capturing {
  background:
    linear-gradient(
      135deg,
      #ff7a88,
      #ff5d71
    );

  color: white;
}


/* =========================================================
   OCR結果
========================================================= */

.recognized-panel {
  width: 100%;
  max-width: 520px;

  margin: 16px auto 0;
}


.recognized-question {
  min-width: 0;

  padding: 17px;

  overflow: hidden;
}


.recognized-question span,
.recognized-question small,
.recognized-number span {
  display: block;

  color: var(--muted);
}


.recognized-question strong {
  display: block;

  min-width: 0;

  margin: 8px 0 5px;

  overflow-wrap: anywhere;

  font-size: 1.1rem;
}


.recognized-question small {
  overflow-wrap: anywhere;
}


.recognized-numbers {
  width: 100%;

  display: grid;

  grid-template-columns:
    minmax(0, 1fr)
    minmax(0, 1fr);

  gap: 10px;

  margin-top: 11px;
}


.recognized-number {
  min-width: 0;

  padding: 14px 8px;

  overflow: hidden;

  text-align: center;
}


.recognized-number span {
  font-size: 0.85rem;

  white-space: nowrap;
}


.recognized-number strong {
  display: block;

  width: 100%;
  min-width: 0;

  margin-top: 7px;

  overflow: hidden;

  font-size:
    clamp(1.6rem, 10vw, 4rem);

  line-height: 1.1;

  text-overflow: ellipsis;
  white-space: nowrap;
}


/* =========================================================
   リモコン
========================================================= */

.connection-card {
  display: flex;
  align-items: center;
  gap: 13px;

  padding: 18px;
}


.connection-card > span {
  flex-shrink: 0;

  font-size: 2rem;
}


.connection-card > div {
  min-width: 0;

  display: grid;
  gap: 4px;
}


.remote-button {
  width: 100%;
  min-height: 180px;

  margin-top: 16px;

  border: 0;
  border-radius: 28px;

  background:
    linear-gradient(
      145deg,
      var(--accent),
      #3fcca0
    );

  color: var(--accent-dark);

  cursor: pointer;
}


.remote-button strong,
.remote-button small {
  display: block;
}


.remote-button strong {
  font-size:
    clamp(2rem, 10vw, 4rem);
}


.remote-button small {
  margin-top: 8px;

  font-weight: 800;
}


.result-panel {
  margin-top: 16px;
  padding: 24px 18px;

  overflow: hidden;

  text-align: center;
}


.result-panel > span {
  color: var(--muted);

  font-weight: 850;
}


.result-panel > strong {
  display: block;

  max-width: 100%;

  margin: 8px 0;

  overflow: hidden;

  font-size:
    clamp(2rem, 13vw, 5rem);

  text-overflow: ellipsis;
  white-space: nowrap;
}


.result-panel p {
  margin-bottom: 0;

  color: var(--muted);

  overflow-wrap: anywhere;
}


.result-panel.left {
  border-color: var(--blue);
}


.result-panel.right {
  border-color: var(--pink);
}


.result-panel.both {
  border-color: var(--accent);
}


.result-panel.none {
  border-color: var(--yellow);
}


.result-panel.error {
  border-color: var(--red);
}


/* =========================================================
   設定
========================================================= */

dialog {
  width:
    min(calc(100% - 30px), 470px);

  padding: 0;

  border: 0;
  border-radius: 22px;

  background: transparent;
  color: var(--text);
}


dialog::backdrop {
  background:
    rgba(2, 7, 16, 0.8);

  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}


.dialog-card {
  max-height: 82vh;

  padding: 20px;

  overflow-y: auto;

  border: 1px solid var(--border);
  border-radius: 22px;

  background: var(--panel);
}


.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;

  padding: 17px 0;

  border-top:
    1px solid var(--border);
}


.setting-row > span,
.setting-column-heading > span {
  min-width: 0;

  display: grid;
  gap: 4px;
}


.setting-row small,
.setting-column small {
  color: var(--muted);
}


.setting-row select {
  width: min(47%, 190px);
  min-height: 42px;

  padding: 0 10px;

  border: 1px solid var(--border);
  border-radius: 11px;

  background: #091425;
  color: var(--text);
}


.setting-column {
  padding: 17px 0;

  border-top:
    1px solid var(--border);
}


.setting-column input[type="range"] {
  width: 100%;

  margin: 18px 0;
}


.secondary-button,
.dialog-save {
  min-height: 45px;

  padding: 0 15px;

  border-radius: 12px;

  font-weight: 900;

  cursor: pointer;
}


.secondary-button {
  border: 1px solid var(--border);

  background: var(--panel-light);
  color: var(--text);
}


.secondary-button:disabled {
  opacity: 0.45;

  cursor: not-allowed;
}


.dialog-actions {
  margin-top: 10px;
}


.dialog-actions button {
  flex: 1;
}


.dialog-save {
  border: 0;

  background: var(--accent);
  color: var(--accent-dark);
}


/* =========================================================
   スマホ
========================================================= */

@media (max-width: 560px) {
  .app {
    padding-right: 12px;
    padding-left: 12px;
  }

  .topbar {
    margin-bottom: 18px;
  }

  .section-title {
    margin-top: 18px;
  }

  .recognized-numbers {
    gap: 8px;
  }

  .recognized-number {
    padding: 12px 5px;
  }

  .recognized-number span {
    font-size: 0.78rem;
  }

  .recognized-number strong {
    font-size:
      clamp(1.5rem, 9.5vw, 2.8rem);
  }

  .camera-result-overlay > strong {
    font-size:
      clamp(2rem, 13vw, 3.6rem);
  }

  .setting-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .setting-row select {
    width: 100%;
  }
}