:root {
    --primary-color: #fb8720;
    --secondary-color: #764ba2;
    --text-color: #333;
    --background-color: #fb8720;
    --ts-width: 60px;
    --ts-height: 30px;
    --ts-pad: 3px;
    --ts-knob: 24px;
}

.ble-interface {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background-color: var(--background-color);
}

.content-section {
    background: white;
    border-radius: 0 0 15px 15px;
    padding-bottom: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

/* Header styles */
.header {
    background: white;
    padding: 15px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.back-btn {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: bold;
}

.headerTitle {
    color: var(--primary-color);
    font-weight: bold;
}

.headerToggleBtn {
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.headerToggleBtn:hover {
    color: white;
}

/* Mode toggle */
.mode-toggle {
    display: flex;
    justify-content: space-between;
    margin-top: 50px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.mode-btn {
    flex: 1;
    padding: 12px 20px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0dc;
    color: #666;
    font-weight: bold;
    font-size: 1.4em;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    border-radius: 8px 8px 0 0;
    border-bottom: none;
    text-align: center;
}

.mode-btn.active {
    background: white;
    color: #4CAF50;
    border-color: white;
    border-bottom-color: transparent;
}

.mode-btn:hover {
    background: #f0f0f0;
    border-color: #8b8b8b;
    color: #4CAF50;
}

.mode-content {
    padding-left: 20px;
    padding-right: 20px;
    padding-top: 20px;
    gap: 50px;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mode-content.active {
    display: block;
    opacity: 1;
}

/* Chat interface */
.chat-container {
    max-width: 800px;
    margin: 0 auto;
    margin-top: 30px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
}

.chat-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    background: #f9f9f9;
}

.chat-header h3 {
    margin: 0 0 10px 0;
    color: var(--primary-color);
    font-size: 1.2em;
}

.chat-header p {
    margin: 0;
    color: #666;
    font-size: 1.3em;
}

.messages {
    height: 350px;
    overflow-y: auto;
    padding: 20px;
    background: white;
}

.message {
    margin: 10px 0;
    padding: 10px 15px;
    border-radius: 18px;
    max-width: 70%;
    word-wrap: break-word;
    position: relative;
    line-height: 1.4;
}

.received {
    background: white;
    border: 1px solid #e5e5ea;
    border-radius: 18px 18px 18px 4px;
    margin-right: auto;
}

.sent {
    background: #4CAF50;
    color: white;
    border-radius: 18px 18px 4px 18px;
    margin-left: auto;
}

.chat-input {
    display: flex;
    padding: 15px;
    background: #f5f5f5;
    border-top: 1px solid #e0e0e0;
}

.chat-input input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.chat-input input:focus {
    border-color: #4CAF50;
}

.chat-input button {
    margin-left: 10px;
    padding: 0 25px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
}

.chat-input button:hover {
    background: #43a047;
}

.chat-input button:disabled {
    background: #a5d6a7;
    cursor: not-allowed;
}

/* Button grid */
.button-grid-container {
    max-width: 800px;
    margin: 0 auto;
    margin-top: 30px;
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Grid Controls */
.grid-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.grid-controls-left,
.grid-controls-right {
    display: flex;
    gap: 10px;
    align-items: center;
}

.edit-controls {
    display: flex;
    gap: 5px;
}

.preset-custom-only {
    display: flex;
}

/* Hide custom controls when not in custom mode */
body:not(.custom-preset) .preset-custom-only {
    display: none !important;
}

/* Make grid size selector responsive */
.grid-size-selector {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.grid-size-selector > div {
    display: flex;
    gap: 5px;
    align-items: center;
}

.grid-size-selector select {
    padding: 5px 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

.preset-selector {
    margin-top: 20px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.preset-selector select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    font-size: 14px;
}

.grid-size-selector {
    display: flex;
    gap: 20px;
    margin: 10px 0;
    align-items: center;
    flex-direction: row;
}

.grid-size-selector > div {
    display: flex;
    gap: 10px;
    align-items: center;
}

.grid-size-selector select {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.grid-size-selector label {
    margin-right: 10px;
}

.grid-size-selector .btn {
    padding: 8px 20px;
}

.grid-controls button {
    padding: 10px 18px;
    background: #e6f0ff;
    border: none;
    border-radius: 6px;
    color: #1a73e8;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.grid-controls button:hover {
    background: #dbe8ff;
}

.grid-controls button:active {
    transform: translateY(1px);
}

#gridSize {
    margin-left: 10px;
    font-weight: bold;
    color: #555;
}

:root {
    --button-width: 135px;
    --button-height: 135px;
    --button-gap: 10px;
    --button-padding: 15px;
    --transition-speed: 0.3s;
}

.button-grid {
    display: grid;
    justify-content: center;
    gap: var(--button-gap);
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    grid-template-columns: repeat(5, var(--button-width));
    grid-auto-rows: var(--button-height);
    /* 고정 최소 높이 제거로 실제 행 수에 맞는 높이 계산 */
    position: relative;
    transition: all 0.3s ease;
}

/* Remove duplicate pseudo-elements */
.button-grid::before {
    display: none;
}

.button-grid::after {
    display: none;
}

.button-grid button {
    width: var(--button-width);
    height: var(--button-height);
    padding: var(--button-padding);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 5px;
    font-size: 14px;
    min-width: var(--button-width);
    min-height: var(--button-height);
    background-color: #f0f0f0;
    position: relative;
    overflow: hidden;
    z-index: 2;
}

.button-grid button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 3;
    transition: all var(--transition-speed) ease;
}

.button-grid button:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.1s ease;
}

.button-grid button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.2s ease;
    border-radius: 6px;
}

.button-grid button:hover::before {
    opacity: 1;
}

/* Edit mode styles */
body.edit-mode .button-grid button {
    cursor: pointer;
    position: relative;
    overflow: visible;
}

body.edit-mode .button-grid button::after {
    content: '✏️';
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 12px;
    opacity: 0.7;
    z-index: 10;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

/* Do not show edit overlay on add-tile */
body.edit-mode .button-grid .add-tile::after {
    content: none !important;
}

/* Notification styles */
.notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 14px;
    z-index: 1000;
    opacity: 0;
    animation: slideIn 0.3s ease-out forwards;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.notification.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translate(-50%, 0);
    }
    to {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
}

/* Button focus styles for better accessibility */
.button-grid button:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
    z-index: 2;
}

/* Loading state for buttons */
.button-grid button.loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.button-grid button.loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Edit mode indicator */
.edit-mode-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 12px;
    font-weight: bold;
    color: var(--primary-color);
    background: rgba(251, 135, 32, 0.1);
    padding: 4px 12px;
    border-radius: 20px;
    z-index: 10;
    display: flex;
    align-items: center;
}

.edit-mode-indicator::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    margin-right: 6px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --button-width: 110px;
        --button-height: 110px;
    }
    
    .button-grid button i {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    :root {
        --button-width: 80px;
        --button-height: 80px;
        --button-padding: 8px;
    }
    
    .button-grid button {
        font-size: 12px;
    }
    
    .button-grid button i {
        font-size: 16px;
    }
}

/* Button editor styles */
/* Modal editor styles */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
}

.modal-card {
    width: 520px;
    max-width: 92vw;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.25);
    overflow: hidden;
}

.modal-header {
    padding: 14px 18px;
    border-bottom: 1px solid #eee;
}

.modal-body {
    padding: 16px 18px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px 16px 18px;
    border-top: 1px solid #eee;
}

.form-row {
    margin-bottom: 14px;
}

.form-row label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #444;
}

.form-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
}

.icon-input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.icon-preview {
    width: 44px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #eee;
    border-radius: 6px;
    background: #fafafa;
}

.emoji-preview {
    font-size: 18px;
}

.button-grid button i {
    font-size: 24px;
    margin-bottom: 5px;
}

/* Responsive design */
@media screen and (max-width: 875px) {
    :root {
        --button-width: 120px;
        --button-height: 120px;
        --button-gap: 8px;
        --button-padding: 10px;
    }
    
    .button-grid {
        padding: 10px;
    }
    
    .button-grid button i {
        font-size: 20px;
    }
}

.button-grid button i {
    font-size: 24px;
    margin-bottom: 5px;
}

/* Responsive design */
@media screen and (max-width: 840px) {
    :root {
        --button-width: 80px;
        --button-height: 80px;
        --button-gap: 10px;
        --button-padding: 12px;
    }
    
    .button-grid {
        grid-template-columns: repeat(3, var(--button-width));
        grid-template-rows: repeat(3, var(--button-height));
        min-height: calc(var(--button-height) * 3 + var(--button-gap) * 2);
    }
    
    .button-grid button {
        min-width: var(--button-width);
        min-height: var(--button-height);
    }
    
    .button-grid button i {
        font-size: 20px;
    }
}

.grid-btn {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    padding: 10px;
    text-align: center;
    font-size: 14px;
    overflow: hidden;
}

.grid-btn:hover {
    border-color: #4CAF50;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.grid-btn i {
    font-size: 24px;
    margin-bottom: 5px;
}

/* Text-based icon style (for unicode arrows etc.) */
.grid-btn .text-icon,
.button-grid button .text-icon,
.icon-preview .text-icon {
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
    display: inline-block;
}

/* Add tile */
.grid-btn.add-tile {
    border: 2px dashed #cbd5e1;
    background: #f8fafc;
    color: #1a73e8;
}
.grid-btn.add-tile:hover {
    background: #eef5ff;
}

/* Header styles */
.grid-btn.header {
    background-color: #ffffff;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgb(248, 249, 255);
    border-radius: 0px 0px 15px 15px;
    padding: 0;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    width: 100%;
    box-sizing: border-box;
    z-index: 3000;
}

.header-content {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
    padding: 30px 36px 15px 36px;
    position: relative;
}

.ble-interface .header h1 {
    font-size: 1.8em;
    font-weight: 800;
    margin-bottom: 8px;
    text-align: center;
}

.header p {
    color: #4a5568;
    font-size: 1.1em;
    text-align: center;
}

.header-toggle-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    font-size: 1.2rem;
}

.header-title-desc {
    text-align: center;
    margin-top: 0;
}

.header-settings-bar {
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    width: 100%;
    margin: 0 auto;
    padding: 0 0 16px 0;
    background: none;
    border-radius: 16px;
    position: relative;
    gap: 16px;
    max-width: 100%;
}

.header-settings-left, .header-settings-right {
    width: 32%;
    min-width: 220px;
    height: 130px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex-shrink: 0;
}

.header-settings-col {
    padding: 16px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: white;
}

.settings-title {
    font-size: 1.3em;
    font-weight: 600;
    text-align: center;
    color: #4a5568;
    margin-bottom: 12px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e2e8f0;
}

/* 토글 컨테이너 스타일링 */
.toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    margin-bottom: 12px;
}

.toggle-label {
    font-size: 1.3em;
    color: #4a5568;
}

.toggle-switch {
    width: var(--ts-width);
    height: calc(var(--ts-height) + 2px);
    background: #e2e8f0;
    border-radius: calc(var(--ts-height) / 2 + 1px);
    position: relative;
    cursor: pointer;
}

.toggle-slider {
    width: var(--ts-knob);
    height: var(--ts-knob);
    background: #fff;
    border-radius: 50%;
    position: absolute;
    left: var(--ts-pad);
    top: var(--ts-pad);
    transition: transform 0.3s;
}

.toggle-switch.closed .toggle-slider { transform: translateX(0); }

.header-toggle-btn {
    position: absolute;
    top: 5px; right: 8px;
    z-index: 10;
    background: #eee;
    border-radius: 50%;
    border: none;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.header-toggle-btn::before {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 12px solid var(--primary-color);
    transition: transform 0.3s;
}
.header-toggle-btn.closed::before {
    transform: rotate(180deg);
}

/* 접혔을 때 숨김 */
.header-settings-bar.closed {
    max-height: 0 !important;
    overflow: hidden;
    padding: 0 !important;
    border: none !important;
}

.header-settings-bar.closed + .container {
    padding-top: 120px;
}

.header-title-desc {
    text-align: center;
    margin-top: 0;
}

.device-toggle-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.toggle-switch {
    position: relative;
    width: var(--ts-width);
    height: var(--ts-height);
    background: #fb8720;
    transition: background 0.3s;
    border-radius: calc(var(--ts-height) / 2);
    cursor: pointer;
}

.toggle-switch.closed .toggle-slider { transform: translateX(0); }

.toggle-switch.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.toggle-slider {
    position: absolute;
    top: var(--ts-pad);
    left: var(--ts-pad);
    width: var(--ts-knob);
    height: var(--ts-knob);
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.toggle-switch.active .toggle-slider {
    transform: translateX(calc(var(--ts-width) - var(--ts-knob) - (var(--ts-pad) * 2)));
}

/* Theme variants controlled by body class */
body.theme-orange {
    --primary-color: #fb8720;
    --background-color: #fb8720;
}

body.theme-esp32 {
    --primary-color: #764ba2;
    --background-color: #764ba2;
}

/* micro:bit theme */
body.theme-microbit {
    --primary-color: #3454D1;
    --background-color: #3454D1;
}

/* Apply theme color to key elements */
.ble-interface .header h1 { color: var(--primary-color); }
.back-btn { color: var(--primary-color); }
.header-toggle-btn { color: var(--primary-color); }
.header-toggle-btn:hover { background-color: #e0e0e0; color: #fff; }
.btn { background: var(--primary-color); }
.btn:hover { filter: brightness(0.9); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { filter: brightness(0.9); }
.btn-secondary { background: #f3f4f6; color: #374151; }
.btn-secondary:hover { filter: brightness(0.95); }
.chat-header h3 { color: var(--primary-color); }
.button-header h3 { color: var(--primary-color); }

/* Device select dropdown */
.device-select-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.device-select {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #fff;
    min-width: 125px;
    font-size: 1em;
}

/* Responsive font scaling */
html { font-size: 16px; }
@media (max-width: 1200px) { html { font-size: 15px; } }
@media (max-width: 1000px) { html { font-size: 14px; } }
@media (max-width: 840px) { html { font-size: 13px; } }
@media (max-width: 700px)  { html { font-size: 12px; } }
@media (max-width: 560px)  { html { font-size: 11.5px; } }
@media (max-width: 480px)  { html { font-size: 11px; } }

.toggle-label {
    font-weight: 500;
    color: #4a5568;
    font-size: 1.1em;
}

.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.status-connected {
    background-color: #4CAF50;
}

.status-disconnected {
    background-color: #f44336;
}

.status-connecting {
    background-color: #2196F3;
}

/* Button editor */
#buttonEditor {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

#buttonEditor h3 {
    margin-top: 0;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

#buttonEditor > div {
    margin-bottom: 15px;
}

#buttonEditor label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

#buttonEditor input[type="text"],
#buttonEditor select,
#buttonEditor input[type="color"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

#buttonEditor .btn {
    margin-right: 10px;
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

#saveBtnConfig {
    background: #4CAF50;
    color: white;
}

#saveBtnConfig:hover {
    background: #43a047;
}

#cancelBtnConfig {
    background: #f5f5f5;
    color: #333;
}

#cancelBtnConfig:hover {
    background: #e0e0e0;
}


/* Utility classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}


/* 880px ~ 780px 사이의 범위 */
@media (max-width: 880px) {
    :root {
        --button-width: 115px;
        --button-height: 115px;
        --button-gap: 10px;
        --button-padding: 12px;
    }
}

/* 780px ~ 680px 사이의 범위 */
@media (max-width: 780px) {
    :root {
        --button-width: 105px;
        --button-height: 105px;
        --button-gap: 9px;
        --button-padding: 10px;
    }

    .toggle-container {
        gap: 10px;
    }
}

/* 680px ~ 580px 사이의 범위 */
@media (max-width: 700px) {
    :root {
        --button-width: 95px;
        --button-height: 95px;
        --button-gap: 8px;
        --button-padding: 8px;
    }
}


@media (max-width: 640px) {
    :root {
        --button-width: 85px;
        --button-height: 85px;
        --button-gap: 7px;
        --button-padding: 6px;
    }
}
/* 580px ~ 480px 사이의 범위 */
@media (max-width: 600px) {
    :root {
        --button-width: 70px;
        --button-height: 70px;
        --button-gap: 7px;
        --button-padding: 6px;
    }
}

@media (max-width: 520px) {
    :root {
        --button-width: 60px;
        --button-height: 60px;
        --button-gap: 7px;
        --button-padding: 6px;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 80%;
    }
    .ble-interface .header h1 {
        margin-top: 10px;
        font-size: 1.6em;
    }
    .header-content p {
      font-size: 1.3em;
      margin-bottom: 10px;
    }
    .container {
        padding-top: 130px;
    }
    
    /* Header settings adjustments */
    .header-settings-bar {
        display: flex;
        flex-direction: row;
        gap: 10px;
        padding: 0 10px;
        flex-wrap: nowrap;
    }
    
    .header-settings-left, .header-settings-right {
        flex: 1;
        min-width: 120px;
        height: auto;
        flex-direction: column;
    }
    
    .header-settings-col {
        padding: 5px;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        background: white;
        height: 110px;
    }
    
    .toggle-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        margin-top: 5px;
    }
    
    .toggle-switch {
        width: 55px;
        height: 24px;
        margin: 0;
    }
    
    .toggle-slider {
        width: 20px;
        height: 20px;
        left: 2px;
        top: 2px;
    }
    
    .toggle-switch.closed .toggle-slider {
        left: 28px;
    }
    
    .toggle-label {
        font-size: 1.2em;
        margin: 0;
    }
    
    .settings-title {
        font-size: 1.3em;
        margin-bottom: 5px;
        padding-bottom: 3px;
    }
    
    .btn {
        font-size: 0.8em;
        height: auto;
    }
    
    .status-indicator {
        width: 10px;
        height: 10px;
        margin-right: 5px;
    }
    
    #connectBtnText {
        font-size: 1.1em;
    }
    
    .header-content {
        padding: 20px 16px 10px 16px;
    }
}

@media (max-width: 460px) {
    /* Button grid adjustments for mobile */
    :root {
        --button-width: 50px;
        --button-height: 50px;
        --button-gap: 6px;
        --button-padding: 5px;
    }

    .button-grid button {
        min-width: var(--button-width);
        min-height: var(--button-height);
    }
}

/* Notification styles */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 5px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    transform: translateY(100px);
    opacity: 0;
    animation: slideIn 0.3s ease-out forwards;
    display: flex;
    align-items: center;
    gap: 10px;
}

.notification::before {
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    margin-right: 8px;
}

.notification.success {
    background-color: #4CAF50;
}

.notification.success::before {
    content: '\f00c';
}

.notification.error {
    background-color: #f44336;
}

.notification.error::before {
    content: '\f06a';
}

.notification.warning {
    background-color: #ff9800;
    color: #333;
}

.notification.warning::before {
    content: '\f071';
}

.notification.info {
    background-color: #2196F3;
}

.notification.info::before {
    content: '\f05a';
}

.notification.fade-out {
    animation: fadeOut 0.3s ease-out forwards;
}

@keyframes slideIn {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        transform: translateY(100px);
        opacity: 0;
    }
}

/* Instructions & Warning styles */
.instructions {
    background: #fffcf8;
    border-radius: 0 0 10px 10px;
    padding: 16px;
    margin-bottom: 20px;
    border: 1px solid #e2e8f0;
}

.instructions h3 {
    color: #744210;
    margin-bottom: 12px;
}

.instructions ol {
    color: #744210;
    padding-left: 20px;
}

.instructions li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.instructions-panel {
    margin-top: 10px;
}

.instructions-toggle {
    display: none;
}

.instructions-accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 12px 16px;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}

.instructions-accordion-header.open {
    border-radius: 10px 10px 0 0;
}

.instructions-accordion-title {
    font-weight: 600;
    color: #4a5568;
    font-size: 1.05em;
}

.instructions-accordion-arrow {
    margin-left: auto;
    color: #4a5568;
    transition: transform 0.2s ease;
}

.instructions-accordion-header.open .instructions-accordion-arrow {
    transform: rotate(180deg);
}

/* Align 내부 제목 */
.instructions h3 {
    color: #4a5568;
    margin-bottom: 12px;
}

.warning-banner {
    display: block;
    background: linear-gradient(135deg, #fed7d7 0%, #fef5e7 100%);
    border: 2px solid #f56565;
    border-radius: 10px;
    padding: 14px 16px;
    margin-bottom: 12px;
}

.warning-banner .warning-title {
    font-weight: 700;
    color: #742a2a;
    margin-bottom: 6px;
}

.warning-banner ul {
    margin: 0;
    padding-left: 18px;
    color: #744210;
}

.warning-banner li {
    margin: 4px 0;
}
