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

:root {
  --primary: #1a5276;
  --primary-light: #2980b9;
  --accent: #27ae60;
  --danger: #c0392b;
  --warning: #f39c12;
  --bg: #f5f6fa;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dcdde1;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --font: 'Inter', -apple-system, sans-serif;
  --mono: 'Courier Prime', monospace;
}

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: fixed;
  width: 100%;
}

body.glitching {
  animation: bgShift 0.3s ease;
}

@keyframes bgShift {
  0% { filter: none; }
  25% { filter: hue-rotate(30deg); }
  50% { filter: hue-rotate(-20deg) saturate(1.3); }
  75% { filter: hue-rotate(10deg); }
  100% { filter: none; }
}

body.inverted {
  filter: invert(1);
  transition: filter 0.5s;
}

/* === HEADER === */
#header {
  background: var(--primary);
  color: white;
  padding: 16px 20px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  transition: background 0.5s;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  opacity: 0.9;
}

.logo-title {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.02em;
}

.logo-subtitle {
  font-size: 11px;
  opacity: 0.7;
  font-weight: 300;
}

.header-meta {
  text-align: right;
  font-size: 11px;
  opacity: 0.7;
  font-family: var(--mono);
}

.header-meta span {
  display: block;
}

#progress-bar {
  height: 28px;
  background: rgba(0,0,0,0.2);
  border-radius: 4px 4px 0 0;
  overflow: hidden;
  position: relative;
  margin-top: 8px;
}

#progress-fill {
  height: 100%;
  background: var(--accent);
  width: 12.5%;
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  border-radius: 4px 0 0 0;
}

#progress-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 500;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* === APP CONTAINER === */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* === MAIN CONTENT === */
#main-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* === SECTIONS === */
.section {
  display: none;
  animation: fadeIn 0.5s ease;
}

.section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--primary);
}

.section-subtitle {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 24px;
  line-height: 1.5;
}

/* === CARDS === */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform 0.3s, box-shadow 0.3s;
}

.card.warning-card {
  border-left: 4px solid var(--warning);
  background: #fef9e7;
}

.card.error-card {
  border-left: 4px solid var(--danger);
  background: #fdedec;
}

.card.success-card {
  border-left: 4px solid var(--accent);
  background: #eafaf1;
}

/* === FORM ELEMENTS === */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-group .hint {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

input[type="text"],
input[type="email"],
input[type="date"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: var(--font);
  background: white;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(41, 128, 185, 0.15);
}

input.error, select.error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.1);
}

.error-msg {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

.btn-primary:active {
  background: var(--primary-light);
  transform: scale(0.97);
}

.btn-success {
  background: var(--accent);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

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

/* Evasive button */
.btn-evasive {
  position: relative;
  transition: transform 0.15s ease-out;
}

/* === CHECKBOX / RADIO === */
.check-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
  border: 1.5px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
}

.check-item.selected {
  border-color: var(--primary-light);
  background: #ebf5fb;
}

.check-item input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.check-item span {
  font-size: 14px;
}

/* === GRID ITEMS (for pattern recognition) === */
.image-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px auto;
  max-width: 320px;
}

.grid-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 3px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  cursor: pointer;
  transition: all 0.3s;
  background: white;
  user-select: none;
}

.grid-cell.selected {
  border-color: var(--primary-light);
  background: #ebf5fb;
  box-shadow: 0 0 0 3px rgba(41, 128, 185, 0.2);
}

.grid-cell.correct {
  border-color: var(--accent);
  background: #eafaf1;
}

.grid-cell.wrong {
  border-color: var(--danger);
  background: #fdedec;
  animation: shake 0.4s;
}

/* === COLOR BUTTONS (emotional baseline) === */
.color-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.color-btn {
  height: 80px;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: all 0.5s;
}

.color-btn.selected {
  border-color: white;
  box-shadow: 0 0 20px rgba(255,255,255,0.3);
  transform: scale(1.05);
}

/* === TRACE PATH === */
#trace-canvas {
  width: 100%;
  height: min(350px, 40vh);
  background: white;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  touch-action: none;
}

/* === CONSENT SCROLL === */
.consent-box {
  height: min(300px, 35vh);
  overflow-y: auto;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  font-size: 12px;
  line-height: 1.8;
  color: var(--text-light);
  font-family: var(--mono);
  scroll-behavior: smooth;
}

.consent-box .clause {
  margin-bottom: 12px;
}

.consent-box .clause-num {
  font-weight: 700;
  color: var(--text);
}

.consent-box .absurd {
  color: var(--text);
  font-weight: 500;
}

/* === RESULTS === */
.diagnosis-card {
  padding: 14px 18px;
  margin-bottom: 10px;
  border-radius: 8px;
  border-left: 4px solid;
  animation: slideIn 0.3s ease both;
  font-size: 14px;
}

.diagnosis-card .code {
  font-family: var(--mono);
  font-size: 12px;
  opacity: 0.7;
}

.diagnosis-card .name {
  font-weight: 600;
  margin: 4px 0;
}

.diagnosis-card .desc {
  font-size: 12px;
  color: var(--text-light);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

.severity-critical { border-color: #c0392b; background: #fdedec; }
.severity-high { border-color: #e67e22; background: #fef5e7; }
.severity-moderate { border-color: #f1c40f; background: #fef9e7; }
.severity-low { border-color: #3498db; background: #ebf5fb; }

.results-header {
  text-align: center;
  padding: 30px 0;
}

.results-header .score {
  font-size: 72px;
  font-weight: 700;
  color: var(--danger);
  line-height: 1;
}

.results-header .score-label {
  font-size: 14px;
  color: var(--text-light);
  margin-top: 8px;
}

.alert-banner {
  background: var(--danger);
  color: white;
  padding: 14px 18px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.alert-banner .alert-icon {
  font-size: 20px;
}

/* === NOTIFICATION POPUP === */
.notification {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: white;
  border-radius: 12px;
  padding: 14px 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  z-index: 200;
  max-width: 340px;
  width: 90%;
  transition: top 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid var(--border);
}

.notification.show {
  top: 20px;
}

.notification .notif-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.notification .notif-body {
  font-size: 12px;
  color: var(--text-light);
}

.notification.notif-warning {
  border-left: 4px solid var(--warning);
}

.notification.notif-error {
  border-left: 4px solid var(--danger);
}

.notification.notif-info {
  border-left: 4px solid var(--primary-light);
}

/* === DISTRACTION LAYER === */
#distraction-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

#distraction-layer .floater {
  position: absolute;
  pointer-events: auto;
  animation: float 8s ease-in-out infinite;
  cursor: pointer;
  font-size: 14px;
  background: white;
  padding: 10px 16px;
  border-radius: 20px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  border: 1px solid var(--border);
  white-space: nowrap;
  z-index: 51;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-20px) rotate(2deg); }
  50% { transform: translateY(10px) rotate(-1deg); }
  75% { transform: translateY(-15px) rotate(1deg); }
}

/* === OVERLAY & MODAL === */
#overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  backdrop-filter: blur(4px);
}

#modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 16px;
  padding: 30px;
  max-width: 400px;
  width: 90%;
  z-index: 301;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  text-align: center;
}

#modal h3 {
  font-size: 18px;
  margin-bottom: 12px;
}

#modal p {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 20px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* === SCREEN FLASH === */
#screen-flash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.1s;
}

#screen-flash.flash {
  opacity: 0.3;
  transition: opacity 0.05s;
}

/* === SHAKE === */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.shaking {
  animation: shake 0.4s ease;
}

/* === TIMER BAR === */
.timer-bar {
  height: 6px;
  background: #ecf0f1;
  border-radius: 3px;
  margin-bottom: 16px;
  overflow: hidden;
}

.timer-bar .timer-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.1s linear, background 0.3s;
}

.timer-bar .timer-fill.urgent {
  background: var(--danger);
}

/* === LOADING SPINNER === */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto;
}

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

/* === ATTENTION DOT === */
.attention-dot {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--danger);
  position: absolute;
  transition: all 0.2s ease-out;
  box-shadow: 0 4px 15px rgba(192, 57, 43, 0.3);
  cursor: pointer;
  z-index: 10;
}

.attention-dot.decoy {
  opacity: 1;
}

.attention-arena {
  position: relative;
  width: 100%;
  height: min(400px, 45vh);
  background: white;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  overflow: hidden;
  touch-action: none;
}

/* === READING TEST === */
.reading-passage {
  font-size: 16px;
  line-height: 1.8;
  padding: 20px;
  background: white;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  margin-bottom: 16px;
}

.reading-passage .word {
  display: inline;
  transition: all 0.5s;
}

.reading-passage .word.shifted {
  color: var(--danger);
  font-style: italic;
}

.reading-passage .word.invisible {
  opacity: 0;
}

.reading-passage .word.replaced {
  text-decoration: line-through;
  color: var(--text-light);
}

/* === MISC === */
.mono {
  font-family: var(--mono);
}

.text-center {
  text-align: center;
}

.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }

.fade-in {
  animation: fadeIn 0.5s ease both;
}

.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-success { color: var(--accent); }

/* Small screen adjustments */
@media (max-width: 480px) {
  .section-title { font-size: 19px; }
  .card { padding: 18px; }
  .image-grid { gap: 8px; }
  .grid-cell { font-size: 36px; }
}

/* Print style for results */
@media print {
  #header, #distraction-layer, #overlay, #modal { display: none; }
  .diagnosis-card { break-inside: avoid; }
}
