:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #f1f5f9;
  --sub: #94a3b8;
  --accent: #22c55e;
  --danger: #f87171;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
}

.app-header h1 { font-size: 22px; letter-spacing: 0.1em; }

.status {
  font-size: 12px;
  color: var(--sub);
  background: var(--panel);
  padding: 4px 10px;
  border-radius: 999px;
}
.status.is-active { color: var(--accent); }
.status.is-error { color: var(--danger); }

.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
}

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

/* カメラ */
.camera {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
}

.camera video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.guide {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 80%;
  height: 40%;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: border-color 0.15s;
}
.camera.is-hit .guide { border-color: var(--accent); }

.camera-message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  background: rgba(15, 23, 42, 0.92);
  font-size: 14px;
  line-height: 1.6;
}
.camera-message[hidden] { display: none; }

.camera-message button {
  background: var(--accent);
  color: #052e16;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: bold;
}

/* 結果 */
.result {
  margin-top: 16px;
  padding: 16px;
  background: var(--panel);
  border-radius: 16px;
  text-align: center;
  transition: background 0.2s;
}
.result.is-hit { background: #14532d; }

.result-label { font-size: 12px; color: var(--sub); }

.result-code {
  margin: 6px 0;
  font-size: 32px;
  font-weight: bold;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.result-hint { font-size: 12px; color: var(--sub); }

/* 履歴 */
.history { margin-top: 20px; }
.history h2 { font-size: 14px; color: var(--sub); margin-bottom: 8px; }
.history-empty { font-size: 13px; color: var(--sub); }
.history-empty[hidden] { display: none; }

.history-list { list-style: none; }
.history-list li {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--panel);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.history-list .time { color: var(--sub); font-size: 13px; }

/* タブバー */
.tabbar {
  display: flex;
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  flex: 1;
  padding: 14px 0;
  background: none;
  border: none;
  color: var(--sub);
  font-size: 14px;
}
.tab.is-active { color: var(--accent); font-weight: bold; }
.tab:disabled { opacity: 0.4; }
