:root {
    --brand-green: #00a96b;
    --brand-green-dark: #008f5b;
    --text-dark: #171a1b;
    --text-mid: #2f3437;
    --surface: #ececec;
    --surface-soft: #e4e4e4;
    --card: #f5f5f5;
    --border: #cfd3d1;
    --danger: #8f2424;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Poppins", "Avenir Next", "Segoe UI", sans-serif;
    color: var(--text-mid);
    background: radial-gradient(circle at top right, #f4f4f4, #e8e8e8 60%);
}

.topbar {
    background: var(--brand-green);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 1rem 1.4rem;
    gap: 1rem;
    flex-wrap: wrap;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

.logo-text {
    margin: 0;
    text-transform: lowercase;
    line-height: 0.8;
    font-size: 2rem;
    font-weight: 700;
}

.logo-sub {
    margin: 0.35rem 0 0;
    font-size: 0.9rem;
    opacity: 0.95;
}

.nav-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.nav-links a {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
}

.nav-links a:hover {
    text-decoration: underline;
    text-underline-offset: 4px;
}

.container {
    width: min(1200px, calc(100% - 1.8rem));
    margin: 1.4rem auto 3rem;
}

.hero h1 {
    margin: 0;
    color: var(--text-dark);
    font-size: clamp(2rem, 5vw, 3rem);
}

.hero-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(340px, 1fr);
    grid-template-areas:
        "main main"
        "links disclaimers";
    gap: 0.8rem;
    align-items: start;
}

.hero-main {
    grid-area: main;
    min-width: 0;
}

.hero p {
    font-size: clamp(1rem, 1.8vw, 1.25rem);
    max-width: 78ch;
    line-height: 1.5;
}

.hero-note {
    font-weight: 600;
    color: #145746;
}

.how-strip {
    margin-top: 0.75rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
}

.how-strip-banner {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
}

.how-item {
    background: #fff;
    border: 1px solid #d7dcda;
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    min-height: 72px;
}

.how-icon {
    width: 26px;
    height: 26px;
    border-radius: 999px;
    background: #0a9f64;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.86rem;
    font-weight: 700;
    flex: 0 0 auto;
}

.how-copy {
    min-width: 0;
}

.how-item p {
    margin: 0;
    color: #243335;
}

.how-title {
    font-size: 0.95rem;
    font-weight: 700;
}

.how-desc {
    margin-top: 0.2rem;
    font-size: 0.82rem;
    line-height: 1.3;
}

.hero-helpful-links {
    grid-area: links;
    margin-top: 0;
    background: #ffffff;
    border: 1px solid #d7dcda;
    border-radius: 10px;
    padding: 0.6rem 0.7rem;
}

.hero-helpful-links h2 {
    margin: 0 0 0.3rem;
    font-size: 1.05rem;
    color: var(--text-dark);
}

.helpful-links-list {
    margin: 0;
}

.hero-disclaimer-block {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.hero-disclaimer {
    margin: 0;
    font-size: 1rem;
    line-height: 1.45;
    color: #364546;
}

.hero-disclaimer + .hero-disclaimer {
    margin-top: 0.4rem;
}

.hero-disclaimer-secondary {
    margin-top: 0.85rem;
    padding-top: 0.75rem;
    border-top: 1px solid #d7dcda;
}

.hero-disclaimer-rail {
    grid-area: disclaimers;
    background: #ffffff;
    border: 1px solid #d7dcda;
    border-radius: 10px;
    padding: 0.7rem;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 1.2rem;
    padding: 1.1rem;
}

.success-banner {
    border: 3px solid #7ad04d;
    background: #edf3e8;
}

.success-banner-head {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
}

.success-icon {
    width: 48px;
    height: 48px;
    border-radius: 999px;
    border: 4px solid #09a165;
    color: #09a165;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    line-height: 1;
    font-weight: 700;
    flex: 0 0 auto;
}

.success-banner-head h2 {
    margin: 0;
    color: var(--text-dark);
}

.success-banner-head p {
    margin: 0.25rem 0 0;
}

.success-banner-list {
    margin-top: 0.9rem;
    display: grid;
    gap: 0.7rem;
}

.success-banner-item {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #c9dfbf;
    border-radius: 10px;
    padding: 0.68rem;
}

.sample-top {
    margin: 0;
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
    color: var(--text-dark);
}

.sample-top span {
    color: #3f5450;
}

.sample-time {
    margin: 0.35rem 0;
    color: #0c6548;
    font-weight: 700;
}

.sample-text {
    margin: 0;
    font-size: 0.93rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.mode-toggle {
    display: flex;
    background: #d8e7e0;
    border-radius: 10px;
    padding: 0.2rem;
}

.mode-btn {
    border: none;
    background: transparent;
    padding: 0.45rem 0.8rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.mode-btn.active {
    background: var(--brand-green);
    color: #fff;
}

.builder-layout {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    margin-top: 0.5rem;
}

.builder-workspace {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr);
    gap: 0.8rem;
    align-items: start;
}

.map-stage {
    min-width: 0;
}

#map {
    width: 100%;
    min-height: 620px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.builder-panel {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.builder-controls-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 0.8rem;
}

.control-card {
    background: #f7faf8;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.45rem 0.5rem;
}

.mode-controls-card {
    min-height: 88px;
}

.mode-card-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.mode-card-content {
    flex: 1 1 auto;
    min-width: 0;
}

.mode-card-title {
    margin: 0 0 0.1rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: #1b4f43;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.mode-card-hint {
    margin: 0 0 0.25rem;
    color: #2f4342;
    font-size: 0.86rem;
    line-height: 1.25;
}

.mode-controls-inline {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.mode-controls-inline input {
    max-width: 170px;
    padding: 0.42rem 0.55rem;
}

.mode-illustration {
    flex: 0 0 130px;
    width: 130px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mode-illustration svg {
    width: 100%;
    height: 100%;
}

.mode-svg-outline {
    fill: rgba(0, 169, 107, 0.06);
    stroke: #34c759;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mode-svg-line {
    stroke: #34c759;
    stroke-width: 4;
    stroke-linecap: round;
}

.mode-svg-center {
    fill: #34c759;
    stroke: #1b8f52;
    stroke-width: 1.5;
}

.mode-svg-node {
    fill: #34c759;
    stroke: #1b8f52;
    stroke-width: 1.5;
}

.inline-label {
    margin: 0;
    font-size: 0.82rem;
    white-space: nowrap;
    font-weight: 600;
}

.compact-top-controls {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 0.45rem;
}

.overlay-toggle-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0.2rem;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 0;
    margin: 0;
    line-height: 1.1;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
}

.overlay-source {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.15;
    color: #3f5450;
}

.overlay-source a {
    color: #045f4d;
    font-weight: 600;
}

#builder {
    padding: 0.9rem;
}

#builder .section-header h2 {
    margin: 0;
}

.builder-actions {
    display: flex;
    align-items: flex-end;
    gap: 0.7rem;
    flex-wrap: wrap;
}

.uf101-kml-actions {
    margin-top: 0.9rem;
}

.map-kml-actions {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
}

.builder-actions form {
    margin: 0;
}

.kml-form {
    flex: 1 1 560px;
}

.kml-inline input {
    flex: 1 1 auto;
}

.kml-action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 0.5rem;
}

.kml-action-buttons .primary-btn,
.kml-action-buttons .secondary-btn {
    flex: 1 1 240px;
}

.inline-action {
    display: flex;
    gap: 0.55rem;
    align-items: center;
}

.compact-btn {
    white-space: nowrap;
    padding: 0.58rem 0.75rem;
}

.helper-text {
    margin: 0.45rem 0 0;
    font-size: 0.86rem;
    color: #495c5a;
}

.helper-text.error {
    color: #8f2424;
}

.helper-text.success {
    color: #0f6a50;
}

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

input,
textarea {
    width: 100%;
    padding: 0.62rem 0.72rem;
    border: 1px solid #aab3af;
    border-radius: 8px;
    font: inherit;
    background: #fff;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

.primary-btn,
.secondary-btn {
    border-radius: 8px;
    padding: 0.62rem 0.92rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.primary-btn {
    background: var(--brand-green-dark);
    color: #fff;
    border: 1px solid var(--brand-green-dark);
}

.secondary-btn {
    background: #fff;
    color: var(--text-dark);
    border: 1px solid #5ba88b;
}

.secondary-btn-filled {
    background: #e8f5ef;
    border-color: #74b99e;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75), 0 1px 2px rgba(0, 0, 0, 0.05);
}

.secondary-btn-filled:hover {
    background: #dff0e9;
}

.uf101-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #7f8f9c;
    background: #fff;
}

.live-output-rail {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2.2rem);
    overflow: auto;
}

.live-output-rail h3 {
    margin: 0 0 0.65rem;
    color: var(--text-dark);
}

.live-output-rail .kml-form {
    flex: 1 1 auto;
}

.live-output-rail .builder-actions {
    align-items: stretch;
}

.live-output-rail #print-btn {
    width: 100%;
}

.uf101-table th,
.uf101-table td {
    border: 1px solid #7f8f9c;
    padding: 0.5rem 0.6rem;
    text-align: left;
    font-size: 0.9rem;
    vertical-align: top;
}

.uf101-table thead th {
    background: #9fb7cf;
    color: #101820;
    font-weight: 700;
}

.uf101-table tbody th {
    width: 36%;
    background: #d2dfec;
    color: #1b2832;
    font-weight: 600;
}

.uf101-table tbody td {
    background: #f8fbff;
    color: #1f2f33;
}

.value-block {
    position: relative;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    line-height: 1.35;
    min-height: 1.4rem;
    border-radius: 6px;
    padding: 0.1rem 0.25rem;
}

.copyable-value {
    cursor: copy;
    transition: background-color 0.18s ease;
}

.copyable-value:hover,
.copyable-value:focus-visible {
    background: rgba(15, 106, 80, 0.08);
    outline: none;
}

.copyable-value::after {
    content: "Click to copy";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(22, 28, 31, 0.28);
    color: #fff;
    font-family: "Poppins", "Avenir Next", "Segoe UI", sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.18s ease;
    pointer-events: none;
}

.copyable-value:hover::after,
.copyable-value:focus-visible::after {
    opacity: 1;
}

.copyable-value[data-copy-state="copied"]::after {
    content: "Copied";
    opacity: 1;
    background: rgba(12, 101, 72, 0.65);
}

.copyable-value[data-copy-state="error"]::after {
    content: "Copy failed";
    opacity: 1;
    background: rgba(143, 36, 36, 0.68);
}

.checklist {
    margin: 0;
    padding-left: 1.2rem;
}

.links-list {
    margin: 0;
    padding-left: 1.2rem;
}

.links-list li + li {
    margin-top: 0.4rem;
}

.links-list a {
    color: #045f4d;
    font-weight: 600;
}

.stories-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.story-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
}

.story-card h3 {
    margin: 0;
    color: var(--text-dark);
}

.story-card header p {
    margin: 0.2rem 0 0;
    font-size: 0.9rem;
}

.approval-time {
    margin: 0.7rem 0 0.5rem;
}

.story-form {
    display: grid;
    gap: 0.62rem;
}

.warning {
    margin: 0.6rem 0 0;
    color: var(--danger);
    font-weight: 600;
}

.flash {
    border-radius: 8px;
    margin-bottom: 1rem;
    padding: 0.62rem 0.8rem;
}

.flash.success {
    background: #dff6ec;
    border: 1px solid #9fd6bc;
}

.flash.error {
    background: #fbe8e8;
    border: 1px solid #dca4a4;
}

.flash.error ul {
    margin: 0.5rem 0 0;
    padding-left: 1.2rem;
}

.hidden {
    display: none;
}

.admin-body {
    background: #efefef;
}

.admin-wrap {
    width: min(620px, calc(100% - 1.6rem));
    margin: 2rem auto;
}

.admin-wrap.wide {
    width: min(1100px, calc(100% - 1.6rem));
}

.admin-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
}

.admin-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.8rem;
}

.admin-actions {
    display: flex;
    gap: 0.5rem;
}

.admin-list {
    margin: 0;
    padding-left: 1.1rem;
}

@media (max-width: 960px) {
    .hero-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "main"
            "links"
            "disclaimers";
    }

    .container {
        width: calc(100% - 1rem);
        margin: 0.9rem auto 2rem;
    }

    .card {
        padding: 0.85rem;
        margin-top: 0.85rem;
    }

    .how-strip {
        grid-template-columns: 1fr;
    }

    .section-header {
        align-items: flex-start;
        gap: 0.55rem;
    }

    .mode-toggle {
        align-self: flex-start;
    }

    .builder-controls-row {
        grid-template-columns: 1fr;
    }

    .mode-controls-inline {
        flex-direction: column;
        align-items: stretch;
    }

    .mode-controls-inline input {
        max-width: none;
    }

    .builder-actions {
        align-items: stretch;
    }

    .builder-actions .secondary-btn,
    .builder-actions .primary-btn {
        width: 100%;
    }

    .kml-form {
        flex-basis: auto;
    }

    .kml-action-buttons {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.45rem;
    }

    .kml-action-buttons .primary-btn,
    .kml-action-buttons .secondary-btn {
        flex: initial;
    }

    .mode-illustration {
        flex-basis: 104px;
        width: 104px;
        height: 58px;
    }

    .builder-workspace {
        grid-template-columns: 1fr;
    }

    .live-output-rail {
        position: static;
        max-height: none;
        overflow: visible;
    }

    .inline-action {
        flex-direction: column;
        align-items: stretch;
    }

    .uf101-table {
        table-layout: fixed;
    }

    .uf101-table thead {
        display: table-header-group;
    }

    .uf101-table tbody th {
        width: 36%;
    }

    #map {
        min-height: 440px;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 15px;
    }

    .topbar {
        align-items: flex-start;
        padding: 0.7rem 0.8rem;
        gap: 0.55rem;
    }

    .logo-text {
        font-size: 1.55rem;
    }

    .logo-sub {
        margin-top: 0.2rem;
        font-size: 0.78rem;
    }

    .nav-links {
        width: 100%;
        justify-content: space-between;
        gap: 0.4rem;
    }

    .nav-links a {
        font-size: 0.84rem;
    }

    .hero h1 {
        font-size: 1.65rem;
    }

    .hero p {
        font-size: 0.96rem;
        line-height: 1.4;
    }

    .how-item {
        min-height: 0;
        padding: 0.45rem 0.5rem;
    }

    .how-title {
        font-size: 0.9rem;
    }

    .how-desc {
        font-size: 0.78rem;
    }

    .hero-helpful-links {
        padding: 0.5rem 0.55rem;
    }

    .hero-helpful-links h2 {
        font-size: 0.96rem;
    }

    #builder {
        padding: 0.7rem;
    }

    .builder-layout {
        gap: 0.55rem;
    }

    .builder-panel {
        padding: 0.38rem;
    }

    .control-card {
        padding: 0.38rem 0.42rem;
    }

    .mode-controls-card {
        min-height: 0;
    }

    .mode-card-layout {
        gap: 0.35rem;
    }

    .mode-card-title {
        font-size: 0.76rem;
    }

    .mode-card-hint {
        font-size: 0.82rem;
        margin-bottom: 0.18rem;
    }

    .inline-label {
        font-size: 0.78rem;
    }

    .mode-illustration {
        flex-basis: 78px;
        width: 78px;
        height: 44px;
    }

    .toggle-label {
        font-size: 0.86rem;
    }

    .overlay-source {
        font-size: 0.74rem;
    }

    #map {
        min-height: 350px;
    }

    .map-kml-actions {
        padding: 0.55rem;
    }

    .kml-action-buttons {
        grid-template-columns: 1fr;
    }

    .helper-text {
        font-size: 0.78rem;
    }

    .live-output-rail {
        padding: 0.55rem;
    }

    .live-output-rail h3 {
        margin-bottom: 0.45rem;
        font-size: 1.15rem;
    }

    .uf101-table th,
    .uf101-table td {
        padding: 0.42rem 0.5rem;
        font-size: 0.84rem;
    }
}

@media print {
    @page {
        margin: 12mm;
    }

    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .topbar,
    .hero,
    #how-it-works,
    #official-links,
    .success-banner,
    #success-stories,
    #faq,
    .section-header,
    .builder-panel,
    .map-kml-actions,
    #cork-warning,
    .mode-toggle,
    #kml-form,
    #print-btn,
    .story-form,
    .flash,
    .nav-links {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .container,
    .card {
        width: 100%;
        margin: 0;
        border: none;
        padding: 0;
    }

    .builder-layout {
        margin: 0;
    }

    .builder-workspace {
        display: block;
    }

    .map-stage {
        break-after: page;
        page-break-after: always;
    }

    #map {
        min-height: 680px;
        height: 680px;
        border-radius: 0;
    }

    .leaflet-control-container,
    .zone-overlay-feature {
        display: none !important;
    }

    .live-output-rail {
        position: static;
        top: auto;
        max-height: none;
        overflow: visible;
        break-before: page;
        page-break-before: always;
        border: 1px solid #7f8f9c;
        border-radius: 0;
        padding: 0;
    }

    .copyable-value::after {
        display: none !important;
    }
}
