/* === 0xd.ir — Index Layout & Table ===
 * Mandatory structural styles. Retro flavor lives in retro.css.
 * Depends on: base.css
 */

/* ==========================================================================
   Card
   ========================================================================== */

main {
  position: relative;
  overflow: hidden;
  margin: 0 auto;
  padding: var(--space-7);
  max-width: var(--content-width);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-elevated) 100%);
  box-shadow:
    inset 0 0 60px rgba(102,179,255,0.02),
    0 4px 24px rgba(0,0,0,0.4),
    0 0 60px rgba(102,179,255,0.03);
}

/* ==========================================================================
   CRT Scanlines (subtle, always on; amber override in retro.css)
   ========================================================================== */

main::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.06) 2px,
    rgba(0, 0, 0, 0.06) 4px
  );
  animation: crt-scan 8s steps(1) infinite;
}

@keyframes crt-scan {
  0%, 91%   { opacity: 0.92; }
  92%       { opacity: 0.52; }
  93%       { opacity: 0.88; }
  94%       { opacity: 0.35; }
  95%       { opacity: 0.95; }
  96%       { opacity: 0.48; }
  97%       { opacity: 0.90; }
  98%       { opacity: 0.40; }
  99%       { opacity: 0.85; }
  100%      { opacity: 0.92; }
}

/* ==========================================================================
   Power Indicator
   ========================================================================== */

.power-indicator {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--terminal-success);
  box-shadow: 0 0 8px var(--terminal-success);
  opacity: 0.8;
  cursor: pointer;
  border: none;
  padding: 0;
  z-index: 10;
  transition: all var(--transition-fast);
  animation: power-pulse 3s ease-in-out infinite;
}
.power-indicator:hover {
  opacity: 1;
  transform: scale(1.3);
  box-shadow: 0 0 16px var(--terminal-success), 0 0 32px rgba(81,207,102,0.3);
}
.power-indicator:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
}
.power-indicator.frozen {
  background: #ff4444;
  box-shadow: 0 0 8px #ff4444;
  animation: power-pulse-frozen 2s ease-in-out infinite;
}

@keyframes power-pulse {
  0%, 100% { opacity: 0.4; box-shadow: 0 0 4px var(--terminal-success); }
  50%       { opacity: 1;   box-shadow: 0 0 14px var(--terminal-success), 0 0 28px rgba(81,207,102,0.3); }
}
@keyframes power-pulse-frozen {
  0%, 100% { opacity: 0.6; box-shadow: 0 0 6px #ff4444; }
  50%       { opacity: 1;   box-shadow: 0 0 16px #ff4444, 0 0 32px rgba(255,68,68,0.4); }
}

/* ==========================================================================
   Glow Token
   ========================================================================== */

:root {
  --glow-color: rgba(102, 179, 255, 0.55);
}

/* ==========================================================================
   Terminal Prompt
   ========================================================================== */

pre.prompt {
  margin: 0;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: all;
  cursor: text;
}

.prompt-r     { color: var(--terminal-prompt); font-weight: 600; }
.prompt-check { color: var(--terminal-success); }
.prompt-dollar { color: var(--text-muted); }
.git-arrow    { color: var(--link); }

/* ==========================================================================
   Glitch Keyframe (shared by pre and td img)
   ========================================================================== */

@keyframes glitch {
  0%, 93%, 100% { transform: translate(0); }
  94%            { transform: translate(-1px,  1px); }
  95%            { transform: translate( 1px, -1px); }
  96%            { transform: translate(0); }
}

td img {
  animation: glitch 4s infinite;
  animation-delay: 1s;
}

pre.prompt { animation: glitch 4s infinite; }

/* ==========================================================================
   Burnout (power-loss opacity dip)
   ========================================================================== */

.prompt-r, .prompt-dollar, .git-arrow, .prompt-check {
  animation: burnout 16s step-end infinite;
}

.prompt-r       { animation-delay: 4s; }
.prompt-dollar  { animation-delay: 0s; }
.git-arrow      { animation-delay: 4s; }
.prompt-check   { animation-delay: 0s; }

@keyframes burnout {
  0%        { opacity: 1; }
  70%       { opacity: 0; }
  71%       { opacity: 0.9; }
  85%       { opacity: 0.3; }
  100%      { opacity: 1; }
}

/* ==========================================================================
   Table
   ========================================================================== */

table {
  clear: both;
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 0.95rem;
}

thead { font-size: 1.05em; }

th {
  text-align: start;
  white-space: nowrap;
  padding: var(--space-2) 0 var(--space-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
  letter-spacing: 0.02em;
}
th:hover { color: var(--link-hover); }
th:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

td {
  white-space: nowrap;
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(46,46,46,0.5);
}
td:not(:first-child) { width: 0; }

td a {
  color: var(--link);
  text-decoration: none;
  text-shadow:
    0 0 4px var(--glow-color);
  transition: color var(--transition-fast), text-shadow var(--transition-fast);
}
td a:hover,
td a:focus-visible {
  color: var(--link-hover);
  text-shadow:
    0 0 4px var(--glow-color),
    0 0 6px var(--glow-color),
    0 0 12px var(--glow-color);
  outline: none;
}
td a:visited { color: var(--link-visited); }

/* ==========================================================================
   :active Tap Feedback (all devices)
   ========================================================================== */

td a:active {
  text-shadow:
    0 0 14px var(--glow-color),
    0 0 30px var(--glow-color),
    0 0 55px var(--glow-color);
  transition: text-shadow 0.05s ease;
}

/* ==========================================================================
   Column alignment
   ========================================================================== */

th:not(:first-child), 
td:not(:first-child) { text-align: start; padding-inline-start: 1em; }
th:nth-child(2), td:nth-child(2) { text-align: end; padding-inline-end: 1em; }
/* Hack to Force non-file columns to fit content; file column takes the rest */
th:first-child, td:first-child { width: 100%; max-width: 0; }
th:not(:first-child), td:not(:first-child) { width: 1px; white-space: nowrap; }

/* ==========================================================================
   Sort Indicators
   ========================================================================== */

table[order] > thead > tr > th::after { display: none; width: 0.8em; margin-inline-end: -0.8em; text-align: end; color: var(--text-muted); }
table[order="asc"]  > thead > tr > th::after { content: "\2193"; }
table[order="desc"] > thead > tr > th::after { content: "\2191"; }

table[order][order-by="0"] > thead > tr > th:nth-child(1)::after,
table[order][order-by="1"] > thead > tr > th:nth-child(2)::after,
table[order][order-by="2"] > thead > tr > th:nth-child(3)::after,
table[order][order-by="3"] > thead > tr > th:nth-child(4)::after { display: inline-block; }

table[order][order-by="0"] > thead > tr > th:nth-child(1),
table[order][order-by="1"] > thead > tr > th:nth-child(2),
table[order][order-by="2"] > thead > tr > th:nth-child(3),
table[order][order-by="3"] > thead > tr > th:nth-child(4) { color: var(--link-hover); }

/* ==========================================================================
   Ellipsis & Planet Image
   ========================================================================== */

a.file {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

a[aria-label="Enter fantastic planet"] {
  float: right;
  white-space: inherit;
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
}
a[aria-label="Enter fantastic planet"] > img {
  height: 48px; width: 48px;
  margin: -24px 24px;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Row Hover Outline
   ========================================================================== */

tbody tr { position: relative; }

tbody tr::after {
  content: '';
  position: absolute;
  inset-block: 0;
  inset-inline: -1em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--link);
  pointer-events: none;
  opacity: 0;
  transition: opacity 100ms ease-out;
  box-shadow: 0 0 6px rgba(158,195,255,0.25), inset 0 0 8px rgba(158,195,255,0.04);
}

/* Hover: only on devices that support it */
@media (hover: hover) {
  tbody tr:hover::after {
    animation:
      row-flicker 0.4s ease-out forwards,
      row-pulse   1.8s 0.4s ease-in-out infinite;
  }
}

@keyframes row-flicker {
  0%   { opacity: 0;    box-shadow: 0 0 14px rgba(158,195,255,0.7), inset 0 0 10px rgba(158,195,255,0.1); }
  8%   { opacity: 0.75; box-shadow: 0 0 10px rgba(158,195,255,0.8); }
  16%  { opacity: 0.15; }
  24%  { opacity: 0.8;  }
  35%  { opacity: 0.25; }
  50%  { opacity: 0.85; box-shadow: 0 0 8px rgba(158,195,255,0.5), inset 0 0 6px rgba(158,195,255,0.08); }
  100% { opacity: 0.85; box-shadow: 0 0 8px rgba(158,195,255,0.5), inset 0 0 6px rgba(158,195,255,0.08); }
}

@keyframes row-pulse {
  0%, 100% { opacity: 0.85; box-shadow: 0 0 8px rgba(158,195,255,0.5), inset 0 0 6px rgba(158,195,255,0.08); }
  50%       { opacity: 0.55; box-shadow: 0 0 4px rgba(158,195,255,0.25), inset 0 0 4px rgba(158,195,255,0.04); }
}

/* ==========================================================================
   Post-Read State
   ========================================================================== */

tr.post-read td a {
  text-shadow: none;
  opacity: 0.55;
  color: var(--text-muted);
}
tr.post-read td a:hover,
tr.post-read td a:focus-visible {
  text-shadow: none;
  opacity: 0.75;
}
/* Row hover outline still applies to post-read rows */

/* ==========================================================================
   Freeze State
   ========================================================================== */

body.frozen main *,
body.frozen main *::before,
body.frozen main *::after {
  animation-play-state: paused !important;
}
body.frozen .power-indicator {
  animation-play-state: running !important;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media screen and (max-width: 768px) {
  main {
    max-width: 100%;
    min-height: 100vh;
    margin: 0;
    padding: var(--space-5);
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  table { font-size: 0.85rem; }

  /* Hide Modify column */
  th:nth-child(4), td:nth-child(4) { display: none; }

  a[aria-label="Enter fantastic planet"] > img { height: 32px; width: 32px; margin: -12px 8px; }
}

@media screen and (max-width: 480px) {
  main { padding: var(--space-4); }
  pre.prompt { font-size: 0.75rem; }
}

@media (pointer: coarse) {
  td a   { 
    padding: var(--space-1) var(--space-2); 
    margin-left: calc(-1 * var(--space-2)); 
  }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  main::before, pre.prompt,
  .prompt-r, .prompt-dollar, .git-arrow, .prompt-check,
  td img, td a,
  tbody tr::after {
    animation: none !important;
    transition: none !important;
  }
  td a, td a:hover, td a:focus-visible { text-shadow: none; }
  tbody tr:hover::after { opacity: 0.85; }
  .power-indicator { animation: none !important; opacity: 0.8; }
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
  main {
    color: black;
    background: white !important;
    border: none;
    max-width: 100%;
    margin: 0;
    padding: var(--space-4);
    box-shadow: none;
  }
  main::before { display: none; }
  .power-indicator, #desync-swipe { display: none !important; }
  table, th, td a { color: black; text-shadow: none !important; }
  td a:visited { color: #333 !important; }
  .prompt, td a, tbody tr::after {
    animation: none !important;
    text-shadow: none !important;
  }
}
