/* --- MODAL STYLES --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
    opacity: 0;
    animation: fadeIn 0.2s forwards;
}

.modal-content {
    background: #2c2c2c;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    border: 1px solid #444;
    transform: scale(0.9);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    position: relative;
    color: #eee;
}

.modal-header {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #eee;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close {
    cursor: pointer;
    font-size: 28px;
    color: #aaa;
    line-height: 1;
    transition: color 0.2s;
}
.modal-close:hover { color: #fff; }

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.modal-footer {
    margin-top: 25px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.plus-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: transparent;
    color: #3399ff;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    border: 2px solid #3399ff;
    transition: all 0.2s;
    margin: 2px;
    vertical-align: middle;
}
.plus-btn:hover {
    background: #3399ff;
    color: white;
    transform: scale(1.1) rotate(90deg);
    box-shadow: 0 0 15px rgba(51, 153, 255, 0.6);
}

.btn-primary {
    background: #3399ff;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-primary:hover { background: #2288ee; }

.btn-secondary {
    background: #444;
    color: #ccc;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-secondary:hover { background: #555; color: white; }

/* Custom Piece Creator Form Styles */
.modal-body .control-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-body .control-row label {
    font-size: 13px;
    font-weight: 600;
    color: #bbb;
    margin-bottom: 0;
}

.modal-body .control-row input[type="text"] {
    background: #1a1a1a;
    color: #eee;
    border: 2px solid #444;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.2s;
}

.modal-body .control-row input[type="text"]:focus {
    outline: none;
    border-color: #3399ff;
    background: #222;
}

#cp-symbol-status {
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 4px;
    background: #1a1a1a;
    border-left: 3px solid #444;
    line-height: 1.4;
}

#cp-symbol-status.available {
    border-left-color: #2ecc71;
    background: rgba(46, 204, 113, 0.1);
}

#cp-symbol-status.taken {
    border-left-color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
}

.used-symbols-list {
    display: block;
    margin-top: 4px;
    opacity: 0.7;
    font-size: 10px;
    word-break: break-word;
}

.btn-primary:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-primary:disabled:hover {
    background: #555;
}

@keyframes fadeIn { to { opacity: 1; } }
@keyframes popIn { to { transform: scale(1); } }

/* Piece studio */
.piece-studio .modal-content { width: min(840px, 94vw); max-width: 840px; max-height: 92dvh; box-sizing: border-box; display: flex; flex-direction: column; padding: 18px; border-radius: 6px; font-family: inherit; background: #2c2c2c; border-color: #444; }
.piece-studio .modal-header { flex: none; border-color: #444; margin-bottom: 16px; }
.piece-studio .modal-header small { display: block; color: #aaa; font-size: 10px; letter-spacing: 2px; margin-bottom: 6px; }
.piece-studio .modal-header span { font-size: 20px; }
.piece-studio .modal-close { background: transparent; border: 0; padding: 4px 10px; }
.piece-studio .modal-body { overflow-y: auto; overscroll-behavior: contain; min-height: 0; display: block; padding: 2px; }
.piece-studio label { display: flex; flex-direction: column; gap: 7px; color: #ccc; font-size: 12px; font-weight: normal; min-width: 0; }
.piece-studio input, .piece-studio select { width: 100%; min-width: 0; box-sizing: border-box; background: #1a1a1a; color: #eee; border: 1px solid #444; border-radius: 5px; padding: 7px; margin: 0; font-size: 13px; }
.piece-studio input[type=color] { height: 37px; padding: 4px; }
.piece-studio button { cursor: pointer; }
.piece-studio button:focus-visible, .piece-studio input:focus-visible, .piece-studio select:focus-visible, .piece-studio summary:focus-visible { outline: 3px solid #e74c3c; outline-offset: 2px; }
.piece-studio button:disabled { cursor: default; opacity: 1; }
.studio-identity { display: grid; grid-template-columns: 112px minmax(0,1fr) 140px; align-items: start; gap: 18px; padding-bottom: 18px; border-bottom: 1px solid #444; }
#cp-art-preview { display: flex; padding-top: 10px; gap: 5px; }
#cp-art-preview img { width: 52px; height: 52px; object-fit: contain; }
#cp-symbol-status { color: #999; font-size: 10px; line-height: 1.4; }
.studio-columns { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 20px; margin-top: 18px; }
.piece-studio h3 { font-size: 15px; margin: 0 0 8px; color: #e74c3c; }
.studio-help { color: #aaa; font-size: 12px; line-height: 1.6; margin: 8px 0 12px; }
.studio-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.studio-presets button, .studio-offset button, #cp-mirror, #cp-clear-vectors, #cp-reset-test, #cp-reset-art { border: 1px solid #555; color: #ddd; background: #444; border-radius: 5px; padding: 7px 10px; font-size: 12px; }
.studio-presets button:hover { background: #555; }
.studio-rule { display: flex; align-items: stretch; border: 1px solid #444; border-radius: 6px; background: #333; margin-bottom: 8px; }
.studio-rule.studio-selected { border-color: #e74c3c; box-shadow: inset 3px 0 #e74c3c; }
.studio-rule button { background: transparent; border: none; color: #ccc; padding: 10px; }
.studio-rule .studio-rule-select { flex: 1; min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: left; }
.studio-rule strong { display: block; font-size: 13px; color: #eee; }
.studio-rule small { display: block; font-size: 11px; line-height: 1.6; margin-top: 3px; }
.studio-rule > button:last-child { font-size: 22px; }
#cp-rule-editor { background: #252525; padding: 12px; border-radius: 6px; margin-bottom: 12px; }
.studio-pair { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; align-items: end; margin: 12px 0; }
.piece-studio .studio-check { display: block; margin: 12px 0; line-height: 1.7; }
.studio-check input { width: auto; vertical-align: middle; margin-right: 4px; }
.studio-check small { display: block; color: #aaa; margin-left: 20px; }
.piece-studio summary { color: #bbb; cursor: pointer; font-size: 12px; padding: 8px 0; }
.studio-offset { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin: 10px 0; }
.studio-special, .studio-art { border-top: 1px solid #444; padding: 8px 0; }
.studio-art { margin-top: 18px; }
.overridden { opacity: .45; }
.studio-tabs { display: flex; background: #1a1a1a; border-radius: 6px; padding: 4px; gap: 4px; }
.studio-tabs button { flex: 1; background: transparent; border: none; color: #bbb; border-radius: 4px; padding: 7px; font-size: 12px; }
.studio-tabs button[aria-pressed=true] { background: #555; color: white; }
#cp-board { display: grid; grid-template-columns: repeat(9, 1fr); aspect-ratio: 1; width: 100%; border-radius: 3px; overflow: hidden; border: 1px solid #444; }
.piece-studio .studio-square { position: relative; border: none; border-radius: 0; margin: 0; padding: 0; aspect-ratio: 1; min-height: 0; font-size: 27px; display: grid; place-items: center; }
.studio-square.light { background: var(--studio-white, #EBECD0); }
.studio-square.dark { background: var(--studio-black, #739552); }
.studio-square.destination::after { content: ''; position: absolute; width: 24%; height: 24%; border-radius: 50%; background: #2229; pointer-events: none; }
.studio-square.direction { box-shadow: inset 0 0 0 3px #ffe092; }
.studio-square.direction::before { content: '◆'; font-size: 11px; position: absolute; top: 0; right: 2px; color: #ffdf8d; }
.studio-square img { width: 80%; height: 80%; object-fit: contain; }
.studio-square.friendly { color: white; text-shadow: 0 1px 2px #000; }
.studio-square.enemy { color: #181b20; text-shadow: 0 0 1px #fff; }
.studio-square.enemy.destination { box-shadow: inset 0 0 0 3px #f3c379; }
.studio-square.enemy.destination::after { background: transparent; }
.studio-legend { display: flex; gap: 12px; font-size: 11px; color: #aaa; padding: 8px 0; }
.studio-summary { color: #aaa; font-size: 12px; margin: 8px 0; }
#cp-error { color: #ffac9e; font-size: 13px; margin: 10px 0 0; }
#cp-error:empty { display: none; }
.piece-studio .modal-footer { flex: none; padding-top: 14px; margin-top: 10px; border-top: 1px solid #444; }
@media (max-width: 700px) {
    .piece-studio .modal-content { width: 96vw; max-height: 96dvh; padding: 14px; }
    .studio-columns { grid-template-columns: minmax(0,1fr); gap: 20px; }
    .studio-identity { grid-template-columns: 1fr 100px; gap: 12px; }
    #cp-art-preview { display: none; }
    .studio-sandbox { max-width: 400px; width: 100%; margin: auto; }
    .piece-studio .modal-footer { flex-wrap: wrap; gap: 6px; }
    .piece-studio .modal-footer button { padding: 9px 12px; }
}

.studio-rules, .studio-sandbox { min-width: 0; }
.piece-studio #cp-symbol-status { background: transparent; border: 0; padding: 0; }

.piece-studio button, .piece-studio input, .piece-studio select { font-family: inherit; }
.piece-studio .btn-primary { background: #444; border: 1px solid #666; color: #eee; }
.piece-studio .btn-primary:hover { background: #555; }
.piece-studio .btn-secondary { background: #333; border: 1px solid #555; }
.piece-studio h3 { text-transform: uppercase; font-size: 11px; letter-spacing: 1px; font-weight: normal; }
.studio-legend { flex-wrap: wrap; }

.piece-studio { color-scheme: dark; }
.piece-studio .modal-body { scrollbar-width: thin; scrollbar-color: #555 #252525; scrollbar-gutter: stable; }
.piece-studio .modal-body::-webkit-scrollbar { width: 8px; }
.piece-studio .modal-body::-webkit-scrollbar-track { background: #252525; }
.piece-studio .modal-body::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
.piece-studio select { appearance: none; padding-right: 25px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='m1 1 5 5 5-5' fill='none' stroke='%23bbb' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; }
.piece-studio select option { background: #2c2c2c; color: #eee; }
.studio-choices { display: flex; flex-wrap: wrap; gap: 4px; }
.studio-choices button { flex: 1; min-width: 0; padding: 7px; background: #333; color: #bbb; border: 1px solid #555; border-radius: 3px; font-size: 12px; }
.studio-choices button[aria-pressed=true] { border-color: #e74c3c; color: #eee; background: #444; }
