body {
  font-family: 'Open Serif', serif;
  font-size: 16px;
  margin: 0;
  padding: 0;
  background-color: #ceeff6; /* Light cyan for the main background */
  color: #333; /* Slightly softer than pure black */
  box-sizing: border-box;
}

a, a:visited {
  color: #d02929; /* Electorama red */
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.current-method {
  font-weight: bold;
  color: #666;
}

#content {
  max-width: calc(100vw - 20vw); /* 1 vw is 1% of the viewport's width */
  margin: 20px auto;
  padding: 20px;
  background-color: #fff; /* White background for content */
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Subtle shadow for depth */
  border: 2px solid #d02929; /* Electorama red border */
}

header {
  background: #ceeff6;
  padding: 10px 0;
  text-align: center;
  border-bottom: 2px solid #d02929;
  background-image: linear-gradient(180deg, #97dbec 1px, transparent 1px),
                    linear-gradient(180deg, #ceeff6 1px, transparent 1px);
  background-size: 100% 5px; /* Creates horizontal pinstripes */
}

header img {
  max-height: 60px;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  border: 1px solid #ddd;
  padding: 8px;
}

th {
  background-color: #d02929;
  color: #fff;
}

input[type="submit"] {
  background-color: #d02929;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
}

input[type="submit"]:hover {
  background-color: #bb2525;
}

#submitButton.throbbing {
  animation: throb 0.5s ease-in-out infinite alternate;
}

@keyframes throb {
  from { background-color: #d02929; }
  to { background-color: #821b1b; }
}

.example-section {
  display: flex;
}

textarea {
  box-sizing: border-box;
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
}

textarea.examplearea {
  background-color: #fff0f0;
  border: 1px dashed #333;
  float: right;
  width:100%;
  margin:5px 0;
  padding:3px;
}

.exampleareacontainer {
  padding-right: 8px;
}

pre {
  white-space: pre-wrap; /* Allows text to wrap within container */
  overflow-x: auto; /* Provides a horizontal scrollbar if needed */
  background-color: #f8f8f8; /* Light background for the pre element */
  border: 1px solid #ddd; /* Border to match other inputs */
  padding: 10px;
  margin: 0 20px 20px 20px; /* Margin to match the #content padding */
}

@media (min-width: 768px) {
  #content {
    margin: 20px auto;
  }
}

.hscroll {
  overflow-x: auto;
  width: 100%;
}

.vscroll {
  height: 22.5em;
  overflow-y: auto;
}

svg {
  max-width: 100%;
  height: auto;
}

.scaletable {
  transform: scale(0.8);
  transform-origin: top left;
  width: 125%;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
}

#abifbox {
  display: none;
}

#abifbox.active {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

/* Hide bottom row by default; show only when the top box is active */
.abif-bottomrow {
  display: none;
}

#abifbox.active + .abif-bottomrow {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  margin-top: 10px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  float: right;
  width: 99%;
  padding-left: 1%;
}

.tab-links {
  list-style: none;
  padding: 0;
  margin-bottom: 20px;
  float: left;
}

.tab-links li {
  /* display: inline-block; */
  margin-right: 10px;
  padding: 8px 15px;
  border: 1px solid #ddd;
  border-right: none;
  background-color: #f5f5f5;
  cursor: pointer;
  width: 150px;
}

.tab-links li.active {
  background-color: #fff;
  border-bottom: 1px solid #fff;
}

.hatnote {
    margin-top: -1.2rem;
    font-size: smaller;
    margin-left: 2rem;
}

/* Notice banners for voting method disclaimers */
.notice-banner {
    display: flex;
    align-items: flex-start;
    margin: 1em 0;
    padding: 0.75em 1em;
    border-left: 4px solid;
    border-radius: 4px;
    font-size: 0.9em;
    line-height: 1.4;
}

.notice-banner .notice-icon {
    margin-right: 0.75em;
    font-size: 1.2em;
    line-height: 1;
    flex-shrink: 0;
}

.notice-banner .notice-content {
    flex: 1;
}

.notice-banner .notice-title {
    font-weight: bold;
    margin-bottom: 0.25em;
}

.notice-banner .notice-text {
    margin: 0;
}

/* Notice type styling */
.notice-disclaimer, .notice-note {
    background-color: #f5f5f5;
    border-left-color: #666;
    color: #333;
}

.notice-warning {
    background-color: #fef2f2;
    border-left-color: #ef4444;
    color: #b91c1c;
}

.notice-info {
    background-color: #eff6ff;
    border-left-color: #3b82f6;
    color: #1e40af;
}

.notice-debug {
    background-color: #f3f4f6;
    border-left-color: #6b7280;
    color: #374151;
}

.election-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-right: 2em;
}

.election-id {
  /* Optional: add left-side styling if desired */
}

.election-tags {
  font-size: 85%;
  color: #aaa;
  text-align: right;
  min-width: 80px;
  margin-left: 1em;
}

.color-box {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 1px solid #999;
    vertical-align: middle;
    margin-right: 0.5em;
}

.tab-color-box {
    display: inline-block;
    width: 0.8em;
    height: 0.8em;
    border: 1px solid #999;
    vertical-align: middle;
    margin-right: 0.4em;
    border-radius: 2px;
}

/* Centralized styling for all voting methods */
.greyedOut {
    color: darkgrey;
    background-color: lightgrey;
}

/* Method tabs interface for UX Step 4 */
.method-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
    margin: 1em 0;
    /* border-bottom: 2px solid #333; */
    background-color: #f5f5f5;
    padding: 0 4px;
}

.method-tab {
    display: inline-block;
    padding: 12px 20px;
    background-color: #e0e0e0;
    border: 1px solid #666;
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    color: #666;
    text-decoration: none;
    font-weight: 500;
    position: relative;
    top: 2px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

a.method-tab {
    color: #333 !important;
}

/* View All Methods link for single-method pages */
.view-all-methods {
    margin-left: 1em;
    color: #d02929;
    text-decoration: none;
    display: inline-block;
    vertical-align: top;
    padding: 14px 0 12px 0; /* Slight adjustment: 14px top, 12px bottom */
}

.view-all-methods:hover {
    text-decoration: underline;
}

.method-tab:hover {
    background-color: #f0f0f0;
    color: #333;
    text-decoration: none;
    transform: translateY(-1px);
}

.method-tab.active {
    background-color: #fff;
    color: #000;
    font-weight: 600;
    border-bottom: 2px solid #fff;
    top: 2px;
}

/* Responsive tabs for mobile */
@media (max-width: 768px) {
    .method-tabs {
        flex-direction: column;
        gap: 1px;
    }

    .method-tab {
        border-radius: 10px;
        border-bottom: 2px solid #333;
        top: 0;
        margin-bottom: 2px;
    }

    .method-tab.active {
        border-bottom: 2px solid #333;
    }
}

/* UX Step 5: Interactive Tabbed View - Compact Toggle */
.view-mode-toggle {
    float: right;
    margin: 0;
    padding: 0.3em 0.6em;
    font-size: 0.85em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3em;
    position: relative;
    top: -3.5em;
}

.toggle-label {
    font-weight: 400;
    color: #666;
    white-space: nowrap;
    font-size: 0.8em;
    text-transform: lowercase;
}

/* Toggle switch styling */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 24px;
    cursor: pointer;
}

.view-mode-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 24px;
    border: 1px solid #999;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
    border: 1px solid #ddd;
}

.toggle-text {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 1px rgba(0,0,0,0.3);
    pointer-events: none;
}

.toggle-text.off {
    left: 6px;
    opacity: 0; /* Hide OFF text */
}

.toggle-text.on {
    right: 6px;
    opacity: 0; /* Hide ON text */
}

/* Checked state - using child selector for tab-controls structure */
#tabbed-mode:checked ~ .view-mode-toggle-tabs .toggle-slider {
    background-color: #666;
}

#tabbed-mode:checked ~ .view-mode-toggle-tabs .toggle-slider:before {
    transform: translateX(36px);
}

#tabbed-mode:checked ~ .view-mode-toggle-tabs .toggle-text.off {
    opacity: 0; /* Keep OFF text hidden */
}

#tabbed-mode:checked ~ .view-mode-toggle-tabs .toggle-text.on {
    opacity: 0; /* Keep ON text hidden */
}

/* Default: Long-form view (all sections visible) */
.results-container {
    /* Default state: show all content */
}

/* Hide tabs in long-form view - handled by JavaScript since DOM structure makes CSS selectors complex */
.method-tabs.hidden-tabs {
    display: none !important;
}

/* Tabbed mode: hide all sections except the one corresponding to active tab */
.results-container.tabbed-mode > * {
    display: none;
}

.results-container.tabbed-mode .method-section.visible {
    display: block;
}

/* Ensure proper spacing in tabbed mode */
.results-container.tabbed-mode {
    min-height: 300px;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 1em;
    margin-top: 0;
}

/* Print styles: always show long-form for printing */
@media print {
    .view-mode-toggle {
        display: none;
    }

    .results-container .method-content {
        display: block !important;
    }
}

/* Pairwise table styling */
.pairwise-table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
    font-size: inherit; /* Use default page font size */
}

.pairwise-table th, .pairwise-table td {
    border: 1px solid #ccc;
    padding: 6px 8px;
}

.pairwise-table th {
    background-color: #f5f5f5;
    color: black;
    min-width: 10em;
    text-align: left;
    vertical-align: top;
    word-wrap: break-word;
    font-weight: normal;
}

.pairwise-table caption {
    caption-side: top;
    text-align: center;
    font-weight: bold;
    padding: 0.5em;
    background-color: rgb(208, 41, 41);
    color: white;
    border: 1px solid rgb(208, 41, 41);
}

.wlt-score {
    display: block;
    text-align: right;
    font-size: 0.85em;
    margin-top: 0.2em;
    font-weight: normal;
}

.matchup-cell-inner {
    display: flex;
    flex-direction: column;
    min-height: 2.5em;
}

.matchup-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0.1em 0;
}

.cand-name {
    text-align: left;
    margin-right: 0.5em;
    flex: 1;
    word-wrap: break-word;
    overflow-wrap: break-word;
    font-weight: 500;
}

.cand-score {
    text-align: right;
    font-weight: normal;
    white-space: nowrap;
}

.score-percentage {
    font-size: 0.85em;
    color: #666;
    margin-left: 4px;
}

.pseudo-header {
    background-color: #f5f5f5;
    font-style: italic;
    text-align: center;
    vertical-align: bottom;
}

.colorblock {
    display: inline-block;
    width: 1em; /* Use default em sizing for consistency */
    height: 1em;
    border: 1px solid #000;
    vertical-align: middle;
    margin-right: 4px;
}

/* STAR Voting Display Styles */
.flex-container {
    display: flex;
    align-items: flex-start;
}

.container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    margin: 5px;
    text-align: center;
}

.star-caption {
    text-align: center;
    margin-top: 12px;
    font-size: 0.8em;
    font-style: italic;
    width: 200px;
}

.stars {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    width: 200px;
}

.r6star {
    width: 198px;
}

.r5star { /* 5 stars */
    width: 165px;
}

.star {
    font-size: 27px;
    line-height: 1;
    margin: 0 1px;
    -webkit-text-stroke: 1px #444;
    text-stroke: 1px #444;
    color: grey;
}

/* Tag Browser Styling */
.tag-browser {
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 20px;
}

.tag-browser h2 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 1.3em;
}

.tag-browser p {
    margin: 0;
    line-height: 1.6;
}

/* Featured Elections Styling */
.featured-elections {
    background-color: #fffbf0;
    border: 1px solid #f0c674;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
}

.featured-elections h3 {
    margin: 0 0 10px 0;
    color: #b58900;
}

.featured-list {
    margin: 0;
    padding-left: 20px;
}

.featured-list li {
    margin-bottom: 5px;
}

/* Homepage Action Boxes */
.homepage-actions {
    display: flex;
    gap: 20px;
    margin: 20px 0;
}

.action-box {
    flex: 1;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 20px;
    text-align: center;
}

.action-box h2 {
    margin: 0 0 10px 0;
    font-size: 1.4em;
}

.action-box h2 a {
    color: #d02929;
    text-decoration: none;
}

.action-box h2 a:hover {
    text-decoration: underline;
}

.action-box p {
    margin: 0;
    line-height: 1.5;
    color: #666;
}

/* ============= Election overview layout ============= */

.election-overview {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 2em;
  margin-bottom: 2em;
}

.summary-section {
  min-width: 0; /* Prevent grid overflow */
}

.preview-sidebar {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.election-preview {
  margin: 0;
  text-align: center;
}

.preview-image {
  max-width: 100%;
  height: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.preview-caption {
  margin-top: 0.5em;
  font-size: 0.85em;
  color: #666;
  line-height: 1.3;
}

/* Tab controls positioned above tabs */
.tab-controls {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1em;
  margin-top: 1em;
}

.view-mode-toggle-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
}

/* Image modal styles */
.image-modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.8);
  cursor: pointer;
  /* Center modal content while letting backdrop receive clicks */
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  /* Avoid covering the full overlay so backdrop clicks target the overlay */
  height: auto;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2vh;
  cursor: default;
}

.image-modal img {
  max-width: 90%;
  max-height: 75vh;
  border-radius: 4px;
  margin-bottom: 1em;
}

.modal-caption {
  color: white;
  font-size: 1.1em;
  line-height: 1.4;
  text-align: center;
  max-width: 80%;
  margin: 0;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

.modal-header {
  position: sticky;
  top: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1em;
  padding-top: 4px;
  padding-bottom: 4px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.45), rgba(0,0,0,0.25));
  backdrop-filter: blur(1px);
  z-index: 1;
}

.format-switcher {
  display: flex;
  gap: 2px;
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  padding: 2px;
}

.format-btn {
  padding: 4px 8px;
  background: none;
  border: none;
  color: #ccc;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.2s ease;
}

.format-btn.active {
  background: rgba(255,255,255,0.2);
  color: white;
}

.format-btn:hover:not(.active) {
  background: rgba(255,255,255,0.1);
  color: white;
}

.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  z-index: 1001;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

/* Within the modal header, keep the close button aligned without absolute positioning */
.modal-header .modal-close {
  position: static;
  margin-left: auto;
  padding: 0 6px;
  font-size: 32px;
  line-height: 1;
}

.modal-close:hover {
  color: #ccc;
}

.modal-instructions {
  color: #ccc;
  font-size: 0.9em;
  margin: 0.5em 0 0 0;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

/* Responsive design for small screens */
@media (max-width: 768px) {
    .election-overview {
        grid-template-columns: 1fr;
    }

    .preview-sidebar {
        order: -1; /* Show preview above summary on mobile */
        margin-bottom: 1em;
    }
    .homepage-actions {
        flex-direction: column;
        gap: 15px;
    }
}

/* Footnote styling for pairwise tables */
.footnote {
    font-size: 0.8em;
    color: #666;
    margin-top: 0.5em;
    font-style: italic;
    line-height: 1.3;
}
