/* ============================================================
   影消しスキャン - メインスタイルシート
   メインカラー: 白 (#ffffff, #f8fafc)
   サブカラー（アクセント）: エメラルドグリーン (#10b981)
   ============================================================ */

:root {
  /* 背景・基本カラー */
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --input-bg: #ffffff;

  /* エメラルドグリーン・アクセント */
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-soft: #ecfdf5;
  --accent-border: #a7f3d0;
  --done: #059669;

  /* アニメーション用イージング */
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;
  line-height: 1.5;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  transition: max-width 0.3s ease, padding 0.3s ease;
}

/* ------------------------------------------------------------
   ヘッダー & 認証バー
   ------------------------------------------------------------ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.auth-bar {
  display: flex;
  align-items: center;
}

.auth-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.auth-user-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ------------------------------------------------------------
   カード & 見出し
   ------------------------------------------------------------ */
h1 {
  font-size: 1.4rem;
  margin: 8px 0 12px;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 12px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  /* 固定の工程パンくずに隠れないようスクロール先を調整 */
  scroll-margin-top: 72px;
}

.card > h2 {
  margin: 0;
}

/* ------------------------------------------------------------
   レイアウト行・ボタン・コントロール
   ------------------------------------------------------------ */
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: #334155;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition:
    transform 0.15s var(--ease-out),
    box-shadow 0.2s ease,
    background-color 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease;
}

.btn.small {
  padding: 5px 10px;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn[aria-pressed="true"] {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent-hover);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-hover);
  color: #ffffff;
  width: 100%;
  margin-top: 10px;
  font-weight: 600;
}

.btn.primary:not(:disabled):hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.btn:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
}

.btn:not(:disabled):active {
  transform: scale(0.98);
  box-shadow: none;
}

.btn:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--accent-border);
  outline-offset: 2px;
}

/* 押した位置から広がるリップル */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.12);
  transform: scale(0);
  pointer-events: none;
  animation: ripple 0.6s ease-out forwards;
}

.btn.primary .ripple {
  background: rgba(255, 255, 255, 0.4);
}

/* ------------------------------------------------------------
   ステータス・エラー・入力
   ------------------------------------------------------------ */
.status {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 6px 0;
  overflow-wrap: anywhere;
}

.error {
  color: #dc2626;
  font-weight: 600;
  font-size: 0.9rem;
  margin: 6px 0;
  overflow-wrap: anywhere;
}

.slider {
  display: block;
  margin: 10px 0;
  font-size: 0.9rem;
  color: var(--ink);
  font-weight: 500;
}

.slider span {
  font-weight: 600;
  color: var(--accent-hover);
  margin-left: 4px;
}

.slider input[type="range"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  accent-color: var(--accent);
  cursor: pointer;
}

textarea {
  width: 100%;
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-border);
}

.low {
  font-size: 0.85rem;
  background: #fef3c7;
  color: #92400e;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #fde68a;
  overflow-wrap: anywhere;
}

.low-word {
  background: #fde047;
  padding: 0 3px;
  border-radius: 3px;
}

/* ------------------------------------------------------------
   Canvas & プレビュー表示
   ------------------------------------------------------------ */
.persp-canvas {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  margin: 0 auto;
  height: auto;
  touch-action: none;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.compare {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

.compare canvas {
  display: block;
  max-width: 100%;
  max-height: 60vh;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.compare .cmp-top {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  border: none;
}

/* ------------------------------------------------------------
   並べて表示（元写真 vs 影消し後）スタイル
   ------------------------------------------------------------ */
.side-by-side-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0;
}

.side-col {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.side-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: bold;
  border-radius: 4px;
  background: #e2e8f0;
  color: #475569;
  margin-bottom: 8px;
}

.side-badge.highlight {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.side-canvas {
  width: 100%;
  height: auto;
  max-height: 45vh;
  border-radius: 6px;
  object-fit: contain;
  background: #f1f5f9;
  display: block;
}

@media (max-width: 767px) {
  .side-by-side-wrapper {
    grid-template-columns: 1fr;
  }
}

/* ------------------------------------------------------------
   オーバーレイ（iOS保存用など）
   ------------------------------------------------------------ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;
  padding: 24px;
  overflow: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.overlay img {
  display: block;
  max-width: 90%;
  max-height: 70vh;
  height: auto;
  margin: 16px 0;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

/* ------------------------------------------------------------
   工程パンくず・アコーディオン
   ------------------------------------------------------------ */
#breadcrumb {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0 -16px 12px;
  padding: 0 16px;
  background: rgba(248, 250, 252, 0.88);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

#breadcrumb::-webkit-scrollbar {
  display: none;
}

#breadcrumb ol {
  display: flex;
  align-items: center;
  min-width: max-content;
  margin: 0;
  padding: 8px 0;
  list-style: none;
}

.crumb + .crumb::before {
  content: "›";
  margin: 0 6px;
  color: var(--muted);
  opacity: 0.6;
}

.crumb button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.2s ease, opacity 0.2s ease, background-color 0.2s ease;
}

.crumb button:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.crumb.is-locked button {
  opacity: 0.35;
  cursor: not-allowed;
}

.crumb button[aria-disabled="true"] {
  cursor: default;
}

.crumb.is-current button {
  font-weight: 700;
  color: var(--accent);
}

/* 工程の見出しボタン */
.acc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 4px 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.acc-head::after {
  content: "▼";
  margin-left: auto;
  padding-left: 8px;
  font-size: 0.75em;
  color: var(--muted);
  transition: transform 0.35s var(--ease-out);
}

.acc-head[aria-expanded="true"]::after {
  transform: rotate(180deg);
}

/* 完了した工程の見出しに ✓ バッジ */
.card.is-done > h2 > .acc-head::before {
  content: "✓";
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 1.4em;
  height: 1.4em;
  border-radius: 50%;
  background: var(--done);
  color: #ffffff;
  font-size: 0.8em;
  font-weight: bold;
  animation: pop 0.5s var(--ease-spring) both;
}

.acc-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s ease;
}

.acc-body.is-open {
  grid-template-rows: 1fr;
}

.acc-inner {
  overflow: hidden;
  min-height: 0;
}

.acc-body.is-open > .acc-inner {
  padding-top: 14px;
}

/* 工程解放時の浮き上がり */
.card:not([hidden]) {
  animation: rise 0.5s var(--ease-out) both;
}

/* ------------------------------------------------------------
   スケルトン & ローディング
   ------------------------------------------------------------ */
.stage {
  position: relative;
}

.skeleton {
  position: relative;
  width: 100%;
  padding: 8px 0;
  transition: opacity 0.2s ease;
}

.skeleton.is-leaving {
  opacity: 0;
}

.skeleton-block,
.skeleton-line {
  border-radius: 6px;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 37%, #e2e8f0 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton-block {
  margin-bottom: 10px;
}

.skeleton-line {
  height: 12px;
  width: 100%;
  margin: 10px 0;
}

.skeleton-overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px;
  border-radius: 8px;
  background: rgba(248, 250, 252, 0.65);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.stage:not(.dim)[aria-busy="true"] > :is(canvas, .compare, .side-by-side-wrapper, textarea) {
  display: none;
}

.stage.dim > :is(.compare, .side-by-side-wrapper) {
  transition: opacity 0.3s ease;
}

.stage.dim[aria-busy="true"] > :is(.compare, .side-by-side-wrapper) {
  opacity: 0.35;
}

/* 差し替えアニメーション */
.fade-in {
  animation: fade-in 0.45s ease-out;
}

textarea.flash {
  animation: flash-in 1.2s ease-out;
}

.error:not([hidden]) {
  animation: shake 0.45s ease-in-out;
}

/* ------------------------------------------------------------
   ログインページ用スタイル
   ------------------------------------------------------------ */
.login-container {
  min-height: 80vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 28px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
  text-align: center;
}

.login-card h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--ink);
}

.login-card p {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 0 0 24px;
}

.login-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
}

.back-link {
  display: inline-block;
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.2s ease;
}

.back-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ------------------------------------------------------------
   デスクトップ・PC用レスポンシブスタイル (900px 以上)
   ------------------------------------------------------------ */
@media (min-width: 900px) {
  main {
    max-width: 1120px;
    padding: 24px;
  }

  .app-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
  }

  .app-header h1 {
    font-size: 1.75rem;
  }

  #breadcrumb {
    margin: 0 -24px 20px;
    padding: 4px 24px;
  }

  /* カード余白・配置の最適化 */
  .card {
    padding: 24px;
    border-radius: 14px;
  }

  .acc-head {
    font-size: 1.25rem;
  }

  /* PC大画面での各ステージ canvas 最大高さを 65vh に調整 */
  .persp-canvas,
  .compare canvas,
  .side-canvas {
    max-height: 65vh;
  }

  /* コントロール行・ボタンのPC向け配置 */
  .btn.primary {
    max-width: 380px;
    margin-left: auto;
    margin-right: auto;
  }

  /* 影消しスライダーなどの調整 */
  .slider {
    max-width: 600px;
  }

  textarea {
    font-size: 1rem;
    padding: 14px;
  }
}

/* ------------------------------------------------------------
   Keyframes
   ------------------------------------------------------------ */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pop {
  0% {
    transform: scale(0);
  }
  60% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes busy-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes ripple {
  to {
    transform: scale(1);
    opacity: 0;
  }
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

@keyframes fade-in {
  from {
    opacity: 0.25;
  }
  to {
    opacity: 1;
  }
}

@keyframes flash-in {
  0% {
    background-color: var(--accent-soft);
    box-shadow: 0 0 0 3px var(--accent-border);
  }
  100% {
    background-color: #ffffff;
    box-shadow: none;
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
