:root {
  --header-height: 50px;
  --footer-height: 50px;
  --frame-color: #ffffff;
  --frame-accent: #4fc3f7;
  --bg: #000;
  --text: #fff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
    sans-serif;
  overflow: hidden;
}

.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.view[hidden] {
  display: none;
}

/* ===== ヘッダー ===== */
.qr-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10;
}
.qr-header__logo {
  display: flex;
  align-items: center;
  background: #fff;
  padding: 4px 10px;
  border-radius: 4px;
}
.qr-header__logo img {
  height: 28px;
  width: auto;
  display: block;
}
.qr-header__office {
  font-size: 14px;
  opacity: 0.9;
}
.qr-header__office--demo {
  background: #d68000;
  color: #fff;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 4px;
  opacity: 1;
}

/* ===== カメラプレビュー領域 ===== */
.qr-main {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #111;
}
#camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== カメラ ミラー表示 ===== */
#camera.mirrored {
  transform: scaleX(-1);
}

/* ===== 読取枠 (右下寄せ) ===== */
.qr-frame {
  position: absolute;
  right: 6%;
  bottom: 12%;
  width: min(40vmin, 240px);
  height: min(40vmin, 240px);
  pointer-events: none;
}
.qr-main.fullscreen-mode .qr-frame {
  display: none;
}
.qr-frame__corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 4px solid var(--frame-color);
}
.qr-frame__corner--tl {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
}
.qr-frame__corner--tr {
  top: 0;
  right: 0;
  border-left: none;
  border-bottom: none;
}
.qr-frame__corner--bl {
  bottom: 0;
  left: 0;
  border-right: none;
  border-top: none;
}
.qr-frame__corner--br {
  bottom: 0;
  right: 0;
  border-left: none;
  border-top: none;
}
.qr-frame__label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -28px;
  text-align: center;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* ===== 検出オーバーレイ ===== */
.qr-detection-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ===== ステータスバナー ===== */
.qr-status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 53, 69, 0.9);
  color: #fff;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  max-width: 90%;
  text-align: center;
  z-index: 20;
}

/* ===== トースト (QR通知用) ===== */
.qr-toast {
  position: absolute;
  top: calc(var(--header-height) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(33, 33, 33, 0.95);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 18px 24px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
  max-width: min(560px, calc(100vw - 24px));
  width: max-content;
  text-align: center;
  z-index: 25;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: qr-toast-in 200ms ease-out;
  word-break: break-word;
}
.qr-toast--warn {
  background: rgba(220, 130, 0, 0.97);
  border-color: rgba(255, 220, 120, 0.85);
}
.qr-toast--error {
  background: rgba(208, 36, 36, 0.97);
  border-color: rgba(255, 150, 150, 0.85);
  animation:
    qr-toast-in 200ms ease-out,
    qr-toast-shake 360ms ease-in-out 200ms;
}
@keyframes qr-toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -12px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}
@keyframes qr-toast-shake {
  0%,
  100% {
    transform: translate(-50%, 0);
  }
  20% {
    transform: translate(calc(-50% - 6px), 0);
  }
  40% {
    transform: translate(calc(-50% + 6px), 0);
  }
  60% {
    transform: translate(calc(-50% - 4px), 0);
  }
  80% {
    transform: translate(calc(-50% + 4px), 0);
  }
}
@media (max-width: 480px) {
  .qr-toast {
    font-size: 16px;
    padding: 14px 18px;
    top: calc(var(--header-height) + 8px);
    max-width: calc(100vw - 16px);
  }
}

/* ===== フッター ===== */
.qr-footer {
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10;
}
.qr-footer__icon-button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 16px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-footer__icon-button:hover {
  background: rgba(255, 255, 255, 0.1);
}
.qr-footer__clock {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* ===== 結果画面 ===== */
.result-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #1a1a1a;
  gap: 12px;
}
.result-header__back {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #fff;
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
}
.result-header__title {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}
/* ===== 初期画面 ===== */
#init-view {
  background: #1a1d23;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}
.init-card {
  width: 100%;
  max-width: 420px;
  background: #242831;
  border-radius: 8px;
  padding: 28px 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.init-title {
  font-size: 18px;
  margin: 0 0 8px;
}
.init-desc {
  font-size: 13px;
  color: #aab;
  margin: 0 0 20px;
  line-height: 1.5;
}
.init-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.init-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}
.init-field[hidden] {
  display: none;
}
.init-field span {
  font-weight: 600;
}
.init-field input {
  background: #1a1d23;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
.init-field input:focus {
  outline: none;
  border-color: #4fc3f7;
}
.init-field input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  background: #11141a;
}
.init-field__badge {
  display: inline-block;
  background: #b06e00;
  color: #fff;
  font-size: 10px;
  font-style: normal;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}
.init-field small {
  color: #889;
  font-size: 11px;
  line-height: 1.5;
}
.init-field code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
}
.init-error {
  background: rgba(220, 53, 69, 0.15);
  border: 1px solid rgba(220, 53, 69, 0.5);
  color: #ff8a95;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 13px;
}
.init-submit {
  background: #2962ff;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.init-submit:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* ===== 設定画面 ===== */
.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #1a1a1a;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 14px;
  gap: 12px;
}
.settings-row label {
  flex: 1;
}
.settings-row select {
  background: #2a2a2a;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 6px 8px;
  max-width: 60%;
}
.settings-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
}
.settings-row--action {
  justify-content: center;
  border-bottom: none;
  margin-top: 24px;
}
.settings-row--meta {
  border-bottom: none;
  color: #889;
  font-size: 12px;
  margin-top: 16px;
}
.settings-reset {
  background: #b71c1c;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 10px 24px;
  font-size: 14px;
  cursor: pointer;
}
.settings-reset:disabled {
  background: #555;
  cursor: not-allowed;
  opacity: 0.6;
}

.result-iframe {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
}
