:root {
  --bg-1: #1a1130;
  --bg-2: #2a1a4a;
  --accent: #c9a3ff;
  --accent-strong: #a06bff;
  --gold: #f0c96b;
  --text: #f3eefc;
  --text-dim: #b9aed6;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(255, 255, 255, 0.12);
  --danger: #ff8a8a;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: radial-gradient(ellipse at top, var(--bg-2), var(--bg-1) 60%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
}

.header {
  text-align: center;
  padding: 28px 8px 12px;
}

.header h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

.header .sub {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.main {
  flex: 1;
  padding-bottom: 24px;
}

.screen.is-hidden {
  display: none;
}

/* --- capture screen --- */
.preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 20px;
  overflow: hidden;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.preview-wrap img#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.preview-wrap:not(.is-empty) img#preview {
  display: block;
}

.preview-wrap:not(.is-empty) .preview-placeholder {
  display: none;
}

.preview-placeholder {
  text-align: center;
  color: var(--text-dim);
  padding: 24px;
}

.placeholder-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 10px;
}

.preview-placeholder p {
  margin: 0;
  line-height: 1.6;
  font-size: 0.9rem;
}

.button-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

.btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 16px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

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

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

.btn-primary {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent-strong), #6b3fd6);
  color: #fff;
  box-shadow: 0 8px 20px rgba(160, 107, 255, 0.35);
  margin-bottom: 14px;
}

.btn-icon {
  margin-right: 6px;
}

.hint {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin: 0;
}

/* --- loading --- */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
}

.loader-hand {
  font-size: 4rem;
  animation: pulse 1.4s ease-in-out infinite;
  margin-bottom: 18px;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.7; }
}

#loading-text {
  color: var(--text-dim);
  font-size: 0.95rem;
}

/* --- result --- */
.result-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 18px 20px;
  margin-bottom: 12px;
}

.result-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  color: var(--gold);
}

.result-card h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--accent);
}

.result-card p {
  margin: 0;
  line-height: 1.75;
  font-size: 0.9rem;
  color: var(--text);
}

.result-overall {
  background: linear-gradient(135deg, rgba(240, 201, 107, 0.14), rgba(160, 107, 255, 0.12));
  border-color: rgba(240, 201, 107, 0.3);
}

.lines-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.lines-grid .result-card {
  margin-bottom: 0;
}

.result-advice {
  border-color: rgba(240, 201, 107, 0.4);
}

.error-card h2 {
  color: var(--danger);
}

#btn-retry, #btn-error-retry {
  margin-top: 6px;
}

.footer {
  text-align: center;
  padding: 8px 8px 20px;
}

.footer p {
  margin: 0;
  font-size: 0.7rem;
  color: var(--text-dim);
  opacity: 0.7;
}

@media (min-width: 400px) {
  .lines-grid {
    gap: 14px;
  }
}
