:root {
  color-scheme: light;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Meiryo", "MS PGothic", sans-serif;
  line-height: 1.6;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  /* スクロール禁止になっている可能性があるので、明示的に許可する */
  overflow-x: hidden;
  overflow-y: auto;
  /* モバイルでのレイアウト崩れを防ぐ */
  -webkit-text-size-adjust: 100%;
}

body {
  background: #f5f5f5;
  color: #333;
}

.scanner {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.scanner__video {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100vw;
  height: auto;
  max-height: 100vh;
  object-fit: contain;
  background: #000;
  z-index: 0;
}

.scanner--active .scanner__video {
  display: block;
}

.scanner__overlay {
  display: none;
  position: absolute;
  pointer-events: none;
  width: 0;
  height: 0;
  z-index: 1;
}

.scanner--debug.scanner--active .scanner__overlay {
  display: block;
}

.scanner__hud {
  display: flex;
  position: absolute;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100%;
  max-height: 100vh;
  padding: 1.5rem;
  flex-direction: column;
  gap: 1.25rem;
  background: linear-gradient(135deg, rgba(10, 15, 18, 0.4), rgba(10, 15, 18, 0.2));
  backdrop-filter: none;
  box-shadow: none;
  z-index: 2;
  overflow-y: auto;
  overflow-x: hidden;
}

/* 帳票スタイル */
.form-container {
  display: flex;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  margin: 0 auto;
  padding: 2rem;
  flex-direction: column;
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border: 1px solid #ddd;
  z-index: 2;
  overflow-y: auto;
}

.form-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #333;
}

.form-title {
  margin: 0 0 1rem 0;
  font-size: 1.5rem;
  font-weight: bold;
  text-align: center;
  color: #333;
}

.form-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.form-status {
  margin-bottom: 1rem;
  padding: 0.5rem;
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.9rem;
  text-align: center;
  color: #666;
}

.form-body {
  margin-bottom: 2rem;
}

.form-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #333;
}

.form-table th,
.form-table td {
  padding: 0.75rem 1rem;
  border: 1px solid #333;
  text-align: left;
}

.form-table th {
  width: 30%;
  background: #f5f5f5;
  font-weight: bold;
  color: #333;
  font-size: 0.95rem;
}

.form-table td {
  background: #fff;
  color: #333;
  font-size: 1rem;
  word-break: break-word;
}

.form-actions {
  margin-top: 1rem;
  text-align: center;
}

.form-results {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #ddd;
}

.results-title {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: bold;
  color: #333;
}

.results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid #333;
  background: #fff;
  max-height: 200px;
  overflow-y: auto;
}

.results-list li {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #ddd;
  font-size: 0.9rem;
  color: #333;
}

.results-list li:last-child {
  border-bottom: none;
}

.results-list li .text {
  font-weight: normal;
  color: #333;
}

.results-list li .meta {
  font-size: 0.8rem;
  color: #666;
}

.btn {
  padding: 0.5rem 1rem;
  border: 1px solid #333;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: normal;
  cursor: pointer;
  transition: background-color 0.2s ease;
  background: #fff;
  color: #333;
}

.btn-primary {
  background: #4a90e2;
  color: #fff;
  border-color: #4a90e2;
}

.btn-primary:hover:enabled {
  background: #357abd;
}

.btn-secondary {
  background: #e74c3c;
  color: #fff;
  border-color: #e74c3c;
}

.btn-secondary:hover:enabled {
  background: #c0392b;
}

.btn-upload {
  background: #f39c12;
  color: #fff;
  border-color: #f39c12;
}

.btn-upload:hover {
  background: #d68910;
}

.btn-copy {
  background: #27ae60;
  color: #fff;
  border-color: #27ae60;
}

.btn-copy:hover {
  background: #229954;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 旧スタイル（後方互換性のため保持） */
.hud__controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.hud__controls button {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  color: #0d1117;
  background: #9de1a4;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

#stopButton {
  display: none;
}

.scanner--active #stopButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.scanner--active #startButton {
  display: none;
}

.hud__controls button:hover:enabled {
  transform: translateY(-1px);
}

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

.hud__controls #stopButton {
  background: #f9a8a8;
}

.hud__upload {
  display: flex;
  margin-bottom: 0.5rem;
}

.upload-button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: #0d1117;
  background: #facc86;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.upload-button:hover {
  transform: translateY(-1px);
}

.upload-button:active {
  transform: translateY(0);
}

.hud__status {
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: #9fcdfb;
}

.hud__fields {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.hud__fields-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.hud__fields-header h2 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

.copy-button {
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  color: #0d1117;
  background: #9de1a4;
  transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.15s ease;
}

.copy-button:hover {
  transform: translateY(-1px);
  background: #7dd184;
}

.copy-button:active {
  transform: translateY(0);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.field:last-child {
  border-bottom: none;
}

.field--inline {
  flex-direction: row;
  justify-content: space-between;
  align-items: baseline;
}

.field .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.7;
}

.field .value {
  font-size: 1.15rem;
  font-weight: 600;
  word-break: break-word;
}

.hud__results {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hud__results h2 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

#resultList {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.15);
}

#resultList li {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#resultList li:last-child {
  border-bottom: none;
}

#resultList li .text {
  font-weight: 600;
}

#resultList li .meta {
  font-size: 0.75rem;
  opacity: 0.65;
}

.legal {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #ddd;
  font-size: 0.75rem;
  color: #666;
  line-height: 1.4;
}

.legal a {
  color: #4a90e2;
  text-decoration: underline;
}

[hidden] {
  display: none !important;
}

#debug-panel {
  margin-top: 0.5rem;
  padding: 0.5rem;
  border-top: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.7rem;
  line-height: 1.3;
  background: #f9f9f9;
  border: 1px solid #ddd;
  /* デスクトップ / 共通 */
  max-height: 40vh;
  overflow-y: auto;
}

#debug-panel h2 {
  margin: 0 0 0.5rem 0;
  font-size: 0.8rem;
  font-weight: bold;
  color: #333;
}

.debug-block {
  margin: 0.15rem 0;
}

.debug-mono {
  font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.55rem;
  line-height: 1.3;
  overflow-x: auto;
}

/* Debug内の長いテキストは個別にスクロール */
#debug-panel pre {
  max-height: 30vh;
  overflow-y: auto;
  padding: 0.5rem;
  box-sizing: border-box;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  color: #333;
}

#debug-panel details {
  margin-top: 0.3rem;
}

#debug-panel details summary {
  cursor: pointer;
  padding: 0.25rem 0;
  color: #333;
  user-select: none;
  font-size: 0.7rem;
  font-weight: bold;
}

#debug-panel details summary:hover {
  color: #4a90e2;
}

#debug-panel details[open] summary {
  margin-bottom: 0.3rem;
}

@media (max-width: 720px) {
  body {
    font-size: 12px;
  }
  .scanner {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .scanner__hud {
    width: 100%;
    height: auto;
    bottom: 0;
    top: auto;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
  }
  .form-container {
    width: 95%;
    max-width: 95%;
    padding: 1rem;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-height: 95vh;
  }
  .form-title {
    font-size: 1.2rem;
  }
  .form-table th,
  .form-table td {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }
  .form-table th {
    width: 35%;
  }
  .hud__results {
    max-height: 160px;
  }
  #debug-panel {
    font-size: 0.55rem;
    max-height: 45vh;
    padding: 0.25rem;
    margin-top: 0.5rem;
  }
  #debug-panel h2 {
    font-size: 0.6rem;
    margin: 0 0 0.2rem;
  }
  #debug-panel details summary {
    font-size: 0.55rem;
    padding: 0.1rem 0;
  }
  #debug-panel pre {
    max-height: 35vh;
    padding: 0.25rem;
  }
  .debug-block {
    margin: 0.1rem 0;
  }
  .debug-mono {
    font-size: 0.5rem;
    line-height: 1.2;
  }
  #debug-panel details {
    margin-top: 0.25rem;
  }
  #debug-panel details[open] summary {
    margin-bottom: 0.25rem;
  }
}

.name-region-fixed {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.5rem;
  background: rgba(10, 15, 18, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.name-region-fixed canvas {
  max-width: 100%;
  max-height: 200px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: #fff;
}

