*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-card-hover: #1b2a4a;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text: #edf2f7;
  --text-muted: #a0aec0;
  --green: #48bb78;
  --yellow: #ecc94b;
  --red: #fc8181;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, .35);
  --transition: .25s cubic-bezier(.4, 0, .2, 1);
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Header ─────────────────────────────────── */

header {
  text-align: center;
  padding: 1.5rem 1rem 1rem;
  background: linear-gradient(135deg, #16213e 0%, #1a1a2e 100%);
  border-bottom: 1px solid rgba(233, 69, 96, .2);
}

header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: .02em;
}

header .subtitle {
  font-size: .85rem;
  color: var(--accent);
  font-weight: 500;
  margin-top: .2rem;
}

/* ── Main ───────────────────────────────────── */

main {
  flex: 1;
  padding: 1.25rem 1rem 6rem;
  max-width: 540px;
  width: 100%;
  margin: 0 auto;
}

/* ── Sections / Views ───────────────────────── */

.view { display: none; }
.view.active { display: block; }

/* ── Setup (API-Key) ────────────────────────── */

#setup-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding-top: 3rem;
}

#setup-view .icon-large {
  width: 80px;
  height: 80px;
  opacity: .85;
}

#setup-view h2 {
  font-size: 1.2rem;
}

#setup-view p {
  color: var(--text-muted);
  font-size: .9rem;
  text-align: center;
  line-height: 1.5;
}

/* ── Capture ────────────────────────────────── */

#capture-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding-top: 2rem;
}

.capture-area {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 2px dashed rgba(233, 69, 96, .35);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(22, 33, 62, .5);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
  overflow: hidden;
}

.capture-area:hover,
.capture-area:focus-visible {
  border-color: var(--accent);
  background: rgba(22, 33, 62, .8);
}

.capture-area.has-image {
  border-style: solid;
  border-color: var(--accent);
}

.capture-area img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: .5rem;
}

.capture-area .placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  color: var(--text-muted);
}

.capture-area.has-image .placeholder { display: none; }

.capture-area .placeholder svg {
  width: 56px;
  height: 56px;
  opacity: .5;
}

.capture-area .placeholder span {
  font-size: .9rem;
}

.capture-buttons {
  display: flex;
  gap: .75rem;
  width: 100%;
}

/* ── Buttons ────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .9rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform .15s, opacity var(--transition);
  min-height: 52px;
  touch-action: manipulation;
}

.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  flex: 1;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  flex: 1;
  border: 1px solid rgba(255, 255, 255, .08);
}

.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }

.btn-full { width: 100%; }

.btn-icon {
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, .08);
  flex: none;
}

/* ── Input ──────────────────────────────────── */

.input-group {
  width: 100%;
}

.input-group label {
  display: block;
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .4rem;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  padding: .85rem 1rem;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color var(--transition);
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Loading ────────────────────────────────── */

#loading-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding-top: 4rem;
}

.spinner {
  width: 56px;
  height: 56px;
  border: 4px solid rgba(233, 69, 96, .2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pulse-text {
  font-size: 1.1rem;
  color: var(--text-muted);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: .5; }
  50% { opacity: 1; }
}

/* ── Results ────────────────────────────────── */

#results-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .25rem;
}

.results-header h2 {
  font-size: 1.1rem;
}

.results-count {
  font-size: .85rem;
  color: var(--text-muted);
}

.match-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, .05);
  transition: transform var(--transition), border-color var(--transition);
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.match-card:hover {
  transform: translateY(-2px);
  border-color: rgba(233, 69, 96, .25);
}

.match-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: rgba(0, 0, 0, .3);
  flex-shrink: 0;
}

.match-info {
  flex: 1;
  min-width: 0;
}

.match-score {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 700;
  margin-bottom: .4rem;
}

.score-high { background: rgba(72, 187, 120, .2); color: var(--green); }
.score-mid  { background: rgba(236, 201, 75, .2); color: var(--yellow); }
.score-low  { background: rgba(252, 129, 129, .2); color: var(--red); }

.match-order {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .15rem;
}

.match-position {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .35rem;
}

.match-action {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: .25rem;
  word-break: break-word;
}

.match-meta {
  font-size: .8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.match-meta a {
  color: var(--accent);
  text-decoration: none;
}

.match-meta a:hover { text-decoration: underline; }

.no-results {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.no-results svg {
  width: 64px;
  height: 64px;
  opacity: .4;
  margin-bottom: 1rem;
}

.no-results h3 {
  font-size: 1.1rem;
  margin-bottom: .5rem;
  color: var(--text);
}

.error-box {
  background: rgba(252, 129, 129, .1);
  border: 1px solid rgba(252, 129, 129, .3);
  border-radius: var(--radius-sm);
  padding: 1rem;
  color: var(--red);
  font-size: .9rem;
  text-align: center;
}

/* ── Settings ───────────────────────────────── */

#settings-view {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

#settings-view h2 {
  font-size: 1.1rem;
  margin-bottom: .25rem;
}

.settings-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Footer ─────────────────────────────────── */

footer {
  text-align: center;
  padding: .75rem 1rem;
  font-size: .75rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(255, 255, 255, .05);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

footer a:hover { text-decoration: underline; }

/* ── Hidden file input ──────────────────────── */

.hidden-input { display: none; }

/* ── Toast ──────────────────────────────────── */

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  color: var(--text);
  padding: .75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, .1);
  opacity: 0;
  transition: transform .35s cubic-bezier(.4, 0, .2, 1), opacity .35s;
  z-index: 100;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Auth ───────────────────────────────────── */

.login-error {
  color: #e94560;
  font-size: .85rem;
  min-height: 1.2em;
  margin-bottom: .5rem;
}

.user-label {
  font-size: .75rem;
  color: rgba(255, 255, 255, .5);
  margin-right: auto;
}

.logout-link {
  color: #e94560;
  text-decoration: none;
  font-size: .8rem;
  margin-left: .75rem;
}

/* ── Responsive ─────────────────────────────── */

@media (min-width: 600px) {
  main { padding: 2rem 1.5rem 6rem; }
  header { padding: 2rem 1.5rem 1.25rem; }
  header h1 { font-size: 1.6rem; }
}
