/* ==========================================
   WRITERJOSHUA – MAIN STYLESHEET (with Cadence)
   ========================================== */

/* ===== CSS VARIABLES ===== */
:root {
  /* Colors – Light Mode */
  --primary: #0066cc;
  --primary-hover: #0052a3;
  --primary-light: #e6f2ff;
  
  --text: #333;
  --text-light: #666;
  --text-lighter: #999;
  
  --border: #ddd;
  --bg: #fff;
  --bg-light: #f9f9f9;
  --bg-code: #f4f4f4;
  
  --link-visited: #551a8b;
  
  /* Spacing */
  --sp-xs: 5px;
  --sp-sm: 10px;
  --sp-md: 15px;
  --sp-lg: 20px;
  --sp-xl: 40px;
  
  /* Typography */
  --ff-serif: Georgia, serif;
  --ff-mono: "Monaco", "Courier New", monospace;
  --lh: 1.6;
  
  /* Layout */
  --max-width: 800px;
  --radius: 4px;
  
  /* Transitions */
  --trans: 0.2s ease;
}

/* Dark mode color overrides */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #66b3ff;
    --primary-hover: #4d9eff;
    --primary-light: rgba(102, 179, 255, 0.15);
    
    --text: #e0e0e0;
    --text-light: #999;
    --text-lighter: #666;
    
    --border: #444;
    --bg: #1e1e1e;
    --bg-light: #2d2d2d;
    --bg-code: #2d2d2d;
    
    --link-visited: #b399d4;
  }
}

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

/* ===== BASE TYPOGRAPHY ===== */
body {
  font-family: var(--ff-serif);
  font-size: 16px;
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

h1 { font-size: 2em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }

p {
  margin-bottom: 1em;
}

/* ===== LINKS ===== */
a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--trans);
}

a:visited {
  color: var(--link-visited);
}

a:hover {
  text-decoration: underline;
}

a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius);
}

/* ===== CODE ===== */
code {
  font-family: var(--ff-mono);
  font-size: 0.9em;
  background: var(--bg-code);
  color: var(--text);
  padding: 2px 6px;
  border-radius: var(--radius);
}

pre {
  background: var(--bg-code);
  color: var(--text);
  padding: var(--sp-lg);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1em 0;
  line-height: 1.4;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.95em;
}

/* ===== LISTS ===== */
ul, ol {
  margin-left: 2em;
  margin-bottom: 1em;
}

li {
  margin-bottom: 0.5em;
}

/* ===== BLOCKQUOTES ===== */
blockquote {
  border-left: 4px solid var(--border);
  padding-left: 1em;
  margin: 1em 0;
  color: var(--text-light);
  font-style: italic;
}

/* ===== LAYOUT ===== */
html {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  flex-shrink: 0;
}

nav {
  flex-shrink: 0;
}

main {
  flex: 1;
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: var(--sp-lg);
}

footer {
  flex-shrink: 0;
  margin-top: auto;
}

/* ===== HEADER ===== */
header {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-lg);
  padding: var(--sp-md);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin-top: 0;
  margin-bottom: 0.2em;
  font-size: 1.8em;
}

header p {
  margin: 0;
  color: var(--text-light);
  font-size: 0.95em;
}

.profile-pic {
  width: 50px;
  height: 50px;
  border-radius: var(--radius);
  object-fit: cover;
  flex-shrink: 0;
}

.header-link {
  display: block;
  border-radius: var(--radius);
}

.header-link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ===== NAVIGATION ===== */
nav {
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
  padding: var(--sp-md) var(--sp-lg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-lg);
}

nav a {
  color: var(--primary);
  font-weight: 500;
  transition: all var(--trans);
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
}

nav a:hover,
nav a.active {
  border-bottom-color: var(--primary);
  text-decoration: none;
}

nav a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 4px;
}

/* ===== FOOTER ===== */
footer {
  margin-top: var(--sp-xl);
  padding-top: var(--sp-lg);
  border-top: 1px solid var(--border);
}

.footer-banner {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  display: block;
  margin-bottom: var(--sp-lg);
}

.footer-controls {
  text-align: center;
  margin: var(--sp-lg) 0;
}

.share-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: var(--sp-sm) var(--sp-lg);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1em;
  font-weight: 500;
  transition: background var(--trans), transform var(--trans);
}

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

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

.share-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.footer-copyright {
  text-align: center;
  font-size: 0.85em;
  font-style: italic;
  color: var(--text-lighter);
  margin: 0;
}

/* ===== JOTS ===== */
.jot {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-lg);
  margin-bottom: var(--sp-lg);
  background: var(--bg-light);
  transition: box-shadow var(--trans);
}

.jot:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.jot h2 {
  margin-top: 0;
  font-size: 1.3em;
}

.jot-meta {
  font-size: 0.85em;
  color: var(--text-lighter);
  margin: -0.5em 0 1em 0;
}

.jot-image {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin-top: var(--sp-md);
  display: block;
}

/* ===== ARCHIVE ===== */
.archive-image {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: var(--sp-lg) 0;
  display: block;
}

.post-excerpt {
  margin: var(--sp-xs) 0 0 0;
  font-size: 0.95em;
  color: var(--text-light);
}

/* ===== PROJECTS ===== */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--sp-lg);
  margin: var(--sp-xl) 0;
}

.project-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  transition: transform var(--trans), box-shadow var(--trans);
}

.project-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
}

.project-card a {
  display: block;
  color: inherit;
  text-decoration: none;
}

.project-card a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.project-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

.project-card h2 {
  margin: var(--sp-md) var(--sp-md) 0 var(--sp-md);
  font-size: 1.2em;
}

.project-excerpt {
  padding: 0 var(--sp-md) var(--sp-md) var(--sp-md);
  font-size: 0.95em;
  color: var(--text-light);
}

.projects-image {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: var(--sp-lg) 0;
  display: block;
}

/* ===== MARKDOWN IMAGES ===== */
#content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: var(--sp-lg) 0;
  display: block;
}

@media (max-width: 768px) {
  #content img {
    margin: var(--sp-md) 0;
  }
}

@media (max-width: 480px) {
  #content img {
    margin: var(--sp-sm) 0;
  }
}

/* ===== UTILITIES ===== */
.error {
  background: rgba(211, 47, 47, 0.1);
  border-left: 4px solid #d32f2f;
  color: #d32f2f;
  padding: var(--sp-lg);
  border-radius: var(--radius);
  margin: var(--sp-lg) 0;
}

/* ===== ACCESSIBILITY ===== */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== CONTENT IMAGES (Markdown) ===== */
#content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: var(--sp-lg) 0;
  display: block;
}

#content img:first-child {
  margin-top: 0;
}

/* ===== POST METADATA ===== */
.post-meta {
  color: var(--text-light);
  font-size: 0.95em;
  font-style: italic;
  margin: -0.5em 0 1em 0;
}

.post-image {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: var(--sp-lg) 0;
  display: block;
}

.post-excerpt {
  color: var(--text-light);
  font-size: 1em;
  margin: var(--sp-md) 0;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet (768px and below) */
@media (max-width: 768px) {
  body {
    font-size: 15px;
  }

  header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--sp-md);
  }

  header h1 {
    font-size: 1.5em;
  }

  nav {
    justify-content: center;
    gap: var(--sp-md);
    padding: var(--sp-md);
  }

  nav a {
    font-size: 0.9em;
  }

  h1 { font-size: 1.6em; }
  h2 { font-size: 1.25em; }

  #content, main {
    padding: var(--sp-md);
  }

  .jot {
    padding: var(--sp-md);
  }

  .projects-grid {
    grid-template-columns: 1fr;
    gap: var(--sp-md);
  }

  .project-card h2 {
    margin: var(--sp-sm) var(--sp-sm) 0 var(--sp-sm);
  }

  .project-excerpt {
    padding: 0 var(--sp-sm) var(--sp-sm) var(--sp-sm);
  }
}

/* Mobile (480px and below) */
@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  header {
    padding: var(--sp-sm);
  }

  header h1 {
    font-size: 1.3em;
  }

  header p {
    font-size: 0.9em;
  }

  .profile-pic {
    width: 40px;
    height: 40px;
  }

  nav {
    gap: var(--sp-sm);
    padding: var(--sp-sm);
  }

  nav a {
    font-size: 0.8em;
    padding-bottom: 1px;
  }

  h1 { font-size: 1.4em; }
  h2 { font-size: 1.1em; }

  #content, main {
    padding: var(--sp-sm);
  }

  code {
    font-size: 0.85em;
  }

  pre {
    padding: var(--sp-md);
    font-size: 0.85em;
  }

  .jot {
    padding: var(--sp-sm);
    margin-bottom: var(--sp-md);
  }

  .footer-banner {
    margin-bottom: var(--sp-md);
  }

  .share-btn {
    padding: var(--sp-sm) var(--sp-md);
    font-size: 0.9em;
  }
}

/* ===== THE CADENCE GAME STYLES ===== */
/* Added for /the-cadence/ integration */

#cadence-app {
  max-width: 100%;
}

.screen {
  animation: fadeIn 0.3s ease-in;
}

.hidden {
  display: none !important;
}

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

/* Landing Page */
#landing {
  padding: 0;
}

.landing-header {
  padding: 20px 0;
  text-align: center;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.landing-header h1 {
  font-size: 1.8em;
  margin: 0 0 5px 0;
  color: var(--primary);
}

.landing-header p {
  margin: 0;
  font-style: italic;
  color: var(--text-light);
  font-size: 0.95em;
}

.volume-controls {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 1000;
}

#mute-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
}

#volume-slider {
  width: 100px;
  height: 5px;
  cursor: pointer;
}

#cadence-main {
  flex: 1;
  padding: 0;
}

.volume-section {
  margin-bottom: 40px;
}

.volume-section h2 {
  color: var(--primary);
  margin-bottom: 10px;
  margin-top: 1.5em;
}

.volume-section .description {
  color: var(--text-light);
  margin-bottom: 20px;
}

.game-list {
  display: grid;
  gap: 10px;
}

.game-button {
  padding: 12px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.2s;
  text-align: left;
  font-family: var(--ff-serif);
}

.game-button:hover:not(:disabled) {
  background: var(--primary-hover);
  transform: translateX(5px);
}

.game-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

.archives-section {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.archives-section h3 {
  color: var(--primary);
  margin-bottom: 10px;
}

/* Game Screens */
.game-screen {
  padding: 0;
}

.game-header {
  background: var(--bg-light);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  border-bottom: 1px solid var(--border);
}

.back-btn {
  background: var(--primary);
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
  font-family: var(--ff-serif);
}

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

.game-header h2 {
  margin: 0;
  flex: 1;
}

.game-description {
  color: var(--text-light);
  margin-bottom: 20px;
  font-size: 14px;
  font-style: italic;
}

.game-content {
  padding: 20px;
}

.game-input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  margin-bottom: 15px;
  font-family: var(--ff-serif);
}

.game-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.feedback {
  padding: 12px;
  margin-bottom: 15px;
  border-radius: var(--radius);
  font-weight: 500;
  min-height: 20px;
}

.feedback.correct {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.feedback.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.attempts,
.progress {
  color: var(--text-light);
  font-size: 14px;
  margin-bottom: 15px;
}

/* Score Display */
.score-indicator {
  position: fixed;
  bottom: 20px;
  left: 20px;
  display: flex;
  gap: 20px;
  padding: 15px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 999;
}

#score-display {
  color: #2ecc71;
  font-weight: 600;
}

#error-display {
  color: #e74c3c;
  font-weight: 600;
}

/* Word Chain */
.chain-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.chain-word {
  background: var(--primary);
  color: #fff;
  padding: 10px 15px;
  border-radius: var(--radius);
  font-weight: 600;
}

#chain-display {
  background: #fff;
  border: 2px solid var(--primary);
  padding: 10px 15px;
  border-radius: var(--radius);
  font-weight: 600;
  min-width: 100px;
  text-align: center;
  font-size: 18px;
  letter-spacing: 2px;
}

.arrow {
  color: var(--primary);
  font-weight: bold;
}

.chain-display-horizontal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 20px;
  background: var(--bg-light);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.chain-item {
  padding: 10px 15px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 16px;
  min-width: 80px;
  text-align: center;
}

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

.chain-current {
  background: #f39c12;
  color: white;
  border: 2px solid var(--primary);
}

.chain-future {
  background: #ddd;
  color: var(--text-light);
}

/* Cryptogram */
#crypto-message {
  background: var(--bg-light);
  padding: 30px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  min-height: 140px;
}

.crypto-letter-box {
  width: 40px;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  font-family: var(--ff-mono);
  text-transform: uppercase;
  cursor: text;
  background: white;
}

.crypto-letter-box:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.1);
}

.crypto-letter-box:disabled {
  background: var(--bg-light);
  cursor: default;
  border-color: var(--text-light);
}

.crypto-letter-box.correct {
  background: #d4edda;
  border-color: #28a745;
}

.crypto-letter-box.error {
  background: #f8d7da;
  border-color: #dc3545;
  animation: shake 0.3s;
}

.crypto-solve-section {
  background: var(--bg-light);
  padding: 15px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.crypto-solve-section p {
  margin-bottom: 10px;
  color: var(--text-light);
  font-size: 14px;
}

#crypto-solve-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-family: var(--ff-serif);
  transition: all 0.2s;
  background: var(--primary);
  color: #fff;
}

#crypto-solve-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

/* Sudoku */
#sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0;
  background: var(--text);
  padding: 2px;
  margin-bottom: 20px;
  border: 3px solid var(--text);
  width: 100%;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.sudoku-cell {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #ccc;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  background: var(--bg);
  color: var(--primary);
  font-family: var(--ff-mono);
}

/* Hide number input spinner */
.sudoku-cell::-webkit-outer-spin-button,
.sudoku-cell::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.sudoku-cell[type=number] {
  -moz-appearance: textfield;
}

.sudoku-cell.puzzle-cell {
  background: var(--bg-light);
  color: var(--text);
  font-weight: 700;
}

.sudoku-cell:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.sudoku-cell.correct {
  background: #d4edda;
  color: #155724;
}

.sudoku-cell.error {
  background: #f8d7da;
  animation: shake 0.3s;
}

.sudoku-cell.border-right {
  border-right: 3px solid var(--text);
}

.sudoku-cell.border-bottom {
  border-bottom: 3px solid var(--text);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Final Screen */
#final-screen {
  padding: 0;
}

.final-stats {
  background: var(--bg-light);
  padding: 20px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.final-stats h2 {
  color: var(--primary);
  margin-bottom: 15px;
}

.final-stats p {
  margin: 10px 0;
}

.final-stats hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 15px 0;
}

.password-section {
  padding: 20px;
}

.password-section h3 {
  color: var(--primary);
  margin-bottom: 10px;
  margin-top: 1.5em;
}

.password-section p {
  color: var(--text-light);
  margin-bottom: 15px;
  font-size: 14px;
}

#leaderboard-section {
  padding: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
}

#leaderboard-section h3 {
  color: var(--primary);
  margin-top: 1.5em;
}

#leaderboard-submit {
  background: #2ecc71;
  color: #fff;
}

#leaderboard-submit:hover:not(:disabled) {
  background: #27ae60;
}

/* Responsive */
@media (max-width: 768px) {
  .volume-controls {
    top: 10px;
    right: 10px;
    font-size: 14px;
  }

  #volume-slider {
    width: 70px;
  }

  .game-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .chain-display {
    gap: 8px;
  }

  .crypto-buttons {
    grid-template-columns: 1fr;
  }

  .crypto-block {
    width: 28px;
    height: 36px;
    line-height: 36px;
    font-size: 20px;
    margin: 0 3px;
  }

  #crypto-message {
    font-size: 20px;
    letter-spacing: 4px;
    padding: 20px 10px;
  }

  #sudoku-grid {
    max-width: 100%;
  }

  .score-indicator {
    bottom: 10px;
    left: 10px;
    flex-direction: column;
    gap: 10px;
  }
}