/**
 * Layout Styles - Hanasemasuka
 * Page structure and responsive layout
 */

/* ============================================
   BASE LAYOUT - CRT/Retro screen effect
   ============================================ */

html,
body {
  height: 100%;
  background: var(--bg-darkest);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: var(--font-size-md);
  line-height: 1.6;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #000008;
  position: relative;
}

/* CRT Scanline overlay */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.15) 0px,
    rgba(0, 0, 0, 0.15) 1px,
    transparent 1px,
    transparent 2px
  );
  pointer-events: none;
  z-index: 9999;
}

/* CRT screen curvature/vignette */
body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 0%,
    transparent 60%,
    rgba(0, 0, 0, 0.4) 100%
  );
  pointer-events: none;
  z-index: 9998;
}

/* Main app container */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================
   HEADER / NAVIGATION - Solid retro bar
   ============================================ */

.main-header {
  background: var(--panel-bg);
  border-bottom: 4px solid var(--window-frame);
  box-shadow: 0 4px 0 #000000;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xl);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.logo-text {
  font-family: var(--font-pixel);
  font-size: var(--font-size-lg);
  color: var(--text-highlight);
  text-shadow: 2px 2px 0 #000000;
  letter-spacing: 2px;
}

.logo-japanese {
  font-family: var(--font-japanese);
  font-size: var(--font-size-jp-sm);
  color: var(--accent-info);
  text-shadow: 2px 2px 0 #000000;
}

/* Navigation - Classic menu style with cursor */
.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 8px 16px;
  font-family: var(--font-pixel);
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  position: relative;
}

/* JRPG cursor pointer */
.nav-link::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--text-highlight);
  opacity: 0;
}

.nav-link:hover {
  color: var(--text-highlight);
}

.nav-link:hover::before {
  opacity: 1;
  animation: cursor-blink 0.5s steps(1) infinite;
}

@keyframes cursor-blink {
  0%, 70% { opacity: 1; }
  71%, 100% { opacity: 0; }
}

.nav-link.active {
  color: var(--text-highlight);
  background: var(--bg-medium);
  border: 2px solid var(--window-frame);
}

.nav-link.active::before {
  opacity: 1;
}

/* User section in header */
.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.header-stats {
  display: flex;
  gap: var(--space-md);
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-xl);
}

/* Page sections - Classic RPG section header */
.page-header {
  margin-bottom: var(--space-xl);
}

.page-title {
  font-family: var(--font-pixel);
  font-size: var(--font-size-2xl);
  color: var(--text-highlight);
  text-shadow: 4px 4px 0 #000000;
  margin-bottom: var(--space-sm);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.page-subtitle {
  font-size: var(--font-size-lg);
  color: var(--text-secondary);
  text-shadow: 2px 2px 0 #000000;
}

/* Content grid */
.content-grid {
  display: grid;
  gap: var(--space-xl);
}

.content-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.content-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.content-grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* ============================================
   DASHBOARD LAYOUT
   ============================================ */

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-xl);
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

.dashboard-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* Quick action cards - Classic JRPG menu items */
.action-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-lg);
}

/* When no review pending, study card takes full width */
.action-cards.no-review {
  grid-template-columns: 1fr;
}

.action-card {
  padding: var(--space-lg);
  background: var(--panel-bg);
  cursor: pointer;
  position: relative;
  
  /* Classic window border */
  border: 4px solid var(--window-frame);
  outline: 4px solid #000000;
  outline-offset: -4px;
  box-shadow:
    inset 4px 4px 0 var(--window-highlight),
    inset -4px -4px 0 var(--window-shadow),
    8px 8px 0 #000000;
}

/* Selection cursor */
.action-card::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 12px solid var(--text-highlight);
  opacity: 0;
}

.action-card:hover::before,
.action-card:focus::before {
  opacity: 1;
  animation: cursor-blink 0.5s steps(1) infinite;
}

.action-card:hover {
  background: var(--bg-medium);
}

.action-card:active {
  box-shadow:
    inset 4px 4px 0 var(--window-shadow),
    inset -4px -4px 0 var(--window-highlight),
    4px 4px 0 #000000;
}

.action-card-icon {
  font-size: var(--font-size-3xl);
  margin-bottom: var(--space-md);
  margin-left: 20px;
}

.action-card-title {
  font-family: var(--font-pixel);
  font-size: var(--font-size-md);
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  margin-left: 20px;
  text-shadow: 2px 2px 0 #000000;
}

.action-card:hover .action-card-title {
  color: var(--text-highlight);
}

.action-card-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-left: 20px;
}

/* Large study card when full width */
.action-cards.no-review .action-card-study {
  padding: var(--space-2xl);
  text-align: center;
}

.action-cards.no-review .action-card-study .action-card-icon {
  font-size: 4rem;
  margin-bottom: var(--space-lg);
}

.action-cards.no-review .action-card-study .action-card-title {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-sm);
}

.action-cards.no-review .action-card-study .action-card-subtitle {
  font-size: var(--font-size-md);
}

/* ============================================
   STUDY MODE LAYOUT
   ============================================ */

.study-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: var(--space-xl);
}

.study-progress {
  width: 100%;
  max-width: 600px;
}

.study-card-area {
  position: relative;
}

.study-controls {
  display: flex;
  gap: var(--space-md);
}

/* Quiz options - Classic RPG battle menu style */
.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  width: 100%;
  max-width: 600px;
}

/* Quiz options - JRPG menu item */
.quiz-option {
  padding: var(--space-md) var(--space-lg);
  padding-left: 32px;
  background: var(--panel-bg);
  font-family: var(--font-japanese);
  font-size: var(--font-size-jp-sm);
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  position: relative;
  
  /* Window border */
  border: 4px solid var(--window-frame);
  outline: 4px solid #000000;
  outline-offset: -4px;
  box-shadow:
    inset 4px 4px 0 var(--window-highlight),
    inset -4px -4px 0 var(--window-shadow),
    4px 4px 0 #000000;
}

/* Selection cursor */
.quiz-option::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 8px solid var(--text-highlight);
  opacity: 0;
}

.quiz-option:hover:not(:disabled)::before,
.quiz-option:focus:not(:disabled)::before {
  opacity: 1;
  animation: cursor-blink 0.5s steps(1) infinite;
}

.quiz-option:hover:not(:disabled) {
  background: var(--bg-medium);
  color: var(--text-highlight);
}

.quiz-option:active:not(:disabled) {
  box-shadow:
    inset 4px 4px 0 var(--window-shadow),
    inset -4px -4px 0 var(--window-highlight),
    2px 2px 0 #000000;
}

.quiz-option.correct {
  background: var(--accent-success-dark);
  border-color: var(--accent-success);
  color: #ffffff;
  animation: flash-correct 0.3s steps(2) 2;
}

.quiz-option.correct::before {
  opacity: 1;
  border-left-color: #ffffff;
}

@keyframes flash-correct {
  0%, 100% { background: var(--accent-success-dark); }
  50% { background: var(--accent-success); }
}

.quiz-option.incorrect {
  background: var(--accent-error);
  border-color: var(--accent-primary-dark);
  color: #ffffff;
  animation: shake 0.4s steps(8);
}

.quiz-option.incorrect::before {
  content: "X";
  border: none;
  font-family: var(--font-pixel);
  font-size: 12px;
  color: #ffffff;
  opacity: 1;
}

/* Typing input */
.typing-input-container {
  width: 100%;
}

/* ============================================
   PROFILE LAYOUT - Classic RPG status screen
   ============================================ */

.profile-header {
  display: flex;
  align-items: center;
  gap: var(--space-xl);
  padding: var(--space-xl);
  background: var(--panel-bg);
  margin-bottom: var(--space-xl);
  position: relative;
  
  /* Classic JRPG window */
  border: 4px solid var(--window-frame);
  outline: 4px solid #000000;
  outline-offset: -4px;
  box-shadow:
    inset 4px 4px 0 var(--window-highlight),
    inset -4px -4px 0 var(--window-shadow),
    8px 8px 0 #000000;
}

/* No gradient decorations - keep it retro */

.profile-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.profile-info {
  flex: 1;
}

.profile-name {
  font-family: var(--font-pixel);
  font-size: var(--font-size-xl);
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
  text-shadow: 2px 2px 0 #000000;
}

.profile-title {
  font-size: var(--font-size-sm);
  color: var(--accent-info);
  margin-bottom: var(--space-md);
  text-shadow: 2px 2px 0 #000000;
  letter-spacing: 1px;
}

.profile-stats {
  display: flex;
  gap: var(--space-xl);
}

.profile-stat {
  text-align: center;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-darkest);
  border: 2px solid var(--bg-dark);
  border-top-color: var(--bg-darkest);
  border-left-color: var(--bg-darkest);
}

.profile-stat:hover {
  background: var(--bg-dark);
}

.profile-stat-value {
  font-family: var(--font-pixel);
  font-size: var(--font-size-xl);
  color: var(--text-highlight);
  text-shadow: 2px 2px 0 #000000;
}

.profile-stat-label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: var(--space-xs);
  text-shadow: 1px 1px 0 #000000;
}

/* ============================================
   SHOP LAYOUT
   ============================================ */

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-lg);
}

.shop-item {
  padding: var(--space-md);
  background: var(--panel-bg);
  border: var(--border-width) solid var(--panel-border-inner);
  text-align: center;
  transition: all var(--transition-fast);
}

.shop-item:hover {
  border-color: var(--accent-info);
}

.shop-item.owned {
  opacity: 0.7;
  border-color: var(--accent-success);
}

.shop-item-preview {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-md);
}

.shop-item-name {
  font-family: var(--font-pixel);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-sm);
}

.shop-item-cost {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  color: var(--coin-color);
}

/* ============================================
   MODAL - Classic JRPG dialog box
   ============================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  /* Dithered dark overlay - retro transparency */
  background: 
    url("data:image/svg+xml,%3Csvg width='4' height='4' viewBox='0 0 4 4' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='0' y='0' width='2' height='2' fill='%23000'/%3E%3Crect x='2' y='2' width='2' height='2' fill='%23000'/%3E%3C/svg%3E");
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel-bg);
  
  /* Classic JRPG window */
  border: 4px solid var(--window-frame);
  outline: 4px solid #000000;
  outline-offset: -4px;
  box-shadow:
    inset 4px 4px 0 var(--window-highlight),
    inset -4px -4px 0 var(--window-shadow),
    8px 8px 0 #000000;
}

.modal-backdrop.active .modal {
  animation: modal-open 0.2s steps(4);
}

@keyframes modal-open {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-medium);
  border-bottom: 4px solid var(--window-frame);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-family: var(--font-pixel);
  font-size: var(--font-size-md);
  color: var(--text-highlight);
  text-shadow: 2px 2px 0 #000000;
  letter-spacing: 2px;
}

.modal-body {
  padding: var(--space-lg);
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 4px solid var(--window-shadow);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-md);
  background: var(--bg-dark);
}

/* ============================================
   FOOTER - Simple retro bar
   ============================================ */

.main-footer {
  background: var(--bg-darkest);
  border-top: 4px solid var(--window-frame);
  padding: var(--space-md) var(--space-xl);
  text-align: center;
}

.footer-text {
  font-family: var(--font-pixel);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  letter-spacing: 1px;
  text-shadow: 1px 1px 0 #000000;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}

.mt-sm {
  margin-top: var(--space-sm);
}
.mt-md {
  margin-top: var(--space-md);
}
.mt-lg {
  margin-top: var(--space-lg);
}
.mt-xl {
  margin-top: var(--space-xl);
}

.mb-sm {
  margin-bottom: var(--space-sm);
}
.mb-md {
  margin-bottom: var(--space-md);
}
.mb-lg {
  margin-bottom: var(--space-lg);
}
.mb-xl {
  margin-bottom: var(--space-xl);
}

.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.justify-center {
  justify-content: center;
}
.justify-between {
  justify-content: space-between;
}
.gap-sm {
  gap: var(--space-sm);
}
.gap-md {
  gap: var(--space-md);
}
.gap-lg {
  gap: var(--space-lg);
}

.hidden {
  display: none !important;
}

/* Japanese text styling */
.japanese {
  font-family: var(--font-japanese);
}

.jp-large {
  font-size: var(--font-size-jp-lg);
}

.jp-xlarge {
  font-size: var(--font-size-jp-xl);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .dashboard-sidebar > * {
    flex: 1;
    min-width: 250px;
  }
}

@media (max-width: 900px) {
  .content-grid-3,
  .content-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .action-cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .header-content {
    flex-wrap: wrap;
    padding: var(--space-md);
  }

  .header-stats {
    display: none;
  }

  /* Hide user section in header on mobile */
  .header-user {
    display: none;
  }

  /* Mobile bottom navigation */
  .main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--panel-bg);
    border-top: var(--border-width) solid var(--panel-border-inner);
    display: flex;
    justify-content: space-around;
    padding: var(--space-sm) 0;
    z-index: var(--z-sticky);
    box-shadow: 0 -4px 0 var(--border-dark);
  }

  .nav-link {
    flex-direction: column;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-xs);
    text-align: center;
  }

  .main-content {
    padding: var(--space-md);
    padding-bottom: calc(var(--space-xl) + 60px);
  }

  .content-grid-2,
  .content-grid-3,
  .content-grid-4 {
    grid-template-columns: 1fr;
  }

  .profile-header {
    flex-direction: column;
    text-align: center;
  }

  .profile-stats {
    justify-content: center;
  }

  .quiz-options {
    grid-template-columns: 1fr;
  }

  /* Responsive card sizing */
  .pixel-card {
    width: min(var(--card-width), calc(100vw - var(--space-xl) * 2));
  }

  .pixel-card-japanese {
    font-size: var(--font-size-jp-lg);
  }

  /* ============================================
     MOBILE: Reduced border widths for space
     ============================================ */
  
  .pixel-panel {
    border-width: 2px;
    outline-width: 2px;
    box-shadow:
      inset 2px 2px 0 var(--window-highlight),
      inset -2px -2px 0 var(--window-shadow),
      4px 4px 0 #000000;
  }

  .pixel-panel::before,
  .pixel-panel::after {
    width: 4px;
    height: 4px;
  }

  .pixel-panel::before {
    top: 2px;
    left: 2px;
  }

  .pixel-panel::after {
    bottom: 2px;
    right: 2px;
  }

  .action-card {
    border-width: 2px;
    outline-width: 2px;
    box-shadow:
      inset 2px 2px 0 var(--window-highlight),
      inset -2px -2px 0 var(--window-shadow),
      4px 4px 0 #000000;
  }

  .action-card::before {
    left: 8px;
    border-left-width: 8px;
    border-top-width: 5px;
    border-bottom-width: 5px;
  }

  .quiz-option {
    border-width: 2px;
    outline-width: 2px;
    padding-left: 24px;
    box-shadow:
      inset 2px 2px 0 var(--window-highlight),
      inset -2px -2px 0 var(--window-shadow),
      2px 2px 0 #000000;
  }

  .quiz-option::before {
    left: 6px;
    border-left-width: 6px;
    border-top-width: 4px;
    border-bottom-width: 4px;
  }

  .modal {
    border-width: 2px;
    outline-width: 2px;
    box-shadow:
      inset 2px 2px 0 var(--window-highlight),
      inset -2px -2px 0 var(--window-shadow),
      4px 4px 0 #000000;
  }

  .modal-header {
    border-bottom-width: 2px;
  }

  .modal-footer {
    border-top-width: 2px;
  }

  .pixel-card-front,
  .pixel-card-back {
    border-width: 2px;
    outline-width: 2px;
    box-shadow:
      inset 2px 2px 0 var(--window-highlight),
      inset -2px -2px 0 var(--window-shadow),
      4px 4px 0 #000000;
  }
}

/* ============================================
   MAX-WIDTH UTILITIES
   ============================================ */

.max-w-sm {
  max-width: 400px;
}
.max-w-md {
  max-width: 500px;
}
.max-w-lg {
  max-width: 600px;
}
.max-w-xl {
  max-width: 800px;
}

/* Highlight variants for action cards */
.action-card-urgent {
  border-color: var(--accent-primary) !important;
  animation: pulse-border 2s ease-in-out infinite;
}

.action-card-urgent::before {
  content: "";
  position: absolute;
  inset: -4px;
  background: var(--accent-primary);
  opacity: 0.1;
  z-index: -1;
}

@keyframes pulse-border {
  0%,
  100% {
    border-color: var(--accent-primary);
  }
  50% {
    border-color: var(--accent-secondary);
  }
}
