:root { --primary: #d97706; --bg: #f8fafc; --panel: #ffffff; --text: #334155; --modal-mask: rgba(0,0,0,0.6); }

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg); color: var(--text); margin: 0; height: 100vh; 
    display: flex; flex-direction: column; overflow: hidden; user-select: none; -webkit-user-select: none;
}

.header { background: var(--panel); padding: 8px 15px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 1px 3px rgba(0,0,0,0.05); z-index: 10; flex-shrink: 0; }
.brand { font-weight: 800; color: #78350f; font-size: 1.1rem; display: flex; align-items: baseline; gap: 8px;}
.brand span { font-size: 0.8rem; font-weight: normal; color: #94a3b8; letter-spacing: 0.5px;}
@media (max-width: 400px) { .brand span { display: none; } }

.toolbar { background: var(--panel); padding: 8px; display: flex; gap: 8px; align-items: center; justify-content: center; border-bottom: 1px solid #e2e8f0; flex-wrap: wrap; flex-shrink: 0; }

.input-group { display: flex; align-items: center; background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 6px; padding: 2px 8px; }
.input-label { font-size: 0.8rem; color: #64748b; margin-right: 5px; font-weight: bold;}
.input-group input { border: none; background: transparent; width: 40px; text-align: center; font-weight: bold; color: var(--text); font-size: 0.9rem;}
input[type="color"] { width: 24px; height: 24px; padding: 0; cursor: pointer; border-radius: 4px;}

.btn { background: white; border: 1px solid #cbd5e1; border-radius: 6px; padding: 0 10px; height: 36px; display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 0.9rem; font-weight: 600; cursor: pointer; color: #475569; min-width: 36px; transition: 0.2s; }
.btn:active { transform: scale(0.96); background: #f1f5f9; }
.btn[data-active="true"] { background: #dbeafe; border-color: #3b82f6; color: #1d4ed8; }
.btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn.danger { color: #ef4444; border-color: #e2e8f0; } 
.btn.danger:hover { background: #fef2f2; border-color: #fca5a5; }
.btn.soft { background: #f8fafc; border-color: #e2e8f0; color: #64748b; }
.btn.soft:hover { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }

.viewport { flex-grow: 1; overflow: auto; background: #cbd5e1; display: flex; justify-content: center; align-items: center; background-image: radial-gradient(#94a3b8 1px, transparent 1px); background-size: 20px 20px; position: relative; }
#canvas-wrapper { box-shadow: 0 10px 25px rgba(0,0,0,0.2); border-radius: 4px; overflow: hidden; background: white; }
canvas { display: block; cursor: crosshair; }
#drop-zone { position: absolute; top:0; left:0; width:100%; height:100%; background: rgba(255,255,255,0.8); display: none; justify-content: center; align-items: center; font-size: 1.5rem; color: var(--primary); font-weight: bold; border: 4px dashed var(--primary); z-index: 50; }

.viewport[data-cursor="eraser"] canvas { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><text y='28' font-size='28'>🧹</text></svg>") 16 16, auto; }
.viewport[data-cursor="rotate"] canvas { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'><text y='28' font-size='28'>🔄</text></svg>") 16 16, context-menu; }

.control-panel { background: var(--panel); border-top: 1px solid #e2e8f0; display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; }
.quick-tools { display: flex; justify-content: center; gap: 10px; padding: 8px; border-bottom: 1px dashed #f1f5f9; }
.basket-scroll { overflow-x: auto; padding: 8px 10px; scrollbar-width: none; scroll-snap-type: x mandatory; }
.basket { display: flex; gap: 10px; min-width: min-content; margin: 0 auto;}

.motif { flex-shrink: 0; width: 64px; height: 86px; border: 2px solid transparent; border-radius: 8px; background: #f8fafc; padding: 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; position: relative; scroll-snap-align: start;}
.motif.active { border-color: var(--primary); background: #fff7ed; transform: translateY(-4px); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.motif-preview { width: 52px; height: 52px; background: #ddd; border-radius: 6px; background-size: cover; background-position: center; margin-bottom: 4px; display: flex; align-items: center; justify-content: center; font-weight: bold; color: rgba(255,255,255,0.9); text-shadow: 0 1px 2px rgba(0,0,0,0.3);}
.motif-count { font-size: 0.75rem; font-weight: bold; color: var(--text); background: rgba(255,255,255,0.8); padding: 1px 8px; border-radius: 10px; }
.del-btn { position: absolute; top: -5px; right: -5px; width: 22px; height: 22px; background: #ef4444; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; opacity: 0; transition: 0.2s; z-index: 2;}
.motif:hover .del-btn { opacity: 1; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--modal-mask); display: none; justify-content: center; align-items: center; z-index: 100; backdrop-filter: blur(2px); }
.modal { background: white; width: 90%; max-width: 500px; border-radius: 12px; padding: 20px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); position: relative; max-height: 80vh; overflow-y: auto;}
.modal h3 { margin-top: 0; color: #78350f; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.modal-close { position: absolute; top: 15px; right: 15px; cursor: pointer; font-size: 1.2rem; color: #999; }
.modal-content p { line-height: 1.6; font-size: 0.95rem; color: #555; }
.key-badge { background: #f1f5f9; border: 1px solid #cbd5e1; border-radius: 4px; padding: 2px 6px; font-family: monospace; font-size: 0.85rem; color: #334155; }

.page-footer { background: #f8fafc; color: #64748b; font-size: 0.75rem; text-align: center; padding: 12px 10px; border-top: 1px solid #e2e8f0; flex-shrink: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); line-height: 1.6; }
.footer-links a { color: #64748b; text-decoration: none; margin: 0 5px; cursor: pointer; }
.footer-links a:hover { color: var(--primary); text-decoration: underline; }
.footer-dedication { font-size: 0.7rem; opacity: 0.6; margin-top: 4px; font-style: italic;}

#storage-warning { display: none; background: #fffbeb; color: #b45309; font-size: 0.75rem; text-align: center; padding: 4px; border-bottom: 1px solid #fcd34d; }
.btn-text { display: none; } 
@media (min-width: 600px) { .btn-text { display: inline; } }


/* 確保織片容器可以定位星星 */
.motif {
    position: relative; 
}

/* 星星書籤按鈕樣式 */
.bookmark-btn {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    text-align: center;
    line-height: 24px;
    cursor: pointer;
    font-size: 16px;
    border: 1px solid #cbd5e1;
    z-index: 10;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    transition: transform 0.1s;
    user-select: none;
}

.bookmark-btn:hover {
    transform: scale(1.1);
}

.bookmark-btn:active {
    transform: scale(0.95);
}

/* 啟用狀態：金色星星 */
.star-active {
    color: #fbbf24;
    border-color: #fbbf24;
}

/* 未啟用狀態：灰色星星 */
.star-inactive {
    color: #cbd5e1;
    background: #f8fafc;
}

/* 稍微調整一下刪除按鈕的位置，避免跟星星打架 */
.del-btn {
    position: absolute;
    top: -8px;
    right: -8px;
}