/*
 * Retro WAP Mobile Styles
 * Targets legacy mobile devices from ~80px to ~360px wide.
 * Design goals: high contrast, clear hierarchy, tappable targets,
 * no horizontal overflow, authentic early-2000s mobile feel.
 */

/* --- Theme variables --- */
:root {
  --bg: #fff;
  --fg: #111;
  --muted: #555;
  --dim: #777;
  --link: #0000ee;
  --link-visited: #551a8b;
  --link-active: #cc0000;
  --border: #ccc;
  --border-soft: #ddd;
  --panel: #fff;
  --panel-dim: #fff;
  --accent-bg: #000;
  --accent-fg: #fff;
  --focus: #666;
  --success: #060;
  --radius: 0;
}

/* --- Reset & base --- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Courier New", Courier, "Liberation Mono", monospace;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0.5em;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Courier New", Courier, "Liberation Mono", monospace;
  font-size: 1rem;
  line-height: 1.55;
  max-width: 100%;
  overflow-x: hidden;
}

/* Prevent long URLs / words from breaking layout */
body, p, h1, h2, h3, a, span, div, li {
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}

img, svg, video {
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  -ms-interpolation-mode: nearest-neighbor;
}

a {
  color: var(--link);
  text-decoration: underline;
}

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

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

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* --- Header --- */
.header {
  text-align: center;
  padding: 0.4em 0;
  margin-bottom: 0.5em;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.header h1 {
  font-size: 1.0625rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 0 0 0.2em;
  line-height: 1.2;
}

.header .subtitle {
  font-size: 0.6875rem;
  color: var(--muted);
  font-style: italic;
  margin: 0 0 0.4em;
}

/* --- Navigation (top) --- */
.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25em;
  justify-content: center;
}

.nav-links form {
  display: inline-flex;
  margin: 0;
}

.nav-links button.logout-link,
.nav-bar button.logout-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 0.75rem;
  padding: 0.35em 0.6em;
  border: 1px solid var(--border-soft);
  background: var(--panel-dim);
  color: var(--fg);
  text-decoration: none;
  min-height: 36px;
  min-width: 44px;
  cursor: pointer;
}

.nav-links button.logout-link:hover,
.nav-links button.logout-link:active,
.nav-bar button.logout-link:hover,
.nav-bar button.logout-link:active {
  background: #ddd;
}

.nav-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  padding: 0.35em 0.6em;
  border: 1px solid var(--border-soft);
  background: var(--panel-dim);
  color: var(--fg);
  text-decoration: none;
  min-height: 36px;
  min-width: 44px;
}

.nav-links a.active,
.nav-links a[aria-current] {
  background: var(--accent-bg);
  color: var(--accent-fg);
  border-color: var(--accent-bg);
}

.nav-links a:hover,
.nav-links a:active {
  background: #ddd;
}

.nav-links a.active:hover,
.nav-links a.active:active {
  background: #333;
}

/* --- Flash messages --- */
.flash {
  padding: 0.5em;
  margin: 0.5em 0;
  border: 1px solid var(--border);
  background: var(--panel-dim);
  color: var(--fg);
  font-size: 0.875rem;
}

.flash.success {
  border-left: 4px solid var(--success);
  text-transform: uppercase;
  font-size: 0.875rem;
}

.flash.error {
  border-left: 4px solid #c00;
  text-transform: uppercase;
  font-size: 0.875rem;
}

/* --- Titles --- */
.page-title {
  font-size: 1rem;
  margin: 0.5em 0;
  padding-bottom: 0.2em;
  border-bottom: 1px dashed var(--border-soft);
}

.section-title {
  font-size: 0.75rem;
  font-weight: bold;
  margin: 0.6em 0 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- Forms --- */
form p {
  margin: 0.5em 0;
}

.field {
  width: 100%;
  padding: 0.5em;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  border: 1px inset var(--border-soft);
  background: var(--panel);
  color: var(--fg);
  border-radius: var(--radius);
  -webkit-appearance: none;
  appearance: none;
}

select.field {
  padding-right: 1.5em;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23000' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4em center;
}

.field-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.2em;
}

input[type="file"] {
  font-family: inherit;
  font-size: 0.8125rem;
  width: 100%;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1;
  padding: 0.35em 0.8em;
  border: 1px outset var(--border-soft);
  background: var(--panel-dim);
  color: var(--fg);
  text-decoration: none;
  cursor: pointer;
  min-height: 32px;
  min-width: 44px;
  border-radius: var(--radius);
}

.btn:active {
  border-style: inset;
}

.btn-primary {
  font-size: 0.875rem;
  font-weight: bold;
  padding: 0.35em 1em;
  border: 1px outset var(--border);
  background: var(--accent-bg);
  color: var(--accent-fg);
}

.btn-primary:active {
  background: #333;
}

.btn-toggle {
  font-size: 0.75rem;
  padding: 0.35em 0.6em;
  margin: 0.15em;
  min-height: 32px;
}

.btn-toggle.active {
  background: var(--accent-bg);
  color: var(--accent-fg);
  border-style: inset;
}

/* --- Boxed groups --- */
.boxed {
  padding: 0.6em;
  border: 1px dashed var(--border-soft);
  background: var(--panel);
  margin: 0.5em 0;
}

.boxed-flush {
  padding: 0.3em 0;
  margin-bottom: 0.5em;
  border-bottom: 1px dashed var(--border-soft);
}

.inline-form {
  display: inline-block;
  margin: 0.1em;
}

.meta-text {
  font-size: 0.75rem;
  color: var(--muted);
}

/* --- Random funny GIF --- */
.funny-gif-card {
  text-align: center;
  padding: 0.5em;
  margin: 0.5em 0;
  background: var(--panel);
}

.funny-gif-card .gif-img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
}

.funny-gif-card .gif-title {
  font-size: 0.75rem;
  font-weight: bold;
  margin: 0 0 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.funny-gif-card .gif-theme {
  font-size: 0.625rem;
  color: var(--dim);
  margin: 0.3em 0 0;
}

/* --- Animal of the day --- */
.animal-card {
  text-align: center;
  padding: 0.5em;
  margin: 0.5em 0;
  background: var(--panel);
}

.animal-card .animal-img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
}

.animal-card .animal-title {
  font-size: 0.75rem;
  font-weight: bold;
  margin: 0 0 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.animal-card .animal-name {
  font-size: 0.8125rem;
  font-weight: bold;
  margin: 0.4em 0 0.2em;
  color: var(--fg);
}

.animal-card .animal-credit {
  font-size: 0.625rem;
  color: var(--dim);
  margin: 0.3em 0 0;
}

/* --- Article list --- */
.articles {
  border-top: 1px dashed var(--border-soft);
}

.article-item {
  padding: 0.6em 0;
  border-bottom: 1px dashed var(--border-soft);
}

.article-item:last-child {
  border-bottom: none;
}

.article-item h3 {
  font-size: 0.875rem;
  font-weight: bold;
  margin: 0 0 0.25em;
  line-height: 1.4;
}

.article-item h3 a {
  color: var(--fg);
  text-decoration: none;
}

.article-item h3 a::before {
  content: "> ";
  color: var(--link);
}

.article-item h3 a:hover,
.article-item h3 a:active {
  text-decoration: underline;
}

.article-item.read h3 a {
  color: var(--dim);
}

.article-item.read .article-summary {
  color: var(--dim);
}

.article-item.read .read-mark {
  font-size: 0.625rem;
  color: var(--success);
  font-weight: bold;
  text-transform: uppercase;
  margin-left: 0.3em;
}

.article-meta {
  font-size: 0.6875rem;
  color: var(--muted);
  margin-bottom: 0.3em;
  line-height: 1.4;
}

.article-meta .source {
  font-weight: bold;
  color: var(--fg);
}

.article-meta .sep {
  color: var(--border-soft);
  margin: 0 0.3em;
}

.article-summary {
  font-size: 0.8125rem;
  color: var(--fg);
  line-height: 1.5;
  margin: 0.3em 0;
}

.read-link {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: bold;
  margin-top: 0.2em;
}

/* --- Article detail --- */
.article-title {
  font-size: 0.9375rem;
  margin: 0.4em 0 0.6em;
  line-height: 1.4;
}

.article-content {
  margin: 0.5em 0;
  font-size: 0.875rem;
  line-height: 1.65;
}

.article-content p {
  margin: 0.6em 0;
}

.article-content .embedded-image {
  text-align: center;
  margin: 0.8em 0;
  padding: 0.5em;
  border: 1px solid var(--border-soft);
  background: var(--panel-dim);
}

.article-content .embedded-image img {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}

.login-prompt {
  margin-top: 1em;
  padding: 0.6em;
  border: 1px solid var(--border-soft);
  background: var(--panel-dim);
  text-align: center;
  font-size: 0.8125rem;
}

/* --- Profile --- */
.profile-header {
  text-align: center;
  padding: 0.8em 0;
  border-bottom: 1px dashed var(--border-soft);
  margin-bottom: 0.5em;
}

.profile-avatar {
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
  border: 1px solid var(--border-soft);
  background: var(--panel-dim);
}

.profile-name {
  font-size: 0.9375rem;
  margin: 0.4em 0 0.2em;
}

/* --- Source link --- */
.source-link {
  text-align: center;
  padding: 0.6em;
  margin: 0.6em 0;
  border: 1px dashed var(--border-soft);
  background: var(--panel-dim);
}

.source-link a {
  font-size: 0.75rem;
  font-weight: bold;
  color: var(--fg);
  text-decoration: none;
}

.source-link a:hover,
.source-link a:active {
  text-decoration: underline;
}

/* --- Pagination --- */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25em;
  padding: 0.5em 0;
  justify-content: center;
  border-bottom: 1px dashed var(--border-soft);
  margin: 0.5em 0;
}

.pagination .page-link,
.pagination .page-current,
.pagination .page-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 32px;
  padding: 0.2em 0.5em;
  font-size: 0.75rem;
  text-decoration: none;
}

.pagination .page-link {
  border: 1px solid var(--border-soft);
  background: var(--panel-dim);
  color: var(--fg);
}

.pagination .page-link:hover,
.pagination .page-link:active {
  background: #ddd;
}

.pagination .page-current {
  border: 1px solid var(--border);
  background: var(--accent-bg);
  color: var(--accent-fg);
  font-weight: bold;
}

.pagination .page-ellipsis {
  color: var(--dim);
}

.page-jump-input {
  width: 50px;
  padding: 0.3em;
  font-family: inherit;
  font-size: 0.8125rem;
  border: 1px inset var(--border-soft);
  background: var(--panel);
  color: var(--fg);
  text-align: center;
}

/* --- Bottom nav --- */
.nav-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  padding: 0.5em 0;
  margin: 0.5em 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.nav-bar a {
  flex: 1 1 auto;
  min-width: 60px;
  text-align: center;
  font-size: 0.75rem;
  padding: 0.4em 0.5em;
  border: 1px solid var(--border-soft);
  background: var(--panel-dim);
  color: var(--fg);
  text-decoration: none;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-bar a:hover,
.nav-bar a:active {
  background: #ddd;
}

/* --- Footer --- */
footer {
  text-align: center;
  padding: 0.8em 0;
  margin-top: 0.8em;
  border-top: 1px solid var(--border);
  font-size: 0.6875rem;
  color: var(--muted);
}

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

/* --- Breakpoints for tiny legacy screens --- */

/* Small modern phones / large feature phones */
@media (max-width: 360px) {
  body { padding: 0.35em; font-size: 0.9375rem; }
  .header h1 { font-size: 0.9375rem; }
  .header .subtitle { font-size: 0.625rem; }
  .nav-links a { font-size: 0.6875rem; padding: 0.3em 0.5em; min-height: 32px; }
  .page-title { font-size: 0.9375rem; }
  .section-title { font-size: 0.8125rem; }
  .article-item h3 { font-size: 0.8125rem; }
  .article-content { font-size: 0.8125rem; }
  .article-title { font-size: 0.875rem; }
}

/* Old smartphones / WAP era (~160-240px) */
@media (max-width: 240px) {
  body { padding: 0.25em; font-size: 0.875rem; line-height: 1.5; }
  .header { padding: 0.3em 0; }
  .header h1 { font-size: 0.8125rem; letter-spacing: 0; }
  .header .subtitle { display: none; }
  .nav-links { flex-direction: column; gap: 0.15em; }
  .nav-links a {
    width: 100%;
    justify-content: flex-start;
    font-size: 0.75rem;
    padding: 0.4em 0.5em;
    min-height: 32px;
  }
  .nav-links a::before {
    content: "> ";
    color: var(--link);
    margin-right: 0.3em;
  }
  .page-title { font-size: 0.875rem; }
  .section-title { font-size: 0.75rem; }
  .field { font-size: 0.875rem; padding: 0.4em; }
  .btn { font-size: 0.8125rem; min-height: 32px; }
  .btn-primary { font-size: 0.8125rem; }
  .article-item h3 { font-size: 0.75rem; }
  .article-meta { font-size: 0.625rem; }
  .article-summary { font-size: 0.75rem; }
  .pagination .page-link,
  .pagination .page-current,
  .pagination .page-ellipsis { min-width: 26px; min-height: 26px; font-size: 0.6875rem; }
  .nav-bar a { font-size: 0.6875rem; min-height: 32px; }
  footer { font-size: 0.625rem; }
}

/* Feature phones / very small screens (~80-160px) */
@media (max-width: 160px) {
  body { padding: 0.15em; font-size: 0.8125rem; }
  .header h1 { font-size: 0.75rem; }
  .nav-links a { font-size: 0.6875rem; padding: 0.3em 0.4em; min-height: 28px; }
  .flash { font-size: 0.75rem; padding: 0.4em; }
  .page-title { font-size: 0.8125rem; }
  .article-title { font-size: 0.8125rem; }
  .article-content { font-size: 0.75rem; }
  .btn { font-size: 0.75rem; min-height: 28px; padding: 0.3em 0.5em; }
  .btn-primary { font-size: 0.75rem; }
  .animal-card .animal-title { font-size: 0.625rem; }
  .animal-card .animal-credit { font-size: 0.5625rem; }
  .funny-gif-card .gif-title { font-size: 0.625rem; }
  .funny-gif-card .gif-theme { font-size: 0.5625rem; }
  .pagination .page-link,
  .pagination .page-current,
  .pagination .page-ellipsis { min-width: 22px; min-height: 22px; font-size: 0.625rem; padding: 0.15em 0.3em; }
}

/* Ultra-narrow (~80px and below) */
@media (max-width: 100px) {
  body { font-size: 0.75rem; padding: 0.1em; }
  .header h1 { font-size: 0.6875rem; }
  .nav-links a { font-size: 0.625rem; padding: 0.2em 0.3em; }
  .article-item h3 { font-size: 0.6875rem; }
  .article-meta { font-size: 0.5625rem; }
  .nav-bar a { font-size: 0.625rem; min-height: 26px; padding: 0.2em; }
  .btn { min-height: 26px; }
}

/* Coarse pointer = touch screens */
@media (pointer: coarse) {
  .nav-links a,
  .nav-bar a,
  .btn,
  .btn-toggle,
  .pagination .page-link,
  .pagination .page-current {
    min-height: 40px;
  }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --fg: #eee;
    --muted: #bbb;
    --dim: #999;
    --link: #8cf;
    --link-visited: #c9f;
    --link-active: #f66;
    --border: #eee;
    --border-soft: #888;
    --panel: #111;
    --panel-dim: #222;
    --accent-bg: #fff;
    --accent-fg: #000;
    --focus: #0ff;
    --success: #6f6;
  }

  .header,
  .animal-card,
  .boxed,
  .boxed-flush,
  .source-link,
  .login-prompt,
  .article-content .embedded-image {
    background: var(--panel);
    border-color: var(--border-soft);
  }

  .field,
  .page-jump-input {
    background: var(--panel);
    color: var(--fg);
    border-color: var(--border-soft);
  }

  select.field {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23eee' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  }

  .btn,
  .nav-links a,
  .nav-bar a,
  .pagination .page-link {
    background: var(--panel-dim);
    color: var(--fg);
    border-color: var(--border-soft);
  }

  .btn:hover,
  .nav-links a:hover,
  .nav-bar a:hover,
  .pagination .page-link:hover {
    background: #333;
  }

  .btn-primary,
  .nav-links a.active,
  .pagination .page-current,
  .btn-toggle.active {
    background: var(--accent-bg);
    color: var(--accent-fg);
    border-color: var(--accent-bg);
  }

  .article-item h3 a {
    color: var(--fg);
  }

  .article-item.read h3 a,
  .article-item.read .article-summary {
    color: var(--dim);
  }
}
