* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-color: #2a2a2a;
  --card-color: #f4f3ee;
  --text-color: #1a1a1a;
  --toolbar-bg: rgba(40, 40, 40, 0.95);
  --toolbar-btn: #888;
  --toolbar-btn-hover: #fff;
  --viewport-height: 100vh;
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  height: var(--viewport-height);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--bg-color);
  font-family: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
  font-weight: normal;
}

/* Hidden keyboard input */
#keyboard-input {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px; /* Prevents iOS zoom */
}

/* Loading overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-color);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  padding: 24px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #ffd700;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

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

.loading-text {
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  margin-bottom: 16px;
}

.loading-progress {
  width: 200px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 auto;
}

.loading-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd700, #ff69b4, #9370db);
  transition: width 0.2s ease;
}

/* Toolbar */
.toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 100;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--toolbar-btn);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, filter 0.2s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

/* Individual gradient colors for each button */
#btn-new {
  color: #ffd700;
}

#btn-ribbon {
  color: #888;
}

#btn-export {
  color: #ff69b4;
}

#btn-share {
  color: #9370db;
}

#btn-library {
  color: #9370db;
}

.toolbar-btn:hover,
.toolbar-btn:active {
  filter: brightness(1.3);
  background: rgba(255, 255, 255, 0.1);
}

/* Ribbon color indicator */
.ribbon-indicator {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1a1a1a;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.ribbon-indicator.red {
  background: #c41e3a;
}

/* Card container */
.card-container {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  padding-top: 80px;
  padding-bottom: 20px;
  width: 100%;
  height: 100%;
  max-height: var(--viewport-height);
}

.card-container.keyboard-visible {
  align-items: flex-start;
  padding-top: 68px;
  padding-bottom: 12px;
  padding-left: 12px;
  padding-right: 12px;
}

/* Paper card */
.card {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 4 / 3;
  background-color: var(--card-color);
  border-radius: 3px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  position: relative;
  cursor: text;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* Paper background image */
.paper-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  z-index: 0;
}

/* Canvas for sprite rendering */
#typewriter-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* Cursor - upward-pointing triangle */
.cursor {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 12px solid #1a1a1a;
  transform: translateX(-50%);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.cursor[data-ribbon="red"] {
  border-bottom-color: #c41e3a;
}

.cursor.hidden {
  display: none;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Responsive adjustments */
@media (max-width: 540px) {
  .card-container {
    padding: 12px;
    padding-top: 70px;
  }
}

@media (max-height: 600px) {
  .card-container {
    padding-top: 70px;
  }

  .card {
    max-width: 400px;
  }
}

/* PWA standalone mode adjustments */
@media (display-mode: standalone) {
  .toolbar {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .card-container {
    padding-top: calc(68px + env(safe-area-inset-top));
  }
}

/* Focus styles */
.toolbar-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: all;
}

/* Modal card */
.modal {
  background: var(--card-color);
  border-radius: 8px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  transform: scale(0.9);
  transition: transform 0.2s ease;
}

.modal-overlay.show .modal {
  transform: scale(1);
}

/* Modal content */
.modal-title {
  margin: 0 0 12px 0;
  font-size: 20px;
  color: var(--text-color);
  font-family: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
  font-weight: normal;
}

.modal-message {
  margin: 0 0 24px 0;
  font-size: 16px;
  color: var(--text-color);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  line-height: 1.5;
}

/* Modal buttons */
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.modal-btn-secondary {
  background: #ddd;
  color: #333;
}

.modal-btn-secondary:hover {
  background: #ccc;
}

.modal-btn-primary {
  background: linear-gradient(135deg, #ffd700 0%, #ff69b4 50%, #9370db 100%);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.modal-btn-primary:hover {
  filter: brightness(1.1);
}

/* Gallery overlay */
.gallery-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-color);
  z-index: 500;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.gallery-overlay.show {
  transform: translateX(0);
  pointer-events: auto;
}

/* Gallery header */
.gallery-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--toolbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.gallery-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.gallery-back:hover {
  background: rgba(255, 255, 255, 0.1);
}

.gallery-title {
  font-family: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
  font-size: 20px;
  font-weight: normal;
  color: #fff;
  margin: 0;
}

/* Gallery content */
.gallery-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* Gallery grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

/* Gallery item */
.gallery-item {
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: var(--card-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

.gallery-item:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.gallery-item:active {
  transform: scale(0.98);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-item-date {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 12px;
  text-align: center;
}

/* Gallery empty state */
.gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #888;
  text-align: center;
  padding: 32px;
}

.gallery-empty svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.gallery-empty p {
  font-family: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
  font-weight: normal;
  font-size: 18px;
  margin: 0 0 8px 0;
  color: #aaa;
}

.gallery-empty span {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
}

/* Action overlay */
.action-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.action-overlay.show {
  opacity: 1;
  pointer-events: all;
}

/* Action sheet */
.action-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--toolbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px 16px 0 0;
  padding: 8px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 700;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  pointer-events: none;
}

.action-sheet.show {
  transform: translateY(0);
  pointer-events: auto;
}

.action-sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  margin: 8px auto 16px;
}

/* Action buttons */
.action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.action-btn:active {
  background: rgba(255, 255, 255, 0.15);
}

.action-btn svg {
  flex-shrink: 0;
}

.action-btn-danger {
  color: #ff6b6b;
}

.action-btn-cancel {
  justify-content: center;
  margin-top: 8px;
  color: #888;
  font-weight: 500;
}

/* Larger grid on wider screens */
@media (min-width: 540px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(4, 1fr);
    max-width: 800px;
    margin: 0 auto;
  }
}

/* Info button (lower right corner) */
.info-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: all 0.2s ease;
}

.info-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.05);
}

.info-btn:active {
  transform: scale(0.95);
}

/* About modal */
.about-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.about-overlay.show {
  display: flex;
}

.about-modal {
  background: var(--card-bg);
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  position: relative;
  animation: slideUp 0.3s ease;
}

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

.about-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.about-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.about-title {
  font-family: Seravek, 'Gill Sans Nova', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
  font-weight: normal;
  font-size: 28px;
  color: #ffd700;
  margin: 0 0 20px 0;
}

.about-content {
  color: #ddd;
  line-height: 1.6;
}

.about-content p {
  margin: 0 0 16px 0;
  font-size: 15px;
  color: #ddd;
}

.about-content strong {
  color: #fff;
  font-weight: 600;
}

.about-content ul {
  margin: 8px 0 16px 0;
  padding-left: 20px;
}

.about-content li {
  margin: 6px 0;
  font-size: 15px;
  color: #ddd;
}

.about-footer {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-style: italic;
  color: #aaa;
  font-size: 14px;
}
