:root {
    --bg: #1c1c1e;
    --card-bg: #ffffff;
    --text: #1a1a1a;
    --subtext: #666;
    --accent: #007aff;
    --danger: #ff3b30;
    --shadow: 0 8px 30px rgba(0,0,0,0.12);
    --radius: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
}

body {
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    min-height: -webkit-fill-available;
    display: flex;
    justify-content: center;
    align-items: center; /* Ensure vertical centering */
    overflow: hidden; /* Prevent scrolling */
    margin: 0;
    touch-action: none; /* Disable default touch actions like scroll/zoom */
}

#app {
    width: 100%;
    max-width: 640px;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
}

#card-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1000px;
    padding: 20px;
    overflow: hidden; /* Hide cards moving out */
}

/* Card Styles */
.card-scene {
    width: 100%;
    max-width: 340px;
    /* aspect-ratio: 9/16; Removed fixed aspect ratio to allow flexibility */
    height: 80vh; /* Use percentage of viewport height */
    height: 80dvh;
    max-height: 600px;
    position: absolute; /* Stack cards */
    /* Smooth easeOutQuint glide; z-index swaps mid-transition so the outgoing
       card stays above the incoming one for the first half of the slide. */
    transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1),
                z-index 0s linear 0.28s;
    /* Add perspective to the scene to create 3D depth */
    perspective: 1500px;
    will-change: transform, opacity;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    /* Use a spring-like bezier for more realism */
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
    cursor: pointer;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Add a slight lifting effect when flipping */
.card-scene.flipped .card-inner {
    transform: rotateY(180deg) scale(1.02);
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: var(--radius);
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    /* justify-content: space-between; Removed to allow scrolling flow */
    padding: 32px;
    overflow-y: auto; /* Allow scrolling if content overflows */
    /* Ensure faces are rendered nicely in 3D */
    transform-style: preserve-3d;
}

.card-face > :first-child {
    margin-top: auto;
}

.card-face > :last-child {
    margin-bottom: auto;
}

/* Front face needs z-index to stay on top initially */
.card-face:first-child {
    z-index: 2;
    transform: rotateY(0deg);
}

.card-back {
    transform: rotateY(180deg);
    background: #f8f9fa;
    z-index: 1;
}

/* QR and Info */
.qr-wrapper {
    margin-bottom: 32px;
    padding: 16px;
    background: white;
    border-radius: 20px;
}

.card-name {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.card-role {
    font-size: 1rem;
    font-weight: 500;
    color: var(--subtext);
    margin-bottom: 4px;
}

.card-detail {
    font-size: 0.95rem;
    color: var(--subtext);
    margin: 4px 0;
}

/* Action Buttons */
.action-btn {
    width: 100%;
    padding: 16px;
    margin: 8px 0;
    border: none;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s, color 0.2s;
}

.action-btn:active {
    transform: scale(0.98);
}

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

.edit-btn {
    background-color: #f0f0f0;
    color: var(--text);
}

.delete-btn {
    background-color: rgba(255, 59, 48, 0.1);
    color: var(--danger);
}

.flip-hint {
    margin-top: 16px;
    color: #999;
    font-size: 0.8rem;
    text-align: center;
}

/* Install CTA on the About card front */
.install-btn {
    display: inline-block;
    margin-top: 18px;
    padding: 11px 24px;
    border: none;
    border-radius: 980px;
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
}

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

.install-btn[hidden] {
    display: none;
}

/* iOS "Add to Home Screen" instruction sheet */
.install-help-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.5);
}

.install-help-sheet {
    width: 100%;
    max-width: 360px;
    padding: 28px 24px;
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--text);
    box-shadow: var(--shadow);
    text-align: left;
}

.install-help-sheet h3 {
    margin-bottom: 12px;
    font-size: 1.3rem;
}

.install-help-sheet p {
    margin-bottom: 12px;
    color: var(--subtext);
}

.install-help-sheet ol {
    margin: 0 0 20px 20px;
    line-height: 1.5;
}

.install-help-sheet li {
    margin-bottom: 8px;
}

/* Visible keyboard focus */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Add Card Placeholder */
.add-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.8);
    border-radius: var(--radius);
    border: 3px dashed #ddd;
    color: #999;
}

.add-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    color: #ccc;
}

/* Hide scrollbar for Chrome, Safari and Opera */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}

/* Hide scrollbar for IE, Edge and Firefox */
.no-scrollbar {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;  /* Firefox */
}

/* Edit Form in Card */
.edit-form {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    justify-content: center;
}

.edit-form input {
    width: 100%;
    padding: 14px 16px;
    border: 1.5px solid #e5e5e5;
    border-radius: 16px;
    font-size: 1rem;
    outline: none;
    background: #f9f9f9;
    transition: border-color 0.2s, background 0.2s;
}

.edit-form input:focus {
    border-color: var(--accent);
    background: #fff;
}

.form-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.form-actions button {
    flex: 1;
    padding: 16px;
    border: none;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

.form-actions button:active {
    transform: scale(0.98);
}

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

.btn-cancel {
    background: #f0f0f0;
    color: var(--text);
}
