/*
  ==============================
  Monster Maker – Modern Design
  ==============================
  A lightweight design system with CSS variables, reset, and
  cohesive component styles. Dark theme by default.
*/

/* Fonts */
@font-face {
    font-family: "JetBrains Sans";
    src: url("fonts/JetBrainsSans-Regular.woff2");
    font-display: swap;
}

@font-face {
    font-family: "JetBrains Mono";
    src: url("fonts/JetBrainsMono-Regular.woff2");
    font-display: swap;
}

/* Design Tokens */
:root {
    /* Colors */
    --bg: #0e0f12;
    --panel: #14161b;
    --elev: #1a1d23;
    --text: #e9edf1;
    --muted: #aeb6c2;
    --subtle: #7c8796;
    --primary: #6ea8fe;
    --primary-600: #508ffc;
    --border: #2a2f38;
    --success: #4ad97b;
    --danger: #ff6b6b;
    --warning: #ffd166;

    /* Effects */
    --shadow-1: 0 4px 18px rgba(0, 0, 0, 0.35);
    --ring: 0 0 0 3px rgba(110, 168, 254, 0.3);

    /* Radii */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;

    /* Spacing */
    --g-1: 4px;
    --g-2: 8px;
    --g-3: 12px;
    --g-4: 16px;
    --g-5: 20px;
    --g-6: 24px;
    --g-8: 32px;

    /* Typography */
    --font-sans: "JetBrains Sans", Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    --fs-xs: 12px;
    --fs-sm: 14px;
    --fs-md: 16px;
    --fs-lg: 20px;
    --fs-xl: 28px;
}

/* Reset + base */
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

html {
    color-scheme: dark;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    color: var(--text);
    background: radial-gradient(1000px 600px at 80% -10%, rgba(110, 168, 254, 0.15), transparent 60%), var(--bg);
    /* Allow document-level scroll (managed by SimpleBar wrapper) */
    overflow: auto;
}

/* App root should occupy the full viewport and manage internal scrolling */
#root {
    /* Lock app to viewport height so the document itself doesn't scroll */
    height: 100vh;
    display: flex;
    flex-direction: column;
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Header */
.app-header {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    padding: var(--g-6) var(--g-4) var(--g-3);
    /* Make header stick to the top in case any outer scroll appears */
    position: sticky;
    top: 0;
    z-index: 50;
    /* Fix transparency so content below doesn't bleed through while scrolling */
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    /* Ensure visual separation from content to avoid collision at scroll 0 */
    margin-bottom: var(--g-5);
}

.title {
    font-size: var(--fs-xl);
    font-weight: 600;
    letter-spacing: .2px;
    margin: 0 0 var(--g-3);
}

.hint {
    color: var(--subtle);
    font-size: var(--fs-sm);
    margin: var(--g-2) 0 0;
    text-align: center;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 180px 160px;
    gap: var(--g-3);
    align-items: center;
}

/* Inputs */
input[type="text"], select, button {
    font: inherit;
    color: var(--text);
}

input[type="text"], select {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 12px;
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

input[type="text"]::placeholder {
    color: var(--subtle);
}

input[type="text"]:focus, select:focus {
    border-color: var(--primary);
    box-shadow: var(--ring);
}

/* Layout */
.app {
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    padding: 0 var(--g-4) var(--g-8);
    /* Make main area fill the remaining space under header and prevent page scrolling */
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0; /* allow children to shrink for overflow */
    /* let content grow; scrolling handled by top-level SimpleBar */
    overflow: visible;
}

.results {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--g-4);
    box-shadow: var(--shadow-1);
    /* Content flows normally; overall page scroll handled by SimpleBar */
    flex: 1 1 auto;
    min-height: 0;
    overflow: visible;
}

.results h2 {
    font-size: var(--fs-lg);
    margin: 0 0 var(--g-3);
    font-weight: 600;
}

.empty {
    color: var(--muted);
}

/* Single-line results list */
.results-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: var(--g-2);
}

.result-item {
    margin: 0;
}

.result-row {
    width: 100%;
    display: grid;
    grid-template-columns: 160px 1fr auto;
    gap: var(--g-3);
    align-items: center;
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: inherit;
    text-align: left;
    transition: border-color .15s ease, transform .04s ease;
}

.result-row:hover {
    border-color: var(--primary-600);
}

.result-row:active {
    transform: translateY(1px);
}

.result-row:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.result-type {
    justify-self: start;
    font-size: var(--fs-sm);
    color: var(--text);
    background: linear-gradient(180deg, rgba(110, 168, 254, 0.25), rgba(110, 168, 254, 0.15));
    border: 1px solid rgba(110, 168, 254, 0.35);
    border-radius: 999px;
    padding: 4px 10px;
    text-transform: none;
}

.result-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.result-subtitle {
    opacity: 0.95;
    color: var(--muted);
}

/* Overflow helper for long subtitles */
.result-subtitle-wrap {
    display: inline-flex;
    align-items: center;
    gap: var(--g-2);
    max-width: 100%;
}

.result-subtitle-text {
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    display: inline-block;
}

.help-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    min-width: 18px;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--elev);
    color: var(--text);
    font-size: 12px;
    line-height: 1;
    font-weight: 700;
    opacity: .8;
}

.help-icon:hover {
    opacity: 1;
    border-color: var(--primary);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(9, 10, 12, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal.open {
    display: flex;
}

.modal .modal-content {
    max-width: 720px;
    width: calc(100% - 32px);
    background: var(--elev);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--g-5);
    text-align: left;
    position: relative;
    box-shadow: var(--shadow-1);
}

.modal .close {
    position: absolute;
    top: 10px;
    right: 12px;
    font-size: 22px;
    line-height: 1;
    background: transparent;
    border: 1px solid transparent;
    color: var(--subtle);
    padding: 2px 6px;
    border-radius: var(--r-sm);
}

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

.card-body {
    display: grid;
    gap: var(--g-3);
    margin-top: var(--g-2);
    /* Two-column layout when image is present; content spans both when alone */
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
}

/* If there's only content (no image column), let it span both columns */
.card-body > .card-content:only-child {
    grid-column: 1 / -1;
}

/* Left-side media container for card images */
.card-media {
    min-width: 0;
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--elev);
}

/* Right-side content column */
.card-content {
    min-width: 0;
}

/* Remove extra top margin on titles inside content */
.card-content #cardTitle,
.card-title {
    margin-top: 0;
}

.card-row {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: var(--g-3);
    /* Center the label vertically relative to multi-line text */
    align-items: center;
}

/* Increase vertical spacing between details rows */
.card-content .card-row + .card-row {
    margin-top: var(--g-2);
}

.card-label {
    font-weight: 600;
    color: var(--text);
}

.card-text {
    color: var(--muted);
}

.translatable {
    cursor: help;
}

/* Hover highlight for interactive translations */
.translatable.hovered {
    background: rgba(255, 235, 59, 0.25);
    border-radius: 4px;
}

.translatable-wrap {
    position: relative;
    display: inline-block;
}

.tip {
    position: absolute;
    background: var(--elev);
    border: 1px solid var(--border);
    padding: 6px 8px;
    border-radius: var(--r-sm);
    display: none;
    box-shadow: var(--shadow-1);
    color: var(--text);
    z-index: 100;
    /* Prevent overly narrow tooltips and improve readability */
    /* Width adapts to content; cap overly wide tooltips */
    /* max-width: min(420px, calc(100vw - 32px)); */
    white-space: normal;
}

.tip.show {
    display: block;
    font-size: 28px;
}

/* Catalog (if used elsewhere) */
.catalog {
    display: none;
}

.tree {
    font-family: var(--font-mono);
}

/* Result list thumbnail icon */
.result-icon {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--elev);
    box-shadow: 1px 1px 4px 0 #000;
    margin: 4px 8px 4px 4px;
    display: inline-block;
    flex: 0 0 auto;
    vertical-align: middle;
}

.result-icon > img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    display: block;
}

/* Generic card image (fills its container) */
.card-image {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

/* Monster Eater avatar ring */
.monster-img {
    display: block;
    margin: 0;
    border-radius: 50%;
    border: #343E78 solid .5em;
    background-color: var(--elev);
    line-height: 1;
    overflow: hidden;
}

.monster-img span {
    display: block;
    margin: 0;
    padding: 0;
    border-radius: 50%;
    border: #BE9637 solid .4em;
    background: url("/img/モンスターイーター/モンスター/texture.png") no-repeat center center;
    background-size: cover;
    overflow: hidden;
    line-height: 1;
}

.monster-img img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.tree-root, .tree-root ul {
    list-style: none;
    margin: 0;
    padding-left: var(--g-3);
}

.tree-item {
    display: inline-block;
    padding: 6px 8px;
    margin: 2px 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: inherit;
}

.tree-item:hover {
    border-color: var(--primary-600);
}

/* Responsive */
@media (max-width: 900px) {
    .controls {
        grid-template-columns: 1fr 1fr;
    }

    /* Make search input occupy the first row alone */
    .controls input[type="text"] {
        grid-column: 1 / -1;
    }

    /* Both selects should share the second row side-by-side */
    .controls select {
        grid-column: auto;
    }

    .result-row {
        grid-template-columns: 120px 1fr;
    }

    .card-row {
        grid-template-columns: 120px 1fr;
    }
}

/* Motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}
