@import url('variables.css');

/* ======== Reset ======== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.skip-link {
  position: absolute; top: -40px; left: 0;
  background: var(--color-primary); color: white;
  padding: var(--space-2) var(--space-4); z-index: 1000;
  transition: top 0.3s; text-decoration: none;
}
.skip-link:focus { top: 0; }

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

/* ======== Base ======== */
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-family);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { line-height: var(--leading-tight); font-weight: 600; }
h1 { font-size: var(--text-3xl); letter-spacing: var(--tracking-tight); font-weight: 700; }
h2 { font-size: var(--text-2xl); letter-spacing: var(--tracking-snug); }
h3 { font-size: var(--text-xl); letter-spacing: var(--tracking-snug); }
h4 { font-size: var(--text-lg); letter-spacing: var(--tracking-normal); }

p { max-width: var(--prose-max); }

.text-secondary { color: var(--color-text-secondary); }
.text-tertiary  { color: var(--color-text-tertiary); }
.text-center    { text-align: center; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  width: 100%; max-width: var(--container-max);
  margin: 0 auto; padding: 0 var(--container-padding);
}
main { flex: 1; padding: var(--space-6) 0; }

header {
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border-light);
  padding: var(--space-4) 0;
}
header .container {
  display: flex; justify-content: space-between;
  align-items: center; flex-wrap: wrap;
}
header h1 { font-size: var(--text-xl); letter-spacing: var(--tracking-snug); }
header nav a {
  padding: var(--space-2) var(--space-3);
  min-height: var(--touch-target-min);
  display: inline-flex; align-items: center;
}

/* ======== Forms ======== */
.form-group { margin-bottom: var(--space-4); }
label { display: block; margin-bottom: var(--space-2); font-weight: 500; font-size: var(--text-sm); color: var(--color-text-secondary); }
.form-hint { display: block; margin-top: var(--space-1); font-size: var(--text-xs); color: var(--color-text-tertiary); }

input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
  width: 100%; padding: var(--space-3) var(--space-4);
  font-size: var(--text-base); font-family: inherit;
  border: 1px solid var(--color-border); border-radius: 8px;
  min-height: var(--touch-target-min); background: var(--color-bg); color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
input::placeholder, textarea::placeholder { color: var(--color-text-tertiary); }

/* ======== Buttons ======== */
.btn,
button[type="submit"] {
  display: inline-flex; align-items: center; justify-content: center;
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base); font-weight: 500;
  min-height: var(--touch-target-min);
  border: none; border-radius: 8px; cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out); text-decoration: none;
}
.btn-primary,
button[type="submit"] {
  background-color: var(--color-primary); color: white; box-shadow: var(--shadow-sm);
}
.btn-primary:hover, button[type="submit"]:hover {
  background-color: var(--color-primary-dark); box-shadow: var(--shadow-md); transform: translateY(-1px); color: white; text-decoration: none;
}
.btn-secondary {
  background-color: var(--color-bg-secondary); color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background-color: var(--color-bg-tertiary); }
.btn-ghost {
  background: transparent; color: var(--color-primary); padding: var(--space-2) var(--space-3);
}
.btn-ghost:hover { background: var(--color-primary-light); }
.btn-block { display: block; width: 100%; }
.btn-large { font-size: var(--text-lg); padding: var(--space-4) var(--space-10); }

button:disabled, .btn:disabled {
  opacity: 0.5; cursor: not-allowed;
}
button[type="submit"]:disabled { background-color: var(--color-border); box-shadow: none; transform: none; }

/* ======== Messages ======== */
.error-message {
  background-color: #fef2f2; border: 1px solid #fecaca;
  color: var(--color-error); padding: var(--space-3) var(--space-4);
  border-radius: 4px; margin-bottom: var(--space-4);
}
.success-message {
  background-color: #f0fdf4; border: 1px solid #bbf7d0;
  color: var(--color-success); padding: var(--space-3) var(--space-4);
  border-radius: 4px; margin-bottom: var(--space-4);
}
.form-error { background: #fee2e2; color: #dc2626; padding: var(--space-3); border-radius: 4px; margin-bottom: var(--space-4); font-size: var(--text-sm); }

/* ======== Login page ======== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100dvh; background: var(--color-bg-secondary); }
.login-container {
  background: var(--color-bg); padding: var(--space-8); border-radius: 16px;
  box-shadow: var(--shadow-lg); width: 100%; max-width: 400px; margin: var(--space-4);
}
.login-container h1 { text-align: center; margin-bottom: var(--space-2); }
.login-container h2 { text-align: center; font-size: var(--text-lg); color: var(--color-text-secondary); font-weight: 400; margin-bottom: var(--space-6); }

/* ======== Cards ======== */
.card {
  background: var(--color-bg); border: 1px solid var(--color-border-light);
  border-radius: 12px; padding: var(--space-6); margin-bottom: var(--space-4);
  box-shadow: var(--shadow-sm);
}

/* ======== Utilities ======== */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
img, video, iframe { max-width: 100%; height: auto; }
button, a, [role="button"] { cursor: pointer; }
hr { border: none; border-top: 1px solid var(--color-border); margin: var(--space-6) 0; }

@media (min-width: 640px) {
  :root { --container-padding: var(--space-6); }
}

/* ======== Waiting page ======== */
.waiting-page { display: flex; justify-content: center; align-items: center; min-height: 60vh; }
.waiting-card { text-align: center; padding: var(--space-8); }
.waiting-icon { margin-bottom: var(--space-6); color: var(--color-primary); }
.waiting-title { font-size: var(--text-2xl); margin-bottom: var(--space-3); }
.waiting-message { color: var(--color-text-secondary); margin-bottom: var(--space-4); max-width: 300px; margin-left: auto; margin-right: auto; }
.waiting-status { margin-top: var(--space-4); }

.spinner { animation: spin 1.5s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ======== Image browser ======== */
.image-browser { padding: var(--space-4); max-width: 600px; margin: 0 auto; }
.image-browser-sticky {
  position: sticky; top: 0; z-index: 50;
  background: var(--color-bg); border-bottom: 1px solid var(--color-border-light);
  padding: var(--space-3) var(--space-4); margin: 0 calc(-1 * var(--space-4));
}
.browser-instruction p {
  font-size: var(--text-base); font-weight: 500; color: var(--color-text);
  line-height: var(--leading-snug); max-width: none;
}

.image-grid-container { margin-top: var(--space-4); }
.image-page { display: none; }
.image-page.active {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}
@supports not (gap: 0.75rem) {
  .image-page.active { display: flex; flex-wrap: wrap; margin: -0.375rem; }
  .image-page.active > .image-card { flex: 1 1 150px; margin: 0.375rem; }
}
@media (min-width: 640px) { .image-page.active { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 768px) { .image-page.active { grid-template-columns: repeat(4, 1fr); } }

.image-page-loading { display: flex; justify-content: center; padding: var(--space-8); }
.image-page-loading .spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
}

.image-card {
  position: relative; cursor: pointer;
  border: 2px solid transparent; border-radius: 8px; overflow: hidden;
  transition: border-color 0.2s var(--ease-out), transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
  background: var(--color-bg-secondary);
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) { .image-card:hover { border-color: var(--color-border); transform: scale(1.01); } }
.image-card:active { transform: scale(0.98); transition-duration: 0.05s; }
.image-card:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.image-card.selected {
  border-color: var(--color-primary); transform: scale(1.03);
  box-shadow: 0 4px 12px rgba(0,102,204,0.25);
}
@media (hover: hover) { .image-card.selected:hover { transform: scale(1.03); } }
.image-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }

/* ======== Bullet inputs ======== */
.bullet-section {
  margin-top: var(--space-6); padding: var(--space-4);
  background: var(--color-bg-secondary); border-radius: 8px;
}
.selected-image-preview { margin-bottom: var(--space-4); text-align: center; }
.selected-image-preview img { max-width: 280px; max-height: 280px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.bullet-section h3 { font-size: var(--text-base); font-weight: 600; margin-bottom: var(--space-2); }
.bullet-section p { font-size: var(--text-sm); color: var(--color-text-secondary); margin-bottom: var(--space-4); }

.bullet-inputs { display: flex; flex-direction: column; gap: var(--space-3); }
.bullet-input {
  width: 100%; font-size: 16px; min-height: var(--touch-target-min);
  padding: var(--space-3); border: 1px solid var(--color-border); border-radius: 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.bullet-input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.bullet-input::placeholder { color: var(--color-text-tertiary); }
.bullet-input-hidden { display: none; }
.bullet-input-reveal { animation: bullet-reveal 0.25s var(--ease-out) forwards; }
@keyframes bullet-reveal {
  from { opacity: 0; transform: translateY(-8px); max-height: 0; }
  to   { opacity: 1; transform: translateY(0); max-height: 60px; }
}
.bullet-input.input-error { border-color: var(--color-error); background-color: rgba(220,38,38,0.05); }
.bullet-input.input-error:focus { border-color: var(--color-error); box-shadow: 0 0 0 3px rgba(220,38,38,0.1); }
.input-error-message { color: var(--color-error); font-size: var(--text-sm); margin-top: calc(-1 * var(--space-2)); margin-bottom: var(--space-2); display: none; }
.input-error-message.visible { display: block; }

.submit-section {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 600px;
  padding: var(--space-4); text-align: center;
  background: var(--color-bg); border-top: 1px solid var(--color-border-light); z-index: 100;
}
.image-browser form { padding-bottom: 80px; }
.btn-submit {
  width: 100%; padding: var(--space-4); font-size: var(--text-base); font-weight: 600;
  background: var(--color-primary); color: white; border: none; border-radius: 8px;
  cursor: pointer; min-height: var(--touch-target-min);
  transition: background-color 0.15s, opacity 0.15s;
}
.btn-submit:hover:not(:disabled) { background: var(--color-primary-dark); }
.btn-submit:disabled { background: var(--color-border); cursor: not-allowed; }
.btn-submit.loading { opacity: 0.7; cursor: wait; }
.selection-hint { margin-top: var(--space-2); font-size: var(--text-sm); color: var(--color-text-tertiary); }

/* ======== Gap badges / synthesis ======== */
.gap-badge {
  display: inline-block; padding: 0.25em 0.75em; border-radius: 4px;
  font-weight: 600; font-size: var(--text-sm);
}
.gap-badge.gap-direction   { background: #DBEAFE; color: #1D4ED8; }
.gap-badge.gap-alignment   { background: #D1FAE5; color: #047857; }
.gap-badge.gap-commitment  { background: #FEF3C7; color: #B45309; }
.gap-badge.gap-tension     { background: #FEF3C7; color: #B45309; }
.gap-badge.gap-fragmentation { background: #DBEAFE; color: #1D4ED8; }
.gap-badge.gap-single      { background: var(--color-bg-secondary); color: var(--color-text-secondary); }

/* ======== Mobile ======== */
@media (max-width: 640px) {
  .image-browser { padding: var(--space-3); }
  .bullet-section { padding: var(--space-3); }
}
