* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--mg-font-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    background: var(--hx-deep);
    color: var(--hx-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, p, li { text-wrap: pretty; }

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.canvas-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--hx-canvas-dark);
    position: relative;
}

.game-tabs-bar {
    display: flex;
    gap: 0;
    background: var(--hx-surface);
    border-bottom: 1px solid var(--hx-border);
    padding: 0 16px;
}

.game-tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--hx-text-mute);
    padding: 10px 16px;
    cursor: pointer;
    font-family: var(--mg-font-body, inherit);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s;
}

.game-tab:hover {
    color: var(--hx-text);
}

.game-tab.active {
    color: var(--hx-glow);
    border-bottom-color: var(--hx-glow);
}

.canvas-wrap {
    flex: 1;
    position: relative;
    min-height: 0;
}

.canvas-wrap canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

.canvas-footer {
    background: var(--hx-surface);
    border-top: 1px solid var(--hx-border);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--hx-text-mute);
    font-family: var(--mg-font-mono, monospace);
    min-width: 0;
    overflow: hidden;
}

.canvas-footer__fullscreen {
    background: none;
    border: 1px solid var(--hx-border);
    border-radius: 4px;
    color: var(--hx-text-mute);
    cursor: pointer;
    font-size: 0.75rem;
    font-family: var(--hx-font-body, sans-serif);
    padding: 3px 8px;
    margin-left: 12px;
    line-height: 1;
    transition: color 0.2s, border-color 0.2s;
}
.canvas-footer__fullscreen:hover {
    color: var(--hx-accent);
    border-color: var(--hx-accent);
}

.canvas-footer #hex-info {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
    margin-right: 12px;
}

.hex-tooltip {
    display: none;
    position: absolute;
    z-index: 100;
    background: var(--hx-surface);
    border: 1px solid var(--hx-border);
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.78rem;
    font-family: var(--mg-font-mono, monospace);
    color: var(--hx-text);
    max-width: 320px;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    line-height: 1.5;
}

.hex-tooltip.visible {
    display: block;
}

.hex-tooltip .tt-name {
    font-weight: 600;
    color: var(--hx-accent);
    margin-bottom: 4px;
}

.hex-tooltip .tt-stats {
    color: var(--hx-text-mute);
}

.hex-tooltip .tt-special {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--hx-border);
    color: var(--hx-accent);
}

.sidebar {
    width: 280px;
    background: var(--hx-surface);
    border-left: 1px solid var(--hx-border);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--hx-border);
    padding: 0;
    flex-shrink: 0;
}

.sidebar-tab {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--hx-text-mute);
    padding: 10px 8px;
    cursor: pointer;
    font-family: var(--mg-font-body, inherit);
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
}

.sidebar-tab:hover {
    color: var(--hx-text);
}

.sidebar-tab.active {
    color: var(--hx-glow);
    border-bottom-color: var(--hx-glow);
}

.sidebar-panel {
    display: none;
    padding: 16px;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}

.sidebar-panel.active {
    display: flex;
}

.editor-hint {
    font-size: 0.8rem;
    color: var(--hx-text-mute);
    margin-bottom: 8px;
}

.ring-reset-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.ring-reset-group label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--hx-text-mute);
    font-family: var(--mg-font-mono, monospace);
}

.ring-reset-group select {
    background: var(--hx-deep);
    border: 1px solid var(--hx-border);
    color: var(--hx-text);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    width: 100%;
    font-family: var(--mg-font-body, inherit);
}

.ring-reset-group select:focus {
    outline: none;
    border-color: var(--hx-glow);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--hx-text-mute);
    font-family: var(--mg-font-mono, monospace);
}

.control-group select,
.control-group input[type="text"],
.control-group input[type="number"] {
    background: var(--hx-deep);
    border: 1px solid var(--hx-border);
    color: var(--hx-text);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100%;
    font-family: var(--mg-font-body, inherit);
}

.control-group select:focus,
.control-group input:focus {
    outline: none;
    border-color: var(--hx-glow);
}

.btn {
    background: var(--hx-glow);
    border: none;
    color: #0a1a0d;
    padding: 10px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.15s;
    width: 100%;
    font-family: var(--mg-font-body, inherit);
}

.btn:hover {
    background: var(--hx-glow-hover);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--hx-border);
    color: var(--hx-text-mute);
}

.btn-outline:hover {
    border-color: var(--hx-glow);
    color: var(--hx-text);
    background: transparent;
}

.sidebar-panel textarea {
    background: var(--hx-deep);
    border: 1px solid var(--hx-border);
    color: var(--hx-text);
    padding: 10px;
    border-radius: 4px;
    font-family: var(--mg-font-mono, monospace);
    font-size: 0.7rem;
    width: 100%;
    height: 100px;
    resize: vertical;
}

.sidebar-panel textarea:focus {
    outline: none;
    border-color: var(--hx-glow);
}

body.embed-mode {
    min-height: 0;
    overflow: hidden;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    display: block;
}

html:has(body.embed-mode) {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--hx-canvas-dark);
}

body.embed-mode .main-content {
    position: fixed;
    inset: 0;
    display: block;
}

body.embed-mode .canvas-area {
    position: absolute;
    inset: 0;
    display: block;
}

body.embed-mode .canvas-wrap {
    position: absolute;
    inset: 0;
}

body.embed-mode .canvas-wrap canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    cursor: default;
}

.fullscreen-mode {
    overflow: hidden;
}
.fullscreen-mode .canvas-area {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--hx-bg, #1a1a2e);
}

.fullscreen-exit {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10000;
    padding: 8px 16px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    font-family: var(--hx-font-body, sans-serif);
    font-size: 13px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.fullscreen-exit:hover { opacity: 1; }

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .canvas-area {
        min-height: 50vh;
        max-height: 70vh;
        flex: none;
    }

    .sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--hx-border);
        flex-direction: column;
        padding: 0;
    }

    .sidebar-tabs {
        width: 100%;
    }

    .sidebar-panel {
        padding: 16px;
    }

    .control-group {
        width: 100%;
    }
}
