:root {
  --bg-color: #000000;
  --card-bg: #270e01;
  --input-field: #fff9ee;
  --primary-brown: #5d4037;
  --secondary-brown: #8d6e63;
  --accent-gold: #d4af37;
  --text-main: #3e2723;
  --text-secondary: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.7);
  --border-color: #d7ccc8;
  --shadow-soft: rgba(93, 64, 55, 0.15);
  --button-border: var(--text-main);
  --button-grad-end: #4e342e;
  --button-hover-start: #6d4c41;
  --card-fallback: #e0e0e0;
}

/* ---------- Base ---------- */

html {
  scrollbar-gutter: stable;
  overflow-y: scroll;
}

body {
  font-family: "Book Antiqua", "Palatino Linotype", "Georgia", serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  padding: 40px 20px;
  margin: 0;
  line-height: 1.5;
  min-height: 100vh;
  box-sizing: border-box;
}

.page-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

h1 {
  text-align: center;
  margin-bottom: 5px;
  color: var(--primary-brown);
  font-size: 2.2em;
  font-weight: normal;
}

h1.heading-light {
  color: var(--text-secondary);
}

p.subtitle {
  font-size: 1.17em;
  margin-top: 5px;
  margin-bottom: 25px;
  text-align: center;
  color: var(--text-muted);
}

.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;
}

/* ---------- App window ---------- */

.app-window {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: 10px 10px 30px var(--shadow-soft);
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 1200px;
  box-sizing: border-box;
  padding: 70px 40px 40px 40px;
}

/* Title bar */
.app-window::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  background: linear-gradient(
    90deg,
    var(--primary-brown),
    var(--secondary-brown),
    var(--primary-brown)
  );
  border-radius: 5px 5px 0 0;
  z-index: 1;
}

form.app-window,
form.app-form {
  width: 100%;
  display: flex;
  justify-content: center;
}

.results-container.app-window {
  max-width: 1200px;
}

.window-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  padding: 0 15px;
  display: flex;
  align-items: center;
  z-index: 2;
}

.window-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

/* ---------- Form ---------- */

.form-container {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
}

.form-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

.sync-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-color);
  background-color: var(--input-field);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  padding: 14px 16px;
  border-radius: 4px;
}

.sync-input:focus {
  outline: none;
  border-color: var(--accent-gold);
  box-shadow: 0 0 5px rgba(212, 175, 55, 0.4);
}

textarea.sync-input {
  height: 380px;
  width: 100%;
  resize: vertical;
}

.form-submit-wrapper {
  text-align: center;
  margin-top: 12px;
  width: 100%;
}

/* ---------- Buttons ---------- */

button,
.window-icon-btn {
  font-family: inherit;
  cursor: pointer;
  transition: all 0.3s ease;

  /* No blue tap flash or double-tap delay on touch screens */
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  padding: 15px;
  border-radius: 2px;
  font-size: 1.1em;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
  z-index: 1;
}

button[type="submit"],
.primary-submit-btn {
  background: linear-gradient(135deg, var(--primary-brown), var(--button-grad-end));
  color: var(--text-secondary);
  border: 1px solid var(--accent-gold);
  width: 100%;
  max-width: 300px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.window-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 1rem;
  z-index: 2;
  padding: 0;

  /* Short transition so the pressed state doesn't linger */
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.window-icon-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
  stroke: currentColor;
}

/* Mouse-only hover: touch screens keep hover "stuck" after a tap */
@media (hover: hover) {
  button[type="submit"]:hover,
  .primary-submit-btn:hover {
    background: linear-gradient(135deg, var(--button-hover-start), var(--primary-brown));
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
  }

  .window-icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
  }

  .preset-btn:hover {
    background: rgba(212, 175, 55, 0.1);
    color: var(--text-secondary);
    border-color: var(--text-secondary);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }
}

.window-icon-btn:active {
  background-color: rgba(255, 255, 255, 0.15);
}

/* Keep the focus ring for keyboard users only */
.window-icon-btn:focus:not(:focus-visible) {
  outline: none;
}

/* ---------- Keyword cards ---------- */

.keyword-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
  margin-top: 25px;
  margin-bottom: 30px;
}

.keyword-card {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.2)),
    var(--card-accent, var(--card-fallback));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 16px;
  min-height: 110px;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;

  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
  cursor: pointer;
}

.keyword-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 20px var(--shadow-soft);
  border-color: rgba(255, 255, 255, 0.3);
}

.keyword-text {
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--text-primary, #fff);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  margin: 0;
  transition: transform 0.2s ease;
}

.keyword-card:hover .keyword-text {
  transform: translateY(-7px);
}

.hover-details {
  position: absolute;
  bottom: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.2s ease;
  color: rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  pointer-events: none;
}

.keyword-card:hover .hover-details {
  opacity: 1;
  transform: translateY(0);
}

.keyword-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* Overrides the earlier .keyword-text values above */
.keyword-text {
  font-size: 1.25em;
  font-weight: bold;
  color: var(--text-secondary);
  line-height: 1.2;
}

.keyword-score {
  font-size: 0.85em;
  color: rgba(255, 255, 255, 0.9);
  margin-top: auto;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
}

.header-block {
  text-align: center;
  width: 100%;
}

.header-block h1 {
  margin-top: 0;
  margin-bottom: 5px;
}

.header-block p.subtitle {
  margin-top: 5px;
  margin-bottom: 25px;
}

/* ---------- Settings modal ---------- */

.modal-dialog {
  border: 1px solid var(--accent-gold);
  border-radius: 8px;
  background-color: var(--card-bg);
  color: var(--text-secondary);
  padding: 0;
  box-sizing: border-box;
  max-width: 700px;
  width: 90%;
  max-height: calc(100dvh - 24px);
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
}

.modal-content {
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.4em;
  color: var(--accent-gold);
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close-btn:hover {
  color: var(--text-secondary);
}

.modal-body p {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1em;
  line-height: 1.6;
}

.modal-body a {
  color: var(--accent-gold);
  text-decoration: underline;
  font-size: 1em;
}

.modal-body a:hover {
  color: #fff;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 10px;
}

.setting-label {
  font-weight: bold;
  color: var(--accent-gold);
  font-size: 0.95em;
}

/* ---------- Sliders ---------- */

.one-sided-slider-container {
  display: grid;
  grid-template-columns: 1fr 2fr;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.two-sided-slider-container {
  display: grid;
  grid-template-columns: 2fr 3fr 2fr;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.slider-end-label {
  font-size: 0.85em;
  color: var(--text-muted);
  white-space: nowrap;
}

.slider-end-label:first-of-type {
  text-align: right;
}

.slider-under-label {
  font-size: 0.85em;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: center;
  margin-bottom: 10px;
  font-weight: bold;
}

.custom-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--primary-brown);
  outline: none;
  border: 1px solid var(--border-color);
}

.custom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--text-main);
  background: var(--accent-gold);
  transition: transform 0.1s ease;
}

.custom-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--text-main);
  background: var(--accent-gold);
  transition: transform 0.1s ease;
}

.custom-slider::-webkit-slider-thumb:hover,
.custom-slider::-moz-range-thumb:hover {
  transform: scale(1.15);
}

/* ---------- Presets ---------- */

.preset-container,
.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin-top: 2px;
  justify-content: center;
}

.preset-btn {
  background: transparent;
  color: var(--accent-gold);
  border: 1px solid var(--accent-gold);
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.9em;
  font-weight: normal;
  text-transform: none;
  letter-spacing: normal;
  transition: all 0.2s ease;
  width: auto;
  box-shadow: none;
}

.char-counter {
  font-size: 0.9em;
  color: var(--text-muted);
  text-align: right;
  margin-top: 5px;
}

/* ---------- Profile Selection Blocks ---------- */

#profile-options-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 15px;
  margin-top: 10px;
  margin-bottom: 25px;
  width: 100%;
}

.profile-option-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  transition: all 0.2s ease;
  position: relative;
  /* Prevent text selection when clicking rapidly */
  user-select: none;
}

/* Hide the actual radio circle, because the whole card acts as the button */
.profile-option-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.profile-option-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.profile-option-name {
  font-weight: bold;
  font-size: 1.15em;
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.profile-option-desc {
  margin: 0;
  font-size: 0.85em;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Hover State (for mouse users) */
@media (hover: hover) {
  .profile-option-card:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(212, 175, 55, 0.5); /* Faded gold border */
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

/* Active/Selected State */
.profile-option-card.active {
  background: rgba(212, 175, 55, 0.1); /* Subtle gold tint */
  border-color: var(--accent-gold);
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.15);
}

.profile-option-card.active .profile-option-name {
  color: var(--accent-gold);
}

/* Focus state for keyboard accessibility */
.profile-option-card input[type="radio"]:focus-visible ~ .profile-option-details {
  outline: 2px solid var(--accent-gold);
  outline-offset: 4px;
  border-radius: 4px;
}

/* =========================================================
   RESPONSIVE (keep at the end of the file)
   ========================================================= */

/* Tablets, phones, and any short landscape screen.
   !important and the "html body" prefix beat the base grid rules. */
@media (max-width: 950px), (orientation: landscape) and (max-height: 600px) {
  /* Single column: labels on top, slider below */
  html body .two-sided-slider-container {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: auto !important;
    align-items: stretch !important;
    justify-items: stretch !important;
    gap: 8px !important;

    height: auto !important;
    min-height: 0 !important;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }

  html body .two-sided-slider-container .slider-end-label {
    grid-column: 1 !important;
    width: 100%;
    text-align: left !important;
    white-space: normal !important;
    padding-left: 5px;
  }

  html body .two-sided-slider-container .slider-end-label:first-of-type {
    grid-row: 1 !important;
  }

  html body .two-sided-slider-container .slider-end-label:last-of-type {
    grid-row: 2 !important;
  }

  html body .two-sided-slider-container .slider-end-label:first-of-type::before {
    content: "Left: ";
    font-weight: bold;
    color: var(--accent-gold);
  }

  html body .two-sided-slider-container .slider-end-label:last-of-type::before {
    content: "Right: ";
    font-weight: bold;
    color: var(--accent-gold);
  }

  /* Square slider; the border is an inset shadow so it fits its container exactly */
  html body .two-sided-slider-container .custom-slider {
    grid-column: 1 !important;
    grid-row: 3 !important;

    display: block;
    box-sizing: border-box;
    width: 100% !important;
    min-width: 0;
    height: 23px;
    margin: 8px 0 !important;
    padding: 0;
    border: 0;
    border-radius: 0;

    -webkit-appearance: none;
    appearance: none;

    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 0 0 1px var(--text-main);
  }

  .two-sided-slider-container .custom-slider::-webkit-slider-runnable-track {
    -webkit-appearance: none;
    height: 23px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .two-sided-slider-container .custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 23px;
    height: 23px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--accent-gold);
    cursor: pointer;
  }

  .two-sided-slider-container .custom-slider::-moz-range-track {
    height: 23px;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  .two-sided-slider-container .custom-slider::-moz-range-thumb {
    box-sizing: border-box;
    width: 23px;
    height: 23px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--accent-gold);
    cursor: pointer;
  }

  /* Presets stacked top to bottom */
  .preset-container,
  .preset-buttons {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 10px;
  }

  .preset-btn {
    width: 100%;
  }
}

/* Portrait phones: tighter page spacing */
@media (max-width: 650px) {
  body {
    padding: 20px 10px;
  }

  .app-window {
    padding: 65px 20px 30px 20px;
  }

  textarea.sync-input {
    height: 250px;
  }

  /* Settings modal: fit the narrow screen */
  .modal-dialog {
    width: calc(100vw - 20px);
  }

  .modal-content {
    padding: 16px;
  }

  .slider-end-label,
  .slider-under-label {
    white-space: normal;
  }

  .one-sided-slider-container > * {
    min-width: 0;
  }
}
