/* === Reset & Base === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #ffcccc;
  --color-surface: rgba(60, 60, 84, 0.9);
  --color-text: #fff;
  --color-text-muted: #666666;
  --color-primary: #669;
  --color-primary-hover: #ffcccc;
  --color-highlight: #ffcccc;
  --color-highlight-secondary: #bfdbfe;
  --color-border: #ffcccc;
  --color-error: #dc2626;
  --color-offline: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.15);
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --max-width: 720px;
}

html {
  font-size: 16px;
  line-height: 1.6;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Layout === */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  text-align: center;
  margin-bottom: 1.5rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-text);
  text-shadow: 0px 0px 8px var(--color-primary)
}

header .subtitle {
  font-size: 0.9rem;
  color: var(--color-text);
  margin-top: 0.25rem;
  text-shadow: 0px 0px 8px var(--color-primary)
}

main {
  flex: 1;
  margin-bottom: 1.5rem;
}

/* === Offline Indicator === */
.offline-indicator {
  background: var(--color-offline);
  color: #ffffff;
  text-align: center;
  padding: 0.5rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.offline-indicator[hidden] {
  display: none;
}

/* === Story Display === */
.story-display {
  background: var(--color-surface);
  border: 2px dotted var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  min-height: 200px;
  line-height: 1.8;
  font-size: 1.05rem;
  box-shadow: var(--shadow);
}

.story-display .placeholder {
  color: var(--color-text-muted);
  font-style: italic;
  text-align: center;
  padding: 2rem 0;
}

.story-display p {
  margin: 0.75em 0;
}

/* === Entry Spans === */
.entry {
  cursor: pointer;
  border-radius: 2px;
  transition: background-color 0.15s ease;
}

.entry--pending {
  opacity: 0.45;
}

.entry:hover {
  background-color: var(--color-highlight);
  color: #000;
}

.entry.same-author {
  background-color: var(--color-highlight-secondary);
  color: #000;
}

/* === Tooltip === */
.tooltip {
  position: fixed;
  background: var(--color-text);
  color: #000;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
}

.tooltip.visible {
  opacity: 1;
}

/* === Error Message === */
.error-message {
  color: var(--color-error);
  font-size: 0.85rem;
  min-height: 1.25rem;
  margin-bottom: 0.5rem;
}

.error-message:empty {
  display: none;
}

/* === Entry Form === */
.entry-form {
  background: var(--color-surface);
  border: 2px dotted var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.75rem;
  position: relative;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--color-text);
}

.form-group input,
.form-group select {
  border: none;
  border-bottom: 1.5px solid var(--color-text-muted);
  background: transparent;
  padding: 0.2em 0.2em;
  border-radius: 0;
  font-size: 0.95rem;
  font-family: var(--font-body);
  color: var(--color-text);
  transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-bottom-color: var(--color-primary);
}

.char-count {
  position: absolute;
  right: 0.75rem;
  bottom: 0.6rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  pointer-events: none;
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-row .form-group {
  flex: 1;
}

button[type="submit"] {
  width: 100%;
  padding: 0.7rem;
  background: var(--color-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

button[type="submit"]:hover {
  background: var(--color-primary-hover);
}

button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* === Responsive Design === */
@media (max-width: 600px) {
  .container {
    padding: 1rem 0.75rem;
  }

  header h1 {
    font-size: 1.4rem;
  }

  .story-display {
    padding: 1rem;
    font-size: 1rem;
    min-height: 150px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }

  .entry-form {
    padding: 1rem;
  }

  button[type="submit"] {
    padding: 0.8rem;
  }
}

@media (min-width: 601px) and (max-width: 1024px) {
  .container {
    padding: 1.5rem;
  }
}

@media (min-width: 1025px) {
  .container {
    padding: 2rem 1rem;
  }

  .story-display {
    min-height: 300px;
  }
}

/* === Animated Background (from muel.nu) === */
#bg0, #bg1, #bg2, #bg01 {
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: -1;
  background-position-y: center;
  background-size: 1000px;
  background-position-x: 0;
  background-repeat: repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#bg1 {
  background-image: url('https://muel.nu/noisep.png');
  animation: bgmove 600s infinite;
  height: 52vh;
  margin-top: 48vh;
}

#bg2 {
  background-image: url('https://muel.nu/noisep.png');
  background-position-y: 100%;
  background-position-x: 200px;
  animation: bgmove2 600s infinite;
  height: 52vh;
  margin-top: 48vh;
}

#bg0 {
  background-image: url('https://muel.nu/sjo5l.png');
  background-size: cover;
  background-position: top center;
  height: 73vh;
  margin-top: 27vh;
}

#bg01 {
  background-image: url('https://muel.nu/sjo5m.png');
  background-position-y: bottom;
  background-size: cover;
  background-repeat: repeat-x;
  min-height: 30vh;
  animation: bgmove3 1820s linear infinite;
}

@keyframes bgmove {
  0%   { background-position-x: 0; }
  5%   { background-position-x: 100px; }
  15%  { background-position-x: -100px; }
  25%  { background-position-x: 100px; }
  35%  { background-position-x: 300px; }
  45%  { background-position-x: 200px; }
  55%  { background-position-x: 400px; }
  65%  { background-position-x: 200px; }
  75%  { background-position-x: 0; }
  85%  { background-position-x: -200px; }
  95%  { background-position-x: 200px; }
  100% { background-position-x: 0; }
}

@keyframes bgmove2 {
  0%   { background-position-y: 0; }
  10%  { background-position-y: 200px; }
  20%  { background-position-y: 100px; }
  30%  { background-position-y: -100px; }
  40%  { background-position-y: 100px; }
  50%  { background-position-y: 200px; }
  60%  { background-position-y: 400px; }
  70%  { background-position-y: 300px; }
  80%  { background-position-y: 200px; }
  90%  { background-position-y: 100px; }
  100% { background-position-y: 0; }
}

@keyframes bgmove3 {
  0%   { background-position-x: -1820px; }
  100% { background-position-x: 1820px; }
}

/* === Mobile FAB Toggle & Collapsible Form === */
.fab-toggle {
  display: none;
}

/* Desktop: form panel always visible, no overlay behavior */
.form-panel {
  display: block;
}

@media (max-width: 600px) {
  .fab-toggle {
    display: block;
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 900;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 2rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.15s ease;
  }

  .fab-toggle:hover {
    background: var(--color-primary-hover);
  }

  .fab-toggle[aria-expanded="true"] {
    display: none;
  }

  .form-panel {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.4);
    padding: 1rem;
    padding-top: 2rem;
    overflow-y: auto;
  }

  .form-panel.open {
    display: block;
  }

  .form-panel .entry-form {
    width: 100%;
    border-radius: var(--radius);
    background: var(--color-surface);
    padding: 1rem;
    box-shadow: var(--shadow-lg);
  }

  footer {
    position: static;
  }
}

/* === Promise Line (spam protection) === */
.promise-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.15em;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-top: 0.75rem;
  line-height: 1.8;
}

.promise-line span {
  white-space: nowrap;
  line-height: 1.8;
  font-size: 1.05rem;
  color: var(--color-text);
}

.inline-input {
  border: none;
  border-bottom: 1.5px dotted var(--color-text);
  background: transparent;
  font-size: 1rem;
  font-family: var(--font-body);
  color: var(--color-text);
  padding: 0 0.2em;
  min-width: 4em;
  max-width: 10em;
  width: auto;
  outline: none;
  transition: border-color 0.15s ease;
  margin: 0 0.3em;
}

.inline-input:focus {
  border-bottom-color: var(--color-primary);
}

.inline-input#author-name {
  min-width: 5em;
  max-width: 12em;
}

.inline-input#promise-field {
  min-width: 3.5em;
  max-width: 6em;
}
