/*
 * YARNIA HUB - Unified Pixel Stylesheet
 *
 * Everything renders at 640x480 native resolution, scaled up to fill viewport.
 * Single pixel font throughout for consistent "resolution" appearance.
 * All measurements in multiples of 8px (the pixel grid).
 *
 * Color palette inspired by illuminated manuscripts.
 * Font: Alkhemikal - medieval blackletter pixel font (CC BY 4.0)
 */

/* Celtic pixel fonts - self-hosted */
@font-face {
  font-family: 'Celtic Bit';
  src: url("/fonts/celtic-bit.ttf") format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Celtic Bit Thin';
  src: url("/fonts/celtic-bit-thin.ttf") format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Celtic Bitty';
  src: url("/fonts/celtic-bitty.ttf") format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* Backup medieval font */
@font-face {
  font-family: 'Alkhemikal';
  src: url("/fonts/Alkhemikal.ttf") format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* Fallback pixel font from Google */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* ==========================================================================
   COLOR PALETTE - Illuminated Manuscript
   ========================================================================== */

:root {
  /* Backgrounds - vellum parchment */
  --bg-dark: #350849;      /* Darkest - viewport (royal purple) */
  --bg-main: #ECDCB1;      /* Main content background (parchment) */
  --bg-card: #F5EBD5;      /* Cards and panels (lighter parchment) */
  --bg-hover: #E3D1A3;     /* Hover states (darker parchment) */

  /* UI Chrome - royal purple */
  --chrome: #350849;       /* Menu/status bar */
  --chrome-light: #4A1B5E; /* Lighter chrome */
  --chrome-border: #250636;/* Dark border */

  /* Text - purple ink on parchment */
  --text-bright: #FFCE34;  /* Brightest text - gilt gold */
  --text-normal: #350849;  /* Normal text - royal purple */
  --text-dim: #7A5C8A;     /* Dimmed text - muted purple */

  /* Accent - Gilt gold (primary) */
  --teal: #FFCE34;
  --teal-bright: #FFD85C;
  --teal-dim: #D4A820;

  /* Accent - Royal purple */
  --gold: #350849;
  --gold-bright: #4A1B5E;
  --gold-dim: #250636;

  /* Accent - Vermillion (manuscript red) */
  --coral: #8B2500;
  --coral-bright: #A83000;
  --coral-dim: #5C1900;

  /* Accent - Bronze embellishments */
  --green: #CBAC6B;
  --green-bright: #DCC07A;
  --green-dim: #A68B4B;

  /* Accent - Deep purple */
  --purple: #5E2D7A;
  --purple-bright: #7A3D9E;
  --purple-dim: #3D1D50;
}

/* ==========================================================================
   BASE RESET
   ========================================================================== */

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

/* ==========================================================================
   PIXEL VIEWPORT - Full screen container
   ========================================================================== */

#pixel-viewport {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-dark);
  position: fixed;
  top: 0;
  left: 0;
}

/* ==========================================================================
   PIXEL CANVAS - The 640x480 fixed resolution container
   ========================================================================== */

#pixel-canvas {
  /* Fixed VGA resolution */
  width: 640px;
  height: 480px;

  /* Scaling origin */
  transform-origin: center center;

  /* Crisp pixel scaling - this is the key */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;

  /* Disable font anti-aliasing */
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
  text-rendering: optimizeSpeed;

  /* Layout */
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;

  /* Base colors */
  background: var(--bg-main);
  color: var(--text-normal);

  /* THE font - medieval pixel throughout */
  font-family: 'Celtic Bit', 'Alkhemikal', 'Press Start 2P', monospace;
  font-size: 10px;
  line-height: 1.4;
}

/* Disable text selection for game-like feel */
#pixel-canvas {
  -webkit-user-select: none;
  user-select: none;
}

/* Allow selection in form inputs */
#pixel-canvas input,
#pixel-canvas textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Force pixel rendering on all children */
#pixel-canvas * {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  -webkit-font-smoothing: none;
  font-smooth: never;
}

/* No transitions - instant state changes like old games */
#pixel-canvas,
#pixel-canvas * {
  transition: none !important;
}

/* ==========================================================================
   TYPOGRAPHY - Single font, limited sizes
   ========================================================================== */

/* Everything uses the same font at 10px by default */
h1, h2, h3, p, a, span, div, label, button, input, textarea {
  font-family: 'Celtic Bit', 'Alkhemikal', 'Press Start 2P', monospace;
  font-size: 10px;
  line-height: 1.4;
}

a {
  color: var(--purple);
  text-decoration: none;
}

a:hover {
  color: var(--chrome);
}

/* ==========================================================================
   LAYOUT STRUCTURE
   ========================================================================== */

/* Menu bar - 16px tall (2 lines of 8px text) */
.menubar {
  height: 16px;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  flex-shrink: 0;
}

.menubar-item {
  color: var(--text-bright);
  padding: 0 8px;
  height: 16px;
  display: flex;
  align-items: center;
}

.menubar-item:hover {
  background: var(--chrome-light);
  color: var(--teal);
}

/* Button styled as menubar item (for sign out) */
.menubar-button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
}

/* Main content - fills remaining space */
.main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* Scrollable content area */
.scroll {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
}

/* Styled scrollbar */
.scroll::-webkit-scrollbar {
  width: 8px;
  background: var(--bg-card);
}

.scroll::-webkit-scrollbar-thumb {
  background: var(--chrome-light);
}

.scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Status bar - 16px tall */
.statusbar {
  height: 16px;
  background: var(--chrome);
  border-top: 1px solid var(--chrome-border);
  display: flex;
  align-items: center;
  padding: 0 8px;
  flex-shrink: 0;
}

.statusbar-section {
  color: var(--green);
  padding: 0 8px;
  border-right: 1px solid var(--chrome-border);
}

.statusbar-fill {
  flex: 1;
  border-right: none;
}

/* ==========================================================================
   CONTENT CONTAINERS
   ========================================================================== */

.container {
  max-width: 624px; /* 640 - 16px padding */
  margin: 0 auto;
}

/* ==========================================================================
   PAGE HEADER
   ========================================================================== */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--chrome-border);
}

.page-title {
  color: var(--chrome);
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */

.btn {
  display: inline-block;
  padding: 8px 16px;
  background: var(--chrome);
  color: var(--text-bright);
  border: none;
  cursor: pointer;
}

.btn:hover {
  background: var(--chrome-light);
  color: var(--teal);
}

.btn-primary {
  background: var(--teal-dim);
  color: var(--chrome);
}

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

/* ==========================================================================
   CARDS / PANELS
   ========================================================================== */

.card {
  background: var(--bg-card);
  border: 1px solid var(--chrome-border);
  padding: 8px;
  margin-bottom: 8px;
}

.card-title {
  color: var(--chrome);
  margin-bottom: 8px;
}

.card-title:hover {
  color: var(--purple);
}

.card-body {
  color: var(--text-dim);
  margin-bottom: 8px;
}

.card-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--chrome-border);
}

/* ==========================================================================
   GRID LAYOUTS
   ========================================================================== */

.grid {
  display: grid;
  gap: 8px;
}

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

/* ==========================================================================
   BADGES / TAGS
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 2px 4px;
  background: var(--green);
  color: var(--chrome);
  margin-right: 4px;
}

.badge-green {
  background: var(--green);
  color: var(--chrome);
}

.badge-amber {
  background: var(--teal);
  color: var(--chrome);
}

.badge-pink {
  background: var(--coral);
  color: var(--bg-card);
}

/* ==========================================================================
   ALERTS
   ========================================================================== */

.alert {
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid;
}

.alert-success {
  background: var(--green-dim);
  border-color: var(--green);
  color: var(--green-bright);
}

.alert-error {
  background: var(--coral-dim);
  border-color: var(--coral);
  color: var(--coral-bright);
}

.alert-warning {
  background: var(--gold-dim);
  border-color: var(--gold);
  color: var(--gold-bright);
}

/* ==========================================================================
   FORMS
   ========================================================================== */

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  color: var(--chrome);
  margin-bottom: 8px;
}

.form-input,
.form-textarea {
  width: 100%;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--green);
  color: var(--text-normal);
  font-family: 'Celtic Bit', 'Alkhemikal', 'Press Start 2P', monospace;
  font-size: 10px;
}

.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--chrome);
  box-shadow: 0 0 0 1px var(--teal);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
}

/* ==========================================================================
   PROGRESS BAR
   ========================================================================== */

.progress {
  height: 8px;
  background: var(--bg-dark);
  border: 1px solid var(--chrome-border);
}

.progress-bar {
  height: 100%;
  background: var(--teal);
  box-shadow: 0 0 4px var(--teal);
}

/* ==========================================================================
   LOADING STATE
   ========================================================================== */

.loading {
  text-align: center;
  padding: 32px;
  color: var(--chrome);
}

/* Simple blinking animation for loading text */
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.loading-text {
  animation: blink 1s step-end infinite;
}

/* ==========================================================================
   EMPTY STATE
   ========================================================================== */

.empty {
  text-align: center;
  padding: 32px;
  border: 1px dashed var(--chrome-light);
}

.empty-title {
  color: var(--text-normal);
  margin-bottom: 8px;
}

.empty-text {
  color: var(--text-dim);
  margin-bottom: 16px;
}

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

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

.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }

.flex { display: flex; }
.flex-between { justify-content: space-between; }
.flex-center { align-items: center; }
.flex-end { justify-content: flex-end; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.hidden { display: none !important; }

/* ==========================================================================
   MOBILE PORTRAIT MODE (320x480)
   ========================================================================== */

#pixel-canvas.pixel-portrait {
  width: 320px;
  height: 480px;
}

.pixel-portrait .grid-2 {
  grid-template-columns: 1fr;
}

/* ==========================================================================
   GAME PLAYER - Fullscreen game view
   ========================================================================== */

.player-body {
  margin: 0;
  padding: 0;
  background: #000;
  font-family: 'Celtic Bit', 'Alkhemikal', 'Press Start 2P', monospace;
  font-size: 10px;
  overflow: hidden;
}

#player-viewport {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: fixed;
  top: 0;
  left: 0;
}

#player-container {
  /* Native game size: 768x478 (landscape) + 16px controls */
  width: 768px;
  height: 494px;
  transform-origin: center center;
  display: flex;
  flex-direction: column;

  /* Crisp pixel scaling */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

#game-canvas {
  width: 768px;
  height: 478px;
  display: block;
  background: var(--bg-dark);

  /* Crisp pixel scaling */
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

.player-controls {
  height: 16px;
  background: var(--chrome);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  color: var(--green);
  font-family: 'Celtic Bit', 'Alkhemikal', 'Press Start 2P', monospace;
  font-size: 10px;

  /* Disable font anti-aliasing */
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
}

.player-controls .key {
  background: var(--chrome-light);
  color: var(--teal);
  padding: 0 4px;
  text-decoration: none;
}

.player-controls a.key:hover {
  background: var(--teal);
  color: var(--chrome);
}

/* Error overlay */
#game-error {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
}

#game-error .alert {
  font-family: 'Celtic Bit', 'Alkhemikal', 'Press Start 2P', monospace;
  font-size: 10px;
}
