:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-accent: #16a34a;
  --color-bg: #f3f4f6;
  --color-surface: #ffffff;
  --color-text: #1f2937;
  --color-border: #d1d5db;
  --color-danger: #dc2626;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* hidden属性をdisplay指定(.screen等のflex)より優先させる */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", sans-serif;
  height: 100%;
  overscroll-behavior: none;
}

.app-header {
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: var(--color-primary);
  color: #fff;
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + var(--safe-bottom));
  min-height: calc(100vh - 60px);
}

/* 初期化インジケータ */
.init-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 0;
  color: #4b5563;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* エラーバナー */
.error-banner {
  background: #fee2e2;
  color: var(--color-danger);
  border: 1px solid #fca5a5;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* 警告バナー(黄色系・非ブロック) */
.warn-banner {
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ホーム画面 */
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 16px 18px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.08s ease, opacity 0.2s ease;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn .icon {
  font-size: 1.2rem;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-secondary {
  background: #e5e7eb;
  color: var(--color-text);
}

.btn-accent {
  background: var(--color-accent);
  color: #fff;
}

.page-badge {
  align-self: center;
  background: var(--color-primary-dark);
  color: #fff;
  font-weight: 700;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.95rem;
}

.page-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
}

.page-thumbs img {
  width: 72px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: #fff;
}

/* 調整・プレビュー画面 */
.hint {
  margin: 0;
  font-size: 0.9rem;
  color: #4b5563;
  text-align: center;
}

.canvas-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111827;
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
}

#adjust-canvas, #preview-canvas {
  max-width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}

.btn-row {
  display: flex;
  gap: 12px;
}

.btn-row .btn {
  flex: 1;
}

/* PDF出力ダイアログ */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}

.dialog {
  background: var(--color-surface);
  border-radius: 16px;
  padding: 24px 20px calc(20px + var(--safe-bottom));
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.dialog-title {
  margin: 0 0 8px;
  font-size: 1.15rem;
  text-align: center;
}

.dialog-info {
  margin: 0 0 18px;
  font-size: 0.9rem;
  color: #4b5563;
  text-align: center;
}

.dialog-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
