/*! HTML5 Boilerplate v9.0.1 | MIT License | https://html5boilerplate.com/ */

/* main.css 3.0.0 | MIT License | https://github.com/h5bp/main.css#readme */
/*
 * What follows is the result of much research on cross-browser styling.
 * Credit left inline and big thanks to Nicolas Gallagher, Jonathan Neal,
 * Kroc Camen, and the H5BP dev community and team.
 */

/* ==========================================================================
   Base styles: opinionated defaults
   ========================================================================== */

html {
  color: #222;
  font-size: 1em;
  line-height: 1.4;
}

/*
 * Remove text-shadow in selection highlight:
 * https://twitter.com/miketaylr/status/12228805301
 *
 * Customize the background color to match your design.
 */

::-moz-selection {
  background: #b3d4fc;
  text-shadow: none;
}

::selection {
  background: #b3d4fc;
  text-shadow: none;
}

/*
 * A better looking default horizontal rule
 */

hr {
  display: block;
  height: 1px;
  border: 0;
  border-top: 1px solid #ccc;
  margin: 1em 0;
  padding: 0;
}

/*
 * Remove the gap between audio, canvas, iframes,
 * images, videos and the bottom of their containers:
 * https://github.com/h5bp/html5-boilerplate/issues/440
 */

audio,
canvas,
iframe,
img,
svg,
video {
  vertical-align: middle;
}

/*
 * Remove default fieldset styles.
 */

fieldset {
  border: 0;
  margin: 0;
  padding: 0;
}

/*
 * Allow only vertical resizing of textareas.
 */

textarea {
  resize: vertical;
}

/* ==========================================================================
   Author's custom styles
   ========================================================================== */

/* CSS Variables - Light Mode */
:root {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --danger-color: #ef4444;
  --danger-hover: #dc2626;
  --bg-color: #f9fafb;
  --card-bg: #ffffff;
  --text-color: #111827;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --radius: 8px;
  --spacing: 1rem;
}

/* CSS Variables - Dark Mode */
body.dark {
  --primary-color: #60a5fa;
  --primary-hover: #3b82f6;
  --danger-color: #f87171;
  --danger-hover: #ef4444;
  --bg-color: #111827;
  --card-bg: #1f2937;
  --text-color: #f9fafb;
  --text-secondary: #9ca3af;
  --border-color: #374151;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7);
}

/* Reset and Base */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

/* Auth Modal */
.auth-modal {
  border: none;
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  background: var(--card-bg);
}

.auth-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.auth-content h2 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  text-align: center;
}

.auth-content > p {
  margin: 0 0 1.5rem;
  color: var(--text-secondary);
  text-align: center;
}

#authForm {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#authForm input {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 1rem;
}

#authForm button {
  padding: 0.75rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  font-weight: 600;
}

#authForm button:hover {
  background: var(--primary-hover);
}

.error-message {
  color: var(--danger-color);
  margin: 0;
  font-size: 0.875rem;
  min-height: 1.25rem;
}

/* App Container */
.app-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 0;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border-color);
}

.app-header h1 {
  margin: 0;
  font-size: 2rem;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
}

/* Buttons */
.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px; /* iPad touch target */
}

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

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

.btn-secondary {
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-color);
}

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

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

/* Dark Mode Toggle */
.theme-toggle {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--bg-color);
  transform: rotate(20deg);
}

/* Main Content */
.main-content {
  min-height: 60vh;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state p {
  margin: 0.5rem 0;
  font-size: 1.125rem;
}

.empty-state-hint {
  font-size: 0.875rem;
}

/* Notes Grid */
.notes-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 768px) {
  .notes-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .notes-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Note Card */
.note-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.note-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--primary-color);
}

.note-card-delete {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 32px;
  height: 32px;
  min-height: auto;
  border-radius: 50%;
  border: none;
  background: var(--danger-color);
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
  padding: 0;
}

.note-card:hover .note-card-delete {
  opacity: 1;
}

.note-card-delete:hover {
  background: var(--danger-hover);
  transform: scale(1.1);
}

.note-card-delete:active {
  transform: scale(0.95);
}

.note-card-title {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card-preview {
  margin: 0 0 0.75rem;
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card-date {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* Editor Section */
.editor-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

/* Editor Tabs */
.editor-tabs {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.editor-tab {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s;
  margin-bottom: -2px;
}

.editor-tab:hover {
  color: var(--text-color);
}

.editor-tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.markdown-hint {
  margin-left: auto;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.note-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group input,
.form-group textarea {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
}

.form-group input {
  font-size: 1.5rem;
  font-weight: 600;
}

.form-group textarea {
  resize: vertical;
  min-height: 300px;
  line-height: 1.6;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.form-actions .btn-danger {
  margin-left: auto;
}

/* Markdown Preview */
.markdown-preview {
  min-height: 300px;
  max-height: 500px;
  overflow-y: auto;
}

.preview-content {
  padding: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-color);
  min-height: 300px;
}

/* Markdown Styling */
.preview-content h1,
.note-card-preview h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 1rem 0 0.5rem;
  color: var(--text-color);
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.25rem;
}

.preview-content h2,
.note-card-preview h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 1rem 0 0.5rem;
  color: var(--text-color);
}

.preview-content h3,
.note-card-preview h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0.75rem 0 0.5rem;
  color: var(--text-color);
}

.preview-content h1:first-child,
.preview-content h2:first-child,
.preview-content h3:first-child {
  margin-top: 0;
}

.preview-content p,
.note-card-preview p {
  margin: 0.5rem 0;
  line-height: 1.6;
}

.preview-content ul,
.preview-content ol,
.note-card-preview ul,
.note-card-preview ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.preview-content li,
.note-card-preview li {
  margin: 0.25rem 0;
}

.preview-content code,
.note-card-preview code {
  background: var(--border-color);
  padding: 0.125rem 0.375rem;
  border-radius: 3px;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 0.875em;
}

.preview-content pre,
.note-card-preview pre {
  background: var(--border-color);
  padding: 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 0.5rem 0;
}

.preview-content pre code,
.note-card-preview pre code {
  background: none;
  padding: 0;
}

.preview-content blockquote,
.note-card-preview blockquote {
  border-left: 4px solid var(--primary-color);
  padding-left: 1rem;
  margin: 0.5rem 0;
  color: var(--text-secondary);
  font-style: italic;
}

.preview-content a,
.note-card-preview a {
  color: var(--primary-color);
  text-decoration: none;
}

.preview-content a:hover,
.note-card-preview a:hover {
  text-decoration: underline;
}

.preview-content strong,
.note-card-preview strong {
  font-weight: 600;
}

.preview-content em,
.note-card-preview em {
  font-style: italic;
}

.preview-content hr,
.note-card-preview hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 1rem 0;
}

.preview-content table,
.note-card-preview table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.5rem 0;
}

.preview-content th,
.preview-content td,
.note-card-preview th,
.note-card-preview td {
  border: 1px solid var(--border-color);
  padding: 0.5rem;
  text-align: left;
}

.preview-content th,
.note-card-preview th {
  background: var(--border-color);
  font-weight: 600;
}

/* Responsive */
@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .header-actions {
    flex-direction: column;
  }

  .app-container {
    padding: 0.5rem;
  }

  .editor-section {
    padding: 1rem;
  }
}

/* iPad Optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
  .app-header h1 {
    font-size: 2.5rem;
  }

  .btn {
    font-size: 1.125rem;
    padding: 0.75rem 1.5rem;
  }

  .note-card {
    padding: 2rem;
  }

  .note-card-title {
    font-size: 1.5rem;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 48px;
    min-width: 48px;
  }

  .note-card {
    padding: 1.5rem;
  }

  /* Show delete button on touch devices */
  .note-card-delete {
    opacity: 0.7;
  }

  .note-card-delete:active {
    opacity: 1;
  }
}

/* ==========================================================================
   Helper classes
   ========================================================================== */

/*
 * Hide visually and from screen readers
 */

.hidden,
[hidden] {
  display: none !important;
}

/*
 * Hide only visually, but have it available for screen readers:
 * https://snook.ca/archives/html_and_css/hiding-content-for-accessibility
 *
 * 1. For long content, line feeds are not interpreted as spaces and small width
 *    causes content to wrap 1 word per line:
 *    https://medium.com/@jessebeach/beware-smushed-off-screen-accessible-text-5952a4c2cbfe
 */

.visually-hidden {
  border: 0;
  clip: rect(0, 0, 0, 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  white-space: nowrap;
  width: 1px;
  /* 1 */
}

/*
 * Extends the .visually-hidden class to allow the element
 * to be focusable when navigated to via the keyboard:
 * https://www.drupal.org/node/897638
 */

.visually-hidden.focusable:active,
.visually-hidden.focusable:focus {
  clip: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  position: static;
  white-space: inherit;
  width: auto;
}

/*
 * Hide visually and from screen readers, but maintain layout
 */

.invisible {
  visibility: hidden;
}

/*
 * Clearfix: contain floats
 *
 * The use of `table` rather than `block` is only necessary if using
 * `::before` to contain the top-margins of child elements.
 */

.clearfix::before,
.clearfix::after {
  content: "";
  display: table;
}

.clearfix::after {
  clear: both;
}

/* ==========================================================================
   EXAMPLE Media Queries for Responsive Design.
   These examples override the primary ('mobile first') styles.
   Modify as content requires.
   ========================================================================== */

@media only screen and (min-width: 35em) {
  /* Style adjustments for viewports that meet the condition */
}

@media print,
  (-webkit-min-device-pixel-ratio: 1.25),
  (min-resolution: 1.25dppx),
  (min-resolution: 120dpi) {
  /* Style adjustments for high resolution devices */
}

/* ==========================================================================
   Print styles.
   Inlined to avoid the additional HTTP request:
   https://www.phpied.com/delay-loading-your-print-css/
   ========================================================================== */

@media print {
  *,
  *::before,
  *::after {
    background: #fff !important;
    color: #000 !important;
    /* Black prints faster */
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  abbr[title]::after {
    content: " (" attr(title) ")";
  }

  /*
   * Don't show links that are fragment identifiers,
   * or use the `javascript:` pseudo protocol
   */
  a[href^="#"]::after,
  a[href^="javascript:"]::after {
    content: "";
  }

  pre {
    white-space: pre-wrap !important;
  }

  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  tr,
  img {
    page-break-inside: avoid;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}

