/* =========================================================================
   Dice Editor V2 - Complete Stylesheet
   ========================================================================= */

/* --- Reset & Base --- */
.dice-editor * { box-sizing: border-box; }

/* --- Top Bar --- */
.dice-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.dice-topbar__back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    border-radius: 8px;
    cursor: pointer;
    color: #64748b;
}
.dice-topbar__back:hover { background: #f1f5f9; color: #334155; }

.dice-topbar__name {
    flex: 1;
    min-width: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
    background: transparent;
    outline: none;
}
.dice-topbar__name:hover { border-color: #e2e8f0; }
.dice-topbar__name:focus { border-color: #3b82f6; background: #fff; }

.dice-topbar__actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dice-topbar__btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    white-space: nowrap;
}
.dice-topbar__btn:hover { background: #f8fafc; border-color: #cbd5e1; }

.dice-topbar__btn--primary {
    background: #3b82f6;
    border-color: #3b82f6;
    color: #fff;
}
.dice-topbar__btn--primary:hover { background: #2563eb; }

.dice-topbar__pool-name {
    font-size: 13px;
    color: #64748b;
    font-weight: 500;
    margin-right: 8px;
}

.dice-topbar__student-input {
    width: 140px;
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}
.dice-topbar__student-input:focus { border-color: #3b82f6; }

.dice-topbar__autosave {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #94a3b8;
    opacity: 0;
    transition: opacity 0.3s;
}
.dice-topbar__autosave--visible { opacity: 1; }

/* --- Topbar Spacer --- */
.dice-topbar__spacer {
    flex: 1;
}

/* --- Presets Button Bar --- */
.dice-presets-bar {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 0 16px;
    flex-wrap: nowrap;
}

.dice-presets-bar__btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: #475569;
    transition: all 0.15s;
    white-space: nowrap;
}
.dice-presets-bar__btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}
.dice-presets-bar__btn svg {
    flex-shrink: 0;
    color: #64748b;
}

/* --- Main Layout --- */
.dice-editor__main {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px 12px 80px;
}

/* --- Dice Net --- */
.dice-net {
    display: flex;
    justify-content: center;
    padding: 20px 0;
}

.dice-net__grid {
    display: grid;
    gap: 0;
}

/* D6 cross: 4 columns x 3 rows */
.dice-net__grid--d6 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 12px; /* room for glue tab indicators */
}

.dice-net__cell {
    position: relative;
    border: 1.5px solid #333;
    cursor: pointer;
    overflow: visible;
    transition: box-shadow 0.15s;
    aspect-ratio: 1;
    margin: -0.75px; /* collapse borders between cells */
}

.dice-net__cell:hover {
    z-index: 2;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.dice-net__cell--active {
    z-index: 3;
    box-shadow: 0 0 0 2.5px #3b82f6;
}

.dice-net__cell--empty {
    visibility: hidden;
    border: none;
}

/* Fold lines: dashed border on edges that connect to adjacent faces */
.dice-net__cell--fold-right  { border-right: 1.5px dashed #aaa; }
.dice-net__cell--fold-bottom { border-bottom: 1.5px dashed #aaa; }
.dice-net__cell--fold-left   { border-left: 1.5px dashed #aaa; }
.dice-net__cell--fold-top    { border-top: 1.5px dashed #aaa; }

/* Glue tab indicators */
.dice-net__tab {
    position: absolute;
    background: rgba(0,0,0,0.04);
    z-index: 0;
    pointer-events: none;
}
.dice-net__tab--top {
    top: -10px; left: 15%; right: 15%; height: 10px;
    clip-path: polygon(10% 100%, 90% 100%, 80% 0%, 20% 0%);
    border-top: 1px dashed #ccc;
}
.dice-net__tab--bottom {
    bottom: -10px; left: 15%; right: 15%; height: 10px;
    clip-path: polygon(10% 0%, 90% 0%, 80% 100%, 20% 100%);
    border-bottom: 1px dashed #ccc;
}
.dice-net__tab--left {
    left: -10px; top: 15%; bottom: 15%; width: 10px;
    clip-path: polygon(100% 10%, 100% 90%, 0% 80%, 0% 20%);
    border-left: 1px dashed #ccc;
}
.dice-net__tab--right {
    right: -10px; top: 15%; bottom: 15%; width: 10px;
    clip-path: polygon(0% 10%, 0% 90%, 100% 80%, 100% 20%);
    border-right: 1px dashed #ccc;
}

.dice-net__cell-label {
    position: absolute;
    top: 3px;
    left: 5px;
    font-size: 10px;
    font-weight: 700;
    color: rgba(0,0,0,0.18);
    pointer-events: none;
    z-index: 1;
    line-height: 1;
}

.dice-net__face-size {
    /* Controls the face size in the net */
    --face-size: 80px;
}

.dice-net__cell {
    width: var(--face-size);
    height: var(--face-size);
}

/* --- Face Rendering (inside net cells & large preview) --- */
.dice-face {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    container-type: inline-size;
}

.dice-face__pip {
    position: absolute;
    width: 14%;
    height: 14%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.dice-face__number {
    font-size: 45cqi;
    font-weight: 700;
    font-family: Arial, sans-serif;
    line-height: 1;
    user-select: none;
}

.dice-face__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.dice-face__image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.dice-face__text {
    font-family: Arial, sans-serif;
    font-weight: 500;
    text-align: center;
    padding: 8%;
    word-break: break-word;
    line-height: 1.2;
    user-select: none;
}

/* --- Face Label under net --- */
.dice-editor__face-label {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    margin: 4px 0 16px;
}

/* --- Face Editor Panel --- */
.dice-face-editor {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
}

.dice-face-editor__section {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
}
.dice-face-editor__section:last-child { border-bottom: none; }

.dice-face-editor__section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #94a3b8;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --- Color Palette --- */
.dice-color-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dice-color-picker__swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.dice-color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 2px solid #e2e8f0;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    padding: 0;
}
.dice-color-swatch:hover { border-color: #94a3b8; transform: scale(1.1); }
.dice-color-swatch--active { border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,0.25); }

.dice-color-picker__row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dice-color-picker__hex {
    width: 80px;
    padding: 4px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 13px;
    font-family: monospace;
    outline: none;
}
.dice-color-picker__hex:focus { border-color: #3b82f6; }

.dice-color-picker__native {
    width: 32px;
    height: 28px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
}

.dice-color-picker__apply-all {
    font-size: 12px;
    color: #3b82f6;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.dice-color-picker__apply-all:hover { background: #eff6ff; }

/* --- Content Type Selector --- */
.dice-content-types {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.dice-content-type {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 4px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 11px;
    color: #64748b;
}
.dice-content-type:hover { border-color: #94a3b8; background: #f8fafc; }
.dice-content-type--active {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #1e40af;
}
.dice-content-type svg { width: 20px; height: 20px; }

/* --- Type-specific Controls --- */
.dice-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Stepper (for pips/numbers) */
.dice-stepper {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    width: fit-content;
}

.dice-stepper__btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #f8fafc;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    font-size: 18px;
    font-weight: 600;
}
.dice-stepper__btn:hover { background: #e2e8f0; }
.dice-stepper__btn:disabled { opacity: 0.3; cursor: default; }

.dice-stepper__value {
    width: 48px;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    border: none;
    border-left: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
    background: #fff;
    padding: 6px 0;
    outline: none;
}

/* Color input row */
.dice-controls__color-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dice-controls__color-label {
    font-size: 12px;
    color: #64748b;
    min-width: 40px;
}

.dice-controls__color-input {
    width: 32px;
    height: 28px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
}

/* Text input */
.dice-controls__text-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    resize: none;
}
.dice-controls__text-input:focus { border-color: #3b82f6; }

/* Image upload */
.dice-upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 20px;
    border: 2px dashed #d1d5db;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    color: #64748b;
    transition: border-color 0.2s, background 0.2s;
}
.dice-upload-zone:hover { border-color: #3b82f6; background: #f0f7ff; }
.dice-upload-zone__text { font-size: 13px; font-weight: 500; }
.dice-upload-zone__hint { font-size: 11px; color: #94a3b8; }

/* Image adjust preview */
.dice-image-adjust {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dice-image-adjust__preview {
    position: relative;
    width: 150px;
    height: 150px;
    margin: 0 auto;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}
.dice-image-adjust__preview:active { cursor: grabbing; }

.dice-image-adjust__preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.dice-image-adjust__hint {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 10px;
    color: #fff;
    background: rgba(0,0,0,0.4);
    padding: 3px;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}
.dice-image-adjust__preview:hover .dice-image-adjust__hint { opacity: 1; }

.dice-image-adjust__row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dice-image-adjust__label {
    font-size: 12px;
    color: #64748b;
    min-width: 36px;
}

.dice-image-adjust__slider {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #e2e8f0;
    border-radius: 2px;
    outline: none;
}
.dice-image-adjust__slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3b82f6;
    cursor: pointer;
}

.dice-image-adjust__val {
    font-size: 12px;
    color: #64748b;
    min-width: 36px;
    text-align: right;
}

.dice-image-adjust__buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.dice-image-adjust__btn {
    padding: 4px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    color: #64748b;
}
.dice-image-adjust__btn:hover { background: #f8fafc; border-color: #cbd5e1; }
.dice-image-adjust__btn--danger { color: #ef4444; border-color: #fecaca; }
.dice-image-adjust__btn--danger:hover { background: #fef2f2; }

/* Icon picker grid (compact) */
.dice-icon-picker {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dice-icon-picker__search {
    position: relative;
}
.dice-icon-picker__search-input {
    width: 100%;
    padding: 6px 110px 6px 32px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
}
.dice-icon-picker__search-input:focus { border-color: #3b82f6; }
.dice-icon-picker__search svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

.dice-icon-picker__tabs {
    display: flex;
    gap: 2px;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px;
}
.dice-icon-picker__tab {
    flex: 1;
    padding: 4px 8px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    color: #64748b;
}
.dice-icon-picker__tab--active { background: #fff; color: #1e293b; box-shadow: 0 1px 2px rgba(0,0,0,0.06); }

.dice-icon-picker__source-select {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    padding: 3px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 5px;
    font-size: 11px;
    color: #64748b;
    background: #f8fafc;
    outline: none;
    cursor: pointer;
}
.dice-icon-picker__source-select:focus { border-color: #3b82f6; }

.dice-icon-picker__grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-height: 55vh;
    overflow-y: auto;
    padding: 2px;
}

.dice-icon-picker__item {
    aspect-ratio: 1;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: none;
}
.dice-icon-picker__item:hover { background: #f1f5f9; border-color: #e2e8f0; }
.dice-icon-picker__item--active { border-color: #3b82f6; background: #eff6ff; }
.dice-icon-picker__item svg { width: 100%; height: 100%; }

.dice-icon-picker__loading,
.dice-icon-picker__empty {
    text-align: center;
    padding: 20px;
    color: #94a3b8;
    font-size: 13px;
}

.dice-icon-picker__more {
    text-align: center;
    padding: 6px;
}
.dice-icon-picker__more-btn {
    border: none;
    background: none;
    color: #3b82f6;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 4px;
}
.dice-icon-picker__more-btn:hover { background: #eff6ff; }

/* --- Icon Picker Overlay (Bottom Sheet) --- */
.dice-icon-overlay__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 199;
    opacity: 0;
    transition: opacity 0.25s;
}
.dice-icon-overlay__backdrop--visible { opacity: 1; }

.dice-icon-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60vh;
    z-index: 200;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.dice-icon-overlay--visible { transform: translateY(0); }

.dice-icon-overlay__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.dice-icon-overlay__search {
    flex: 1;
    position: relative;
}
.dice-icon-overlay__search svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}
.dice-icon-overlay__search-input {
    width: 100%;
    padding: 8px 8px 8px 32px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}
.dice-icon-overlay__search-input:focus { border-color: #3b82f6; }

.dice-icon-overlay__source-select {
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    color: #475569;
    background: #f8fafc;
    outline: none;
    cursor: pointer;
    flex-shrink: 0;
}

.dice-icon-overlay__close {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    flex-shrink: 0;
}
.dice-icon-overlay__close:hover { background: #f1f5f9; color: #334155; }

.dice-icon-overlay__grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    align-content: start;
}

.dice-icon-overlay__grid .dice-icon-picker__item {
    padding: 8px;
}

.dice-icon-overlay__more {
    text-align: center;
    padding: 8px;
    flex-shrink: 0;
    border-top: 1px solid #f1f5f9;
}

/* Inline selected icon preview */
.dice-icon-selected {
    display: flex;
    align-items: center;
    gap: 10px;
}
.dice-icon-selected__preview {
    width: 48px;
    height: 48px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
}
.dice-icon-selected__preview svg { width: 32px; height: 32px; }
.dice-icon-selected__change {
    font-size: 13px;
    color: #3b82f6;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.dice-icon-selected__change:hover { background: #eff6ff; }

/* --- Responsive --- */
@media (max-width: 480px) {
    .dice-net__face-size { --face-size: 64px; }
    .dice-topbar { padding: 6px 8px; }
    .dice-topbar__name { font-size: 14px; padding: 4px 8px; }
    .dice-net__cell-label { font-size: 8px; }
    .dice-net__tab { display: none; }
    .dice-icon-picker__grid { grid-template-columns: repeat(6, 1fr); }
}
