/* ------------------------------------------------------------------
     01. Variables
------------------------------------------------------------------- */

:root {
    --accent: #05f;
    --accent-hover: #09f;
    --ok: #080;
    --danger: #c00;
    --muted: #0002;
    --border: #ccc;
    --font-tiny: 0.7rem;
    --font-small: 0.9rem;
    --font-normal: 1rem;
    --font-large: 1.2rem;
    --radius-small: 0.3rem;
    --radius-large: 0.5rem;
    --gap-quarter: 0.25rem;
    --gap-half: 0.5rem;
    --gap-full: 1rem;
    --gap-extrawide: 1.5rem;
}

/* ------------------------------------------------------------------
     02. Base elements
------------------------------------------------------------------- */

html {
  scrollbar-gutter: stable;
}

body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
}

h1 {
	font-size: 2rem;
}

h2 {
	font-size: var(--font-large);
}

h3 {
	font-size: var(--font-large);
}

h4 {
	font-size: var(--font-normal);
}

a {
    color: inherit;
    text-decoration: none;
}

hr {
    margin: 1rem 0;
    background: var(--muted);
    border: 0;
    height: 3px;
}

fieldset {
    border: 1px solid var(--border);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

legend {
    font-weight: bold;
}

button {
    border: 0;
    cursor: pointer;
    border-radius: var(--radius-small);
    font-size: var(--font-small);
    font-weight: bold;
    transition: 0.2s;
}

input {
    border-radius: var(--radius-small);
    border: 1px solid var(--border);
    padding: var(--gap-quarter);
    font-size: var(--font-tiny);
	box-sizing: border-box;
}

/* colour picker */
input[type="color"] {
    padding: 0;
    border: 0;
    border-radius: 0;
    width: 2rem;
    height: 2rem;
}

/* ------------------------------------------------------------------
     03. a) Layout: global containers and menu
------------------------------------------------------------------- */

.container {
    padding: 2rem;
    margin: auto;
    max-width: 1000px;
}

#menu {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.title-badge {
    font-weight: bold;
    border-bottom: 3px solid;
    padding: 0.1rem 0;
    font-size: 1.3rem;
    border-top: 3px solid;
}


/* ------------------------------------------------------------------
     03. b) Layout: Info page
------------------------------------------------------------------- */
.info-list li {
	margin-bottom: var(--gap-full);
	
}

.info-table td {
	padding: 0.3rem 1rem;
}

.info-table td:last-of-type {
	font-size: var(--font-tiny);
}

/* ------------------------------------------------------------------
     04. Key / filter UI (categories, characters, states)
------------------------------------------------------------------- */

.description-container {
    display: flex;
    align-items: center;
}

.state-grid .description-container {
	display: block;
	text-align: center;
}

.description {
    display: flex;
    min-height: 1.5rem;
    align-items: center;
    margin-left: var(--gap-half);
}

.state-grid .description {
    justify-content: center;
    margin-top: var(--gap-quarter);
	font-size: var(--font-tiny);
	margin-left: 0;
}

details {
    margin-bottom: 1rem;
    box-shadow: 0 2px var(--gap-half) var(--muted);
    overflow: hidden;
}

details:last-of-type,
.state-list .state-item:last-of-type,
.character-state:last-of-type {
    margin-bottom: 0;
}

.cat-list > details {
    border: 2px solid var(--category-bg);
}

details.character {
    margin: 1rem;
}

summary {
    cursor: pointer;
    outline: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

summary::-webkit-details-marker {
    display: none;
}

.category {
    background: var(--category-bg, #bcc);
    padding: var(--gap-half) 0.7rem;
}

summary.character {
    padding: var(--gap-quarter) var(--gap-half);
    box-shadow: 0 2px 4px #eee;
}

.summary-container {
    padding: 0.8rem;
}

summary h3,
summary h4 {
    margin: 0;
    display: flex;
}

.badge,
.pool {
    font-size: var(--font-tiny);
    width: 1rem;
    height: 1rem;
    text-align: center;
    line-height: 1rem;
}

.badge {
    margin-top: -0.2rem;
}

.badge.\30 {
    background: #d00;
    color: #fff;
}

.pool {
    margin: 0 var(--gap-quarter);
    color: #f30;
}

.pad {
    padding-left: var(--gap-half);
}

.pad,
.labels {
    display: flex;
    flex-wrap: wrap;
}

.characters {
    flex: 1 1 35%;
    padding: 1em;
}

.character-state {
    cursor: pointer;
}

.counter {
    font-weight: bold;
    line-height: 0.5;
}

.counter .excluded {
    margin-left: var(--gap-half);
}

.counter .excluded-icon {
    font-weight: normal;
}

summary.active {
    background: #ff0;
}

/* filter header */
.filter-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#resetBtn {
    background: #4ef;
    border: 0;
    padding: var(--gap-half) var(--gap-full);
    font-weight: bold;
    font-size: var(--font-normal);
    border-radius: var(--radius-large);
    margin-left: 1rem;
}

/* ------------------------------------------------------------------
     05. Admin tree / editor
------------------------------------------------------------------- */

.row-title {
    display: flex;
    align-items: center;
}

.drag,
.handle {
    touch-action: none;
}

.handle {
    cursor: grab;
    font-size: 1.3rem;
    display: flex;
    height: 1.5rem;
    justify-content: center;
    align-items: center;
    line-height: 0;
    color: #0003;
    margin-right: var(--gap-half);
}

.handle:active {
    cursor: grabbing;
}

img.handle {
    margin-right: 0;
}

.images-toggle {
    margin-right: var(--gap-half);
    align-items: center;
}

.images-checkbox-label {
    margin-right: var(--gap-quarter);
	font-size: var(--font-tiny);
}

.add-new {
    margin-top: 1rem;
}

summary form.ajax.form,
.add-new form {
    display: flex;
    flex-direction: row;
    align-items: center;
}

.add-new input {
    margin-right: var(--gap-half);
}

.add-new input[name="name"] {
    width: 100%;
}

.add-new.category input,
.add-new.character input {
    /* reserved for future overrides */
}

.state-buttons {
    display: flex;
    justify-content: space-between;
}

summary .save,
.state-list .save {
    margin: 0 var(--gap-half);
}

/* list view - no images */
.state-list input[name="name"] {
    width: 100%;
}

.state-list .state-item {
    margin-bottom: var(--gap-half);
}

.state-list .state-item,
.state-list .state-item form {
    display: flex;
    flex-direction: row;
    width: 100%;
    align-items: center;
}

/* grid view - images */
.state-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
	justify-content: space-evenly;
	gap: var(--gap-half);
}

.state-grid .state-item {
	flex: calc(20% - var(--gap-half));
    max-width: 25%;
}

.state-grid input {
    margin-bottom: var(--gap-half);
}

#page-admin .state-grid .handle {  
	position: absolute;
	width: 1rem;
	bottom: 0rem;
	left: 50%;
}

.cat-list .state-grid img {
    width: 100%;
    margin: auto;
}

.state-grid .form {
    display: flex;
    flex-direction: column;
}

.state-grid .state-item {
    display: flex;
    flex-direction: column;
	overflow: hidden;
	position: relative;
}

.thumb {
    max-width: 100%;
}

.add-new.character input {
    order: 1;
}

.add-new.character .images-toggle {
    order: 2;
    margin: 0 1rem;
}

.add-new.character button {
    order: 3;
}

/* site customisation bar */
#site-customisation {
    display: flex;
    align-items: center;
}

#site-customisation label {
    margin-right: 1rem;
    display: flex;
    align-items: center;
}

#site-customisation label .label {
    margin-right: var(--gap-half);
}

/* ------------------------------------------------------------------
     06. Buttons (variants)
------------------------------------------------------------------- */

.save,
.delete,
.add {
    padding: 0.2em 0.4em;
}

.save {
    background: #00880033;
    color: var(--ok);
}

.save:hover {
    background: var(--ok);
    color: #fff;
}

.delete {
    background: transparent;
    padding: 0;
    margin: 0;
    color: var(--danger);
    font-size: var(--font-tiny);
}

.add {
    background: var(--accent);
    color: #fff;
}

.add:hover {
    background: var(--accent-hover);
}

/* add/edit bar */
.add-edit {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
}

/* ------------------------------------------------------------------
     07. Include / exclude toggles
------------------------------------------------------------------- */

/* hide native checkbox but keep it functional */
.state-checkbox {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* base icon style (tick + exclude) */
.tick-icon,
.exclude-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    font-size: 1.2rem;
    font-weight: normal;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

.tick-icon::before {
    content: '✔';
}

.exclude-toggle::before {
    content: '🛇';
}

.state-item .tick-icon,
.state-item .exclude-toggle {
    color: #ddd;
}

.state-item .tick-icon:hover {
    color: #0a05;
}
.state-item.is-included .tick-icon {
    color: #0a0;
}

.state-item.is-excluded .exclude-toggle,
.state-item .exclude-toggle:hover {
    color: var(--danger);
}

.lock-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1.5rem;
    background: transparent;
    border: 0;
    cursor: pointer;
    padding: 0;
    color: #ddd;
    transition: opacity 0.15s ease;
}

.lock-toggle svg {
    width: 1rem;
    height: 0.9rem;
    fill: currentColor;
}

.lock-toggle .icon-closed {
    display: none;
}

.state-item.is-locked .lock-toggle {
    color: #000;
}

.state-item.is-locked .lock-toggle .icon-open {
    display: none;
}

.state-item.is-locked .lock-toggle .icon-closed {
    display: block;
}
/* ------------------------------------------------------------------
     08. Matches / editor gallery
------------------------------------------------------------------- */

#editor-gallery {
    display: flex;
    justify-content: flex-start;
}

#matches {
    overflow: auto;
}

#editor-gallery img {
    object-fit: cover;
    display: block;
}

#editor-gallery .controls {
    margin-top: var(--gap-half);
}

#editor-gallery .controls input {
    width: 100%;
}

#editor-gallery .state-item {
    width: unset;
    max-width: unset;
    flex: 25% 0 0;
}

.cat-list .state-item img {
    width: 100%;
    display: block;
}

/* ------------------------------------------------------------------
     09. Species cards and grids
------------------------------------------------------------------- */

.sp-card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
	gap:1rem;
}

.sp-card {
    cursor: pointer;
	min-width: 100%;
}

.sp-card .thumb {
    width: 100%;
    background: #f2f2f2;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.sp-card .thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sp-card .thumb .noimg {
    width: 100%;
    height: 100%;
}

.sp-card .label {
    line-height: 0.9;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    margin-top: var(--gap-quarter);
    font-size: var(--font-small);
}

#matches .sp-card .label {
    font-size: var(--font-tiny);
}

#matches .sp-card .label .name {
    width: 0;
}

/* ------------------------------------------------------------------
     10. Modal (gallery)
------------------------------------------------------------------- */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
}

.modal[hidden] {
    display: none;
}

.modal-inner {
    background: #fff;
    max-width: 900px;
    width: 100%;
    overflow: auto;
    border-radius: var(--radius-large);
    padding: 1rem;
    position: relative;
}

.modal-top {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: calc(0rem - var(--gap-half));
	margin-bottom: var(--gap-quarter);
}

.modal-title {
	font-weight: bold;
}

.modal-close {
    font-size: var(--font-large);
    background: none;
    cursor: pointer;
}

.gallery-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.gal-item img {
    width: 100%;
    height: auto;
    display: block;
}

.gal-item .cap {
    font-size: var(--font-small);
    color: #444;
}

/* ------------------------------------------------------------------
     11. Responsive - Mobile
------------------------------------------------------------------- */

@media screen and (max-width: 600px) {
    body {
        font-size: var(--font-small);
    }

    .container {
        padding: 1rem;
    }

    .identify-container {
        display: block;
    }

    .identify-form,
    #matches-container {
        width: 100%;
    }

    .identify-form {
        margin-bottom: calc(25vh + 3rem);
    }

    details {
        margin-bottom: var(--gap-half);
    }

    details,
    summary.character {
        box-shadow: none;
    }

    .summary-container {
        padding: var(--gap-half) 0;
    }

    .summary-container.char-list {
        padding: var(--gap-half);
    }

    .character {
        background: #f3f3f3;
    }

    #editor-gallery .state-item img {
        width: 20rem;
        height: auto;
    }

    summary.category,
    summary.character {
        padding: var(--gap-quarter);
        margin: 0;
    }

    summary input[name="name"] {
        width: 7rem;
    }
	
	#page-list_species .sp-card-grid {
		grid-template-columns: repeat(2, 1fr);
		gap: var(--gap-full);
	}
	#page-list_species .sp-card .thumb {
		aspect-ratio: 3/1;
	}

    #matches-container {
        border-top: 2px solid #ddd;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 2;
        background: #fff;
        width: calc(100% - 2rem);
        padding: 0 1rem;
    }

    #matches {
		padding-bottom: var(--gap-half);
		display: flex;
		justify-content: flex-start;
	}
    
    #matches .sp-card .thumb {
		aspect-ratio: 1/1;
    }

    #matches .sp-card {
        padding: 0;
        margin: 0 1rem 0 0;
        min-width: 8rem;
    }

    button,
    #resetBtn {
        font-size: var(--font-normal);
        padding: var(--gap-quarter) var(--gap-half);
    }

    input[name="name"],
    input[name="image"] {
        font-size: var(--font-small);
        height: 1.4rem;
    }
	
    input[type="checkbox"] {
        zoom: 1.5;
        margin: 0;
    }

    .add-new {
        margin: var(--gap-half) 0;
        padding: var(--gap-quarter);
    }

    #keyForm .state-grid .state-item {
        text-align: center;
    }

    .admin-tree .state-grid .state-item {
        max-width: 25rem;
    }

    .modal-inner {
        max-height: 62vh;
    }
}


/* ------------------------------------------------------------------
     12. Responsive - Tablet
------------------------------------------------------------------- */

@media screen and (min-width: 600px) and (max-width: 900px) {
    .identify-form {
		width: 70%;
	}
    #matches-container {
        width: 30%;
    }
	#matches { 
		grid-template-columns: repeat(1, 1fr);
	}
	.state-grid .state-item {
		flex: 25%;
	}
	
}

/* ------------------------------------------------------------------
     13. Responsive - Desktop
------------------------------------------------------------------- */

@media screen and (min-width: 900px) {

    .identify-form,
    #matches-container {
        width: 50%;
    }
	#matches { 
		grid-template-columns: repeat(2, 1fr);
	}
}

/* ------------------------------------------------------------------
     14. Responsive - Tablet to Desktop
------------------------------------------------------------------- */

@media screen and (min-width: 600px) {
    .identify-container {
        display: flex;
    }

    .add-new input[name="name"] {
        max-width: 20rem;
    }
    
    
    .sp-card .thumb {
	aspect-ratio: 3/2;
    }
	.sp-card .thumb img {
		object-position: bottom;
	}

    #editor-gallery .state-item:first-of-type img {
        width: 100%;
        height: auto;
    }
	
	#page-list_species #species-list {
		gap: var(--gap-full) var(--gap-extrawide);
	}

    #matches-container {
        margin-left: 1rem;
    }
	
	#matches-container h2 {
		margin-top: 0;
	}

    #matches {
        max-height: 70vh;
        display: grid;
		gap: var(--gap-full);
		padding-right: var(--gap-full);
    }
}
