/* ============================================
   CSS Custom Properties & Reset
   ============================================ */
:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --success: #22c55e;
  --success-light: #bbf7d0;
  --danger: #ef4444;
  --danger-light: #fecaca;
  --warning: #f59e0b;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow: 0 4px 24px rgba(0, 0, 0, .08);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .12);
  --transition: .25s cubic-bezier(.4, 0, .2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overflow-y: auto;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: linear-gradient(135deg, #ede9fe 0%, #e0e7ff 50%, #dbeafe 100%);
  color: var(--gray-800);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  line-height: 1.5;
}

/* ============================================
   App Container
   ============================================ */
.app {
  width: 100%;
  max-width: 420px;
  position: relative;
}

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
}

/* ============================================
   Header & Branding
   ============================================ */
.header {
  text-align: center;
  margin-bottom: 28px;
}

.header__icon {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .3);
}

.header__icon svg {
  width: 28px;
  height: 28px;
  color: #fff;
}

.header__title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -.02em;
}

.header__subtitle {
  font-size: .875rem;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ============================================
   View Transitions
   ============================================ */
.view {
  display: none;
  animation: viewIn var(--transition) both;
}

.view.is-active {
  display: block;
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   Form Controls
   ============================================ */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font);
  color: var(--gray-800);
  background: var(--gray-50);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
  background: #fff;
}

.form-input::placeholder {
  color: var(--gray-400);
}

.form-input.is-error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .1);
}

.form-row {
  display: flex;
  gap: 10px;
}

.form-row .form-input {
  flex: 1;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .9375rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active {
  transform: scale(.97);
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  width: 100%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .35);
}

.btn--primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(99, 102, 241, .45);
  transform: translateY(-1px);
}

.btn--secondary {
  width: 100%;
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn--secondary:hover:not(:disabled) {
  background: var(--gray-200);
}

.btn--ghost {
  background: transparent;
  color: var(--gray-500);
  height: 36px;
  padding: 0 12px;
  font-size: .8125rem;
}

.btn--ghost:hover {
  color: var(--primary);
  background: rgba(99, 102, 241, .06);
}

.btn--danger-ghost {
  background: transparent;
  color: var(--danger);
  height: 36px;
  padding: 0 12px;
  font-size: .8125rem;
}

.btn--danger-ghost:hover {
  background: rgba(239, 68, 68, .06);
}

.btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   Verification Code Input (single hidden input)
   ============================================ */
.code-inputs {
  position: relative;
  margin: 24px 0;
  cursor: text;
}

.code-inputs__real {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: 16px;
  z-index: 2;
  -webkit-appearance: none;
  appearance: none;
}

.code-inputs__cells {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.code-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 56px;
  font-size: 1.375rem;
  font-weight: 700;
  font-family: var(--font);
  color: var(--gray-900);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--gray-50);
  transition: all var(--transition);
}

.code-cell.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
  background: #fff;
}

.code-cell.is-filled {
  border-color: var(--primary-light);
  background: #fff;
}

.code-inputs.is-loading .code-cell {
  opacity: .5;
}

.code-inputs.is-loading .code-inputs__real {
  pointer-events: none;
}

/* ============================================
   Code Status (auto-verify feedback)
   ============================================ */
.code-status {
  text-align: center;
  font-size: .8125rem;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--gray-500);
}

.code-status .spinner-sm {
  width: 14px;
  height: 14px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

/* ============================================
   Door — CSS Illustration
   ============================================ */
.door-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
}

.door-scene__text {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--gray-700);
}

.door-scene__hint {
  font-size: .8125rem;
  color: var(--gray-400);
  margin-top: 4px;
}

.door {
  width: 140px;
  margin: 0 auto 20px;
  perspective: 600px;
}

.door__frame {
  position: relative;
  width: 140px;
  height: 192px;
  background: var(--gray-200);
  border-radius: 6px 6px 0 0;
  padding: 6px;
  transform-style: preserve-3d;
}

.door__interior {
  position: absolute;
  inset: 6px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, #c7d2fe 0%, #a5b4fc 100%);
}

.door__panel {
  position: relative;
  width: 100%;
  height: 100%;
  background: linear-gradient(170deg, #f8fafc 0%, #e2e8f0 100%);
  border-radius: 3px 3px 0 0;
  transform-origin: left center;
  transition: transform .7s cubic-bezier(.4, 0, .2, 1);
  box-shadow: inset -2px 0 8px rgba(0,0,0,.06);
  z-index: 1;
}

.door__line {
  position: absolute;
  left: 16px;
  right: 16px;
  height: 0;
  border-top: 1.5px solid var(--gray-300);
}

.door__line--top { top: 28px; }
.door__line--bot { bottom: 28px; }

/* Handle assembly */
.door__handle-area {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
}

.door__handle-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a8a29e, #78716c);
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  z-index: 1;
}

.door__handle-bar {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 6px;
  background: linear-gradient(180deg, #a8a29e, #78716c);
  border-radius: 3px;
  transform-origin: left center;
  transform: translate(0, -50%);
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}

.door__keyhole {
  position: absolute;
  right: 23px;
  top: calc(50% + 20px);
  width: 6px;
  height: 10px;
  background: var(--gray-400);
  border-radius: 3px 3px 1px 1px;
}

.door__shadow {
  height: 8px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,.15) 0%, transparent 70%);
  margin-top: -1px;
}

/* ---------- State: Opening (handle turning) ---------- */
.door--opening .door__handle-bar {
  animation: handleTurn 1.2s ease-in-out infinite;
}

.door--opening .door__handle-knob {
  animation: knobGlow 1.2s ease-in-out infinite;
}

@keyframes handleTurn {
  0%, 100% { transform: translate(0, -50%) rotate(0deg); }
  40%      { transform: translate(0, -50%) rotate(-35deg); }
  60%      { transform: translate(0, -50%) rotate(-35deg); }
}

@keyframes knobGlow {
  0%, 100% { box-shadow: 0 1px 3px rgba(0,0,0,.25); }
  50%      { box-shadow: 0 0 8px 2px rgba(99, 102, 241, .5); }
}

/* ---------- State: Opened (door swings open) ---------- */
.door--open .door__panel {
  transform: rotateY(-70deg);
  box-shadow: 4px 0 16px rgba(0,0,0,.15);
}

.door--open .door__handle-bar {
  transform: translate(0, -50%) rotate(-30deg);
  animation: none;
}

.door--open .door__handle-knob {
  animation: none;
}

.door--open .door__shadow {
  transform: scaleX(.6) translateX(15%);
  transition: transform .7s cubic-bezier(.4, 0, .2, 1);
}

/* ---------- Size: Small (for result view) ---------- */
.door--sm {
  width: 90px;
  margin-bottom: 12px;
}

.door--sm .door__frame {
  width: 90px;
  height: 124px;
  padding: 4px;
}

.door--sm .door__interior { inset: 4px; }
.door--sm .door__line { left: 10px; right: 10px; }
.door--sm .door__line--top { top: 18px; }
.door--sm .door__line--bot { bottom: 18px; }
.door--sm .door__handle-area { right: 10px; width: 20px; height: 20px; }
.door--sm .door__handle-knob { width: 8px; height: 8px; }
.door--sm .door__handle-bar { width: 15px; height: 4px; }
.door--sm .door__keyhole { right: 15px; top: calc(50% + 14px); width: 4px; height: 7px; }

/* ============================================
   Door Results
   ============================================ */
.results {
  margin: 20px 0;
}

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  transition: background var(--transition);
}

.result-item--ok {
  background: var(--success-light);
}

.result-item--fail {
  background: var(--danger-light);
}

.result-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.result-item--ok .result-badge {
  background: var(--success);
  color: #fff;
}

.result-item--fail .result-badge {
  background: var(--danger);
  color: #fff;
}

.result-badge svg {
  width: 16px;
  height: 16px;
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-size: .875rem;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-detail {
  font-size: .75rem;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ============================================
   Status Icon (Success / Error big)
   ============================================ */
.status-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  animation: viewIn .4s both;
}

.status-icon--success {
  background: var(--success-light);
  color: var(--success);
}

.status-icon--error {
  background: var(--danger-light);
  color: var(--danger);
}

.status-icon svg {
  width: 36px;
  height: 36px;
}

/* ============================================
   Alert / Toast
   ============================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: .8125rem;
  font-weight: 500;
  margin-bottom: 16px;
  display: none;
  animation: viewIn var(--transition) both;
}

.alert.is-visible {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.alert--error {
  background: var(--danger-light);
  color: #b91c1c;
}

.alert--success {
  background: var(--success-light);
  color: #15803d;
}

.alert svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ============================================
   Countdown / Timer
   ============================================ */
.countdown {
  font-size: .8125rem;
  color: var(--gray-400);
  text-align: center;
  margin-top: 12px;
}

.countdown__num {
  color: var(--primary);
  font-weight: 600;
}

/* ============================================
   Settings Footer
   ============================================ */
.settings-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-100);
  gap: 8px;
}

.license-tag {
  font-size: .75rem;
  color: var(--gray-400);
  font-family: 'SF Mono', 'Cascadia Code', monospace;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   Divider
   ============================================ */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  font-size: .75rem;
  color: var(--gray-400);
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}

/* ============================================
   Summary Row
   ============================================ */
.summary {
  text-align: center;
  margin: 12px 0 20px;
}

.summary__big {
  font-size: 1.5rem;
  font-weight: 700;
}

.summary__big--success { color: var(--success); }
.summary__big--mixed   { color: var(--warning); }
.summary__big--fail    { color: var(--danger); }

.summary__label {
  font-size: .8125rem;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ============================================
   Responsive & Keyboard Adaptation
   ============================================ */
@media (max-width: 480px) {
  body {
    padding: 0;
    align-items: flex-start;
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }
  .app { max-width: 100%; }
  .card {
    border-radius: 0;
    padding: 28px 20px;
    padding-top: max(28px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    min-height: 100vh;
    min-height: 100dvh;
  }
}

body.keyboard-open .header {
  margin-bottom: 12px;
}

body.keyboard-open .header__icon {
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
}

body.keyboard-open .header__icon svg {
  width: 20px;
  height: 20px;
}
