@font-face {
    font-family: "GGMedium";
    src: url("../fonts/GG_Medium.otf") format("opentype");
    font-display: swap;
}

@font-face {
    font-family: "GGBold";
    src: url("../fonts/GG_Bold.otf") format("opentype");
    font-display: swap;
}

:root {
    --ink: #12343d;
    --muted: #64767d;
    --line: #d8e2e1;
    --paper: #ffffff;
    --canvas: #eef4f2;
    --accent: #0e5964;
    --accent-soft: #d8eee9;
    --coral: #ee735f;
    --danger: #b83a3a;
    --shadow: 0 18px 50px rgba(18, 52, 61, 0.12);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        linear-gradient(rgba(14, 89, 100, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(14, 89, 100, 0.035) 1px, transparent 1px),
        #f5f8f7;
    background-size: 24px 24px;
    font-family: "GGMedium", "Trebuchet MS", sans-serif;
}

button,
input,
select,
textarea { font: inherit; }

button,
label[for] { -webkit-tap-highlight-color: transparent; }

button { color: inherit; }

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.topbar {
    position: sticky;
    z-index: 100;
    top: 0;
    min-height: 76px;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    color: var(--ink);
    text-decoration: none;
}

.brand img {
    width: 115px;
    max-height: 48px;
    object-fit: contain;
}

.brand span { display: grid; }
.brand small,
.panel-heading small,
.workspace-heading small,
.selected-element-heading small {
    color: var(--muted);
    font-family: "GGBold", sans-serif;
    font-size: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.brand strong { font-family: "GGBold", sans-serif; font-size: 18px; }

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 9px;
}

.save-state {
    margin-right: 5px;
    color: var(--muted);
    font-size: 12px;
}

.save-state::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 7px;
    border-radius: 50%;
    background: #4fbf79;
    box-shadow: 0 0 0 4px rgba(79, 191, 121, 0.12);
}

.button {
    min-height: 40px;
    padding: 9px 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    font-family: "GGBold", sans-serif;
    font-size: 13px;
    text-decoration: none;
    transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.button:hover { transform: translateY(-1px); }
.button:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(14, 89, 100, 0.22);
    outline-offset: 2px;
}

.button-primary {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 8px 18px rgba(14, 89, 100, 0.18);
}

.button-secondary { border-color: var(--line); background: #fff; }
.button-quiet { color: var(--muted); background: transparent; }
.button-danger { color: var(--danger); border-color: #efd1d1; background: #fff7f7; }
.button-small { min-height: 34px; padding: 7px 10px; font-size: 12px; }
.file-button { cursor: pointer; }

.app-shell {
    width: 100%;
    min-height: calc(100vh - 76px);
    padding: 18px;
    display: grid;
    grid-template-columns: minmax(250px, 290px) minmax(430px, 1fr) minmax(250px, 300px);
    gap: 18px;
}

.panel,
.workspace {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 10px 30px rgba(18, 52, 61, 0.06);
}

.panel {
    padding: 18px;
    align-self: start;
}

.panel-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.panel-heading h1,
.panel-heading h2,
.workspace-heading h2 {
    margin: 2px 0 0;
    font-family: "GGBold", sans-serif;
    font-size: 21px;
}

.step-number {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--accent);
    border-radius: 12px 12px 4px 12px;
    font-family: "GGBold", sans-serif;
    font-size: 12px;
}

.tool-section,
.property-group,
.export-options {
    padding: 18px 0;
    border-bottom: 1px solid var(--line);
}

.tool-section:last-child,
.property-group:last-child { border-bottom: 0; }

.tool-section h2,
.property-group h3,
.export-options h2 {
    margin: 0 0 11px;
    font-family: "GGBold", sans-serif;
    font-size: 14px;
}

.tool-section p,
.empty-properties p {
    margin: -3px 0 12px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.tool-card {
    min-width: 0;
    min-height: 94px;
    padding: 10px 7px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    color: var(--ink);
    background: #f7faf9;
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    text-align: center;
}

.tool-card:hover { border-color: #92bcb7; background: #f1f8f6; }
.tool-card strong { font-family: "GGBold", sans-serif; font-size: 11px; }
.tool-card small { color: var(--muted); font-size: 9px; line-height: 1.25; }
.tool-icon { font-family: "GGBold", sans-serif; font-size: 18px; }
.tool-icon-shape { width: 19px; height: 19px; border-radius: 5px; background: var(--coral); }

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.section-title-row > span {
    min-width: 25px;
    min-height: 25px;
    display: grid;
    place-items: center;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 50%;
    font-family: "GGBold", sans-serif;
    font-size: 11px;
}

.field {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
}

.field > span,
.variable-builder > label {
    font-family: "GGBold", sans-serif;
    font-size: 11px;
}

input[type="text"],
input[type="number"],
select,
textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    color: var(--ink);
    background: #fff;
    border: 1px solid #cdd9d7;
    border-radius: 9px;
}

textarea { min-height: 76px; resize: vertical; }
input[type="color"] { width: 100%; min-height: 38px; padding: 3px; border: 1px solid #cdd9d7; border-radius: 9px; background: #fff; }

.inline-field {
    margin-top: 6px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 7px;
}

.inline-field button {
    padding: 0 11px;
    color: #fff;
    border: 0;
    border-radius: 9px;
    background: var(--accent);
    cursor: pointer;
    font-family: "GGBold", sans-serif;
    font-size: 11px;
}

.variable-list { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.variable-chip {
    padding: 6px 8px;
    color: var(--accent);
    border: 1px solid #b8d8d3;
    border-radius: 999px;
    background: #f2faf8;
    font-size: 10px;
    cursor: pointer;
}

.variable-list-empty { color: var(--muted); font-size: 11px; }
.background-actions,
.design-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.design-actions h2 { flex-basis: 100%; }

.workspace {
    min-height: calc(100vh - 112px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    overflow: hidden;
}

.workspace-heading,
.workspace-footer {
    min-height: 70px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: rgba(255, 255, 255, 0.92);
}

.workspace-heading { border-bottom: 1px solid var(--line); }
.workspace-footer { min-height: 54px; border-top: 1px solid var(--line); }

.record-navigation {
    display: flex;
    align-items: center;
    gap: 8px;
}

.side-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 3px;
    border-radius: 11px;
    background: #e8efed;
}

.side-toggle button {
    min-width: 68px;
    min-height: 34px;
    padding: 6px 11px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    font-family: "GGBold", sans-serif;
    font-size: 11px;
}

.side-toggle button.active {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 4px 12px rgba(14, 89, 100, 0.18);
}

.record-navigation button {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
}

.record-navigation button:disabled { opacity: 0.35; cursor: default; }
.record-navigation span { min-width: 112px; display: grid; text-align: center; }
.record-navigation strong { font-family: "GGBold", sans-serif; font-size: 12px; }
.record-navigation small { color: var(--muted); font-size: 10px; }

.canvas-scroll {
    min-height: 520px;
    padding: 32px;
    display: grid;
    place-items: center;
    overflow: auto;
    background:
        radial-gradient(circle at 15% 10%, rgba(238, 115, 95, 0.09), transparent 28%),
        radial-gradient(circle at 85% 85%, rgba(14, 89, 100, 0.10), transparent 30%),
        #e9f0ee;
}

.badge-stage {
    flex: none;
    padding: 20px;
    transition: width 180ms ease, height 180ms ease;
}

.badge-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #f4f7f6;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    box-shadow: var(--shadow), 0 0 0 1px rgba(18, 52, 61, 0.12);
    isolation: isolate;
    touch-action: none;
}

.badge-element {
    position: absolute;
    user-select: none;
    cursor: grab;
    touch-action: none;
}

.badge-element:active { cursor: grabbing; }
.badge-element.selected { outline: 2px solid #1598aa; outline-offset: 2px; }
.badge-element.text-element {
    display: flex;
    overflow: hidden;
    white-space: pre-wrap;
    line-height: 1.08;
    overflow-wrap: anywhere;
}

.badge-element.shape-element { border-style: solid; }
.badge-element.image-element img { width: 100%; height: 100%; display: block; pointer-events: none; }
.resize-handle {
    position: absolute;
    z-index: 3;
    right: -7px;
    bottom: -7px;
    width: 14px;
    height: 14px;
    display: none;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #1598aa;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    cursor: nwse-resize;
}

.badge-element.selected .resize-handle { display: block; }

.zoom-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.zoom-control input { width: 110px; accent-color: var(--accent); }
.zoom-control output { min-width: 35px; }
.data-summary { color: var(--muted); font-size: 11px; text-align: right; }
.status-dot { width: 7px; height: 7px; display: inline-block; margin-right: 6px; border-radius: 50%; background: #4fbf79; }

.empty-properties {
    margin: 18px 0;
    padding: 24px 15px;
    border: 1px dashed #b7c8c5;
    border-radius: 12px;
    background: #f7faf9;
    text-align: center;
}

.empty-properties span { font-family: "GGBold", sans-serif; font-size: 13px; }
.empty-properties p { margin: 7px 0 0; }
.properties-form[hidden],
.property-group[hidden] { display: none !important; }

.selected-element-heading {
    padding: 18px 0 13px;
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--line);
}

.selected-element-heading > div { display: grid; }
.selected-element-heading strong { margin-top: 2px; font-family: "GGBold", sans-serif; }
.icon-button { padding: 6px 9px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 11px; }
.icon-button.danger { color: var(--danger); background: #fff2f2; }
.two-columns,
.position-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.property-group { display: grid; gap: 11px; }
.unit-input { position: relative; }
.unit-input input { padding-right: 32px; }
.unit-input em { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 10px; font-style: normal; }

.segmented-control { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 3px; border-radius: 10px; background: #edf3f2; }
.segmented-control button { min-height: 31px; border: 0; border-radius: 7px; background: transparent; cursor: pointer; font-size: 11px; }
.segmented-control button.active { color: #fff; background: var(--accent); }
.layer-actions > div { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.layer-actions > .button { width: 100%; }

.export-options { border-bottom: 0; }
.radio-card { margin-top: 8px; padding: 11px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--accent); background: #f0f8f6; }
.radio-card input { accent-color: var(--accent); }
.radio-card span { display: grid; }
.radio-card strong { font-family: "GGBold", sans-serif; font-size: 12px; }
.radio-card small { color: var(--muted); font-size: 10px; }

.toast {
    position: fixed;
    z-index: 300;
    right: 20px;
    bottom: 20px;
    max-width: 360px;
    padding: 12px 16px;
    color: #fff;
    border-radius: 11px;
    background: var(--ink);
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
    font-size: 12px;
}

.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.export-overlay {
    position: fixed;
    z-index: 400;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(9, 32, 38, 0.68);
    backdrop-filter: blur(6px);
}

.export-overlay[hidden] { display: none; }
.export-dialog { width: min(390px, 100%); padding: 24px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.export-dialog strong { display: block; margin: 14px 0 5px; font-family: "GGBold", sans-serif; font-size: 18px; }
.export-dialog p { margin: 0; color: var(--muted); font-size: 12px; }
.export-progress { height: 8px; overflow: hidden; border-radius: 999px; background: #e4ecea; }
.export-progress span { width: 4%; height: 100%; display: block; border-radius: inherit; background: linear-gradient(90deg, var(--accent), #3eb8a8); transition: width 180ms ease; }

@media (max-width: 1180px) {
    .app-shell { grid-template-columns: 250px minmax(400px, 1fr); }
    .properties-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 200px 1fr 220px; gap: 20px; }
    .properties-panel .panel-heading { align-self: start; }
    .properties-panel .properties-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
    .properties-panel .selected-element-heading { grid-column: 1 / -1; }
    .properties-panel .export-options { align-self: start; }
}

@media (max-width: 820px) {
    .topbar { position: relative; padding: 12px 15px; flex-wrap: wrap; }
    .brand img { width: 94px; }
    .brand strong { font-size: 16px; }
    .topbar-actions { width: 100%; justify-content: stretch; flex-wrap: wrap; }
    .topbar-actions .button { flex: 1 1 auto; }
    .save-state { width: 100%; }
    .app-shell { padding: 10px; grid-template-columns: 1fr; }
    .tools-panel { order: 2; }
    .workspace { order: 1; min-height: auto; }
    .properties-panel { order: 3; display: block; }
    .properties-panel .properties-form { display: block; }
    .canvas-scroll { min-height: 500px; padding: 18px 8px; }
    .workspace-heading { align-items: flex-start; }
    .side-toggle { align-self: center; }
    .workspace-footer { align-items: flex-start; flex-direction: column; }
    .data-summary { text-align: left; }
}

@media (max-width: 520px) {
    .topbar-actions .button { flex-basis: calc(50% - 6px); }
    .workspace-heading { flex-direction: column; }
    .side-toggle { width: 100%; }
    .side-toggle button { width: 100%; }
    .record-navigation { width: 100%; justify-content: space-between; }
    .panel { padding: 14px; }
    .badge-stage { padding: 10px; }
    .canvas-scroll { min-height: 450px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
