:root {
  --primary: #5c67f2;
  --primary-hover: #4a54d1;
  --danger: #ff7675;
  --success: #00b894;
  --bg: #f4f6f9;
  --sidebar-bg: #ffffff;
}

body {
  margin: 0;
  font-family: "Segoe UI", "微軟正黑體", sans-serif;
  background-color: var(--bg);
  overflow: hidden;
}
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

.sidebar {
  width: 340px;
  background: var(--sidebar-bg);
  box-shadow: 2px 0 15px rgba(0, 0, 0, 0.08);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar h2 {
  margin: 0;
  color: var(--primary);
  font-size: 22px;
  font-weight: bold;
}
.tool-group {
  border-bottom: 1px solid #eee;
  padding-bottom: 15px;
}
.tool-group h3 {
  font-size: 13px;
  color: #888;
  margin: 0 0 10px 0;
  text-transform: uppercase;
  font-weight: bold;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stitch-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
button {
  padding: 8px 2px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 13px;
  transition: 0.2s;
  white-space: nowrap;
}
button:hover {
  background: #f0f1ff;
  border-color: var(--primary);
}
button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: bold;
  box-shadow: 0 2px 5px rgba(92, 103, 242, 0.3);
}
.btn-danger {
  color: var(--danger);
  border-color: #ffdada;
}
.btn-success {
  background: var(--success);
  color: white;
  border: none;
  font-weight: bold;
  box-shadow: 0 2px 5px rgba(0, 184, 148, 0.3);
}
.btn-success:hover {
  background: #00a082;
}
.file-label {
  display: block;
  padding: 10px;
  text-align: center;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  background: #fafafa;
  font-weight: bold;
  color: #555;
}
input[type="file"] {
  display: none;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
#colorPicker {
  flex: 1;
  height: 35px;
  border: none;
  cursor: pointer;
  border-radius: 4px;
}
#textInput,
#authorName {
  flex: 1;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  width: 100%;
  box-sizing: border-box;
}
.rotate-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 5px;
}
input[type="range"] {
  flex: 1;
}
.checkbox-label {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #444;
}

/* 畫布區塊：加深陰影，讓它像一張白紙 */
.canvas-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  padding: 20px;
  background: #e2e8f0;
}
canvas {
  background: white;
  box-shadow: 2px 5px 20px rgba(0, 0, 0, 0.15);
  cursor: crosshair;
  flex-shrink: 0;
  touch-action: none;
  border-radius: 4px;
}

.app-footer {
  margin-top: auto;
  padding-top: 20px;
  font-size: 12px;
  color: #999;
  text-align: center;
  line-height: 1.6;
  padding-bottom: 20px;
}
.app-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: bold;
}
.app-footer a:hover {
  text-decoration: underline;
}

/* 說明視窗 Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}
.modal-content {
  background: white;
  width: 90%;
  max-width: 450px;
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  position: relative;
  max-height: 85vh;
  overflow-y: auto;
}
.close-btn {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 28px;
  cursor: pointer;
  color: #aaa;
  transition: 0.2s;
  line-height: 1;
}
.close-btn:hover {
  color: #e74c3c;
}
.guide-sections {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.guide-box {
  background: #f8f9fa;
  padding: 12px 15px;
  border-left: 4px solid var(--primary);
  border-radius: 4px;
}
.guide-box h3 {
  margin: 0 0 5px 0;
  font-size: 15px;
  color: #333;
}
.guide-box p {
  margin: 0;
  font-size: 13.5px;
  color: #666;
  line-height: 1.6;
}

@media (max-width: 768px) {
  body {
    overflow: hidden;
  }
  .app-container {
    flex-direction: column;
  }
  .canvas-wrapper {
    height: 50vh;
    flex: none;
    padding: 10px;
    border-bottom: 1px solid #ccc;
    z-index: 1;
  }
  .sidebar {
    height: 50vh;
    width: 100%;
    flex: none;
    padding: 15px;
    box-sizing: border-box;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.1);
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
  }
  .mobile-hide {
    display: none;
  }
  .group-stitches {
    order: 1;
    border-top: none;
  }
  .group-edit {
    order: 2;
  }
  .group-grid {
    order: 3;
  }
  .group-brush {
    order: 4;
  }
  .group-canvas {
    order: 5;
  }
  .group-file {
    order: 6;
  }
  .app-footer {
    order: 7;
  }

  .group-file h3::after {
    content: " ❓點我看教學";
    color: var(--primary);
    cursor: pointer;
    float: right;
    text-transform: none;
    font-size: 13px;
  }
}
