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

html, body {
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", "Heiti TC", sans-serif;
  background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 50%, #a29bfe 100%);
  min-height: 100vh;
  color: #2d3436;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: 40px;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #6a5acd 0%, #8a7eef 100%);
  color: white;
  padding: 16px 24px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 28px;
  font-weight: bold;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
  letter-spacing: 1px;
}

nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: rgba(255,255,255,0.2);
  color: white;
  border: 2px solid white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.nav-btn:hover {
  background: rgba(255,255,255,0.35);
  transform: translateY(-2px);
}

.nav-btn.active {
  background: white;
  color: #6a5acd;
  box-shadow: 0 4px 12px rgba(255,255,255,0.5);
}

.btn-logout {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.3);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.view { display: none; }
.view.active { display: block; animation: fadein 0.3s; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Card ===== */
.card {
  background: white;
  padding: 24px;
  border-radius: 20px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  margin-bottom: 20px;
}

.card h2 { margin-bottom: 12px; color: #6a5acd; }
.card h3 { margin-bottom: 12px; color: #636e72; }

/* ===== Game Info ===== */
.game-info {
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
}

.info-item.grow { flex: 1; min-width: 240px; }

.info-label { color: #636e72; font-weight: bold; }

.info-value {
  font-size: 24px;
  font-weight: bold;
  color: #f39c12;
  min-width: 40px;
  text-align: center;
}

.progress-bar {
  flex: 1;
  height: 14px;
  background: #ecf0f1;
  border-radius: 7px;
  overflow: hidden;
  min-width: 120px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #00b894, #55efc4);
  width: 0;
  transition: width 0.4s ease;
  border-radius: 7px;
}

#progress-text {
  font-weight: bold;
  color: #636e72;
  min-width: 50px;
  text-align: right;
}

/* ===== Character Display ===== */
.instruction {
  font-size: 22px;
  color: #6a5acd;
  text-align: center;
  margin-bottom: 20px;
}

.character-display {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  padding: 16px;
  border-radius: 16px;
  min-height: 280px;
  border: 3px dashed #ddd;
}

.layout-left-right {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  height: 280px;
}

.layout-left-right > .slot {
  font-size: clamp(50px, 7vw, 100px);
}

.layout-top-bottom {
  display: grid;
  grid-template-rows: 130px 130px;
  gap: 12px;
  height: 280px;
}

.layout-top-bottom > .slot {
  font-size: clamp(50px, 7vw, 100px);
}

.layout-top-bottom-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 145px 145px;
  gap: 12px;
  height: 320px;
}

.layout-top-bottom-bottom > .slot:first-child {
  grid-column: 1 / -1;
  font-size: clamp(50px, 7vw, 90px);
}

.layout-top-bottom-bottom > .slot:not(:first-child) {
  font-size: clamp(40px, 5vw, 70px);
}

/* ===== 三疊結構（3 部件上下疊加，非品字）===== */
.layout-vertical-3 {
  display: grid;
  grid-template-rows: 95px 95px 95px;
  gap: 10px;
  height: 320px;
}

.layout-vertical-3 > .slot {
  font-size: clamp(35px, 5vw, 60px);
}

/* ===== 四疊結構（4 部件上下疊加）===== */
.layout-top-bottom-bottom-bottom {
  display: grid;
  grid-template-rows: 75px 75px 75px 75px;
  gap: 8px;
  height: 320px;
}

/* ===== 通用堆疊結構（5+ 部件）===== */
.layout-stack {
  display: grid;
  grid-auto-rows: 1fr;
  gap: 6px;
  height: 100%;
  min-height: 320px;
}

/* ===== 自定義位置結構 ===== */
.layout-custom {
  position: relative;
  width: 100%;
  height: 400px;
}

.layout-custom > .slot {
  position: absolute;
  font-size: clamp(35px, 5vw, 60px);
}

.layout-top-bottom-bottom-bottom > .slot {
  font-size: clamp(30px, 4vw, 50px);
}

/* ===== 上中下結構（上1全寬 + 中2左右 + 下1全寬）===== */
.layout-top-2-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 10px;
  height: 320px;
}

.layout-top-2-bottom > .slot:nth-child(1) {
  grid-column: 1 / -1;
  grid-row: 1;
  font-size: clamp(45px, 6vw, 75px);
}

.layout-top-2-bottom > .slot:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
  font-size: clamp(40px, 5vw, 65px);
}

.layout-top-2-bottom > .slot:nth-child(3) {
  grid-column: 2;
  grid-row: 2;
  font-size: clamp(40px, 5vw, 65px);
}

.layout-top-2-bottom > .slot:nth-child(4) {
  grid-column: 1 / -1;
  grid-row: 3;
  font-size: clamp(45px, 6vw, 75px);
}

/* ===== 包圍結構（冖包玉+缶）===== */
.layout-surround-3 {
  position: relative;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layout-surround-3 .slot-outer {
  position: relative;
  width: 88%;
  height: 92%;
  z-index: 1;
  font-size: clamp(60px, 8vw, 120px);
}

.layout-surround-3 .slot-inner-top {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  height: 45%;
  z-index: 2;
}

.layout-surround-3 .slot-inner-bottom {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  height: 42%;
  z-index: 2;
}

/* ===== 左右右結構（林左右 + 手手上下）===== */
.layout-left-right-right {
  display: grid;
  grid-template-columns: 45% 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
  height: 280px;
}

.layout-left-right-right .slot-outer {
  grid-column: 1;
  grid-row: 1 / 3;
  font-size: clamp(55px, 9vw, 110px);
}

.layout-left-right-right .slot-inner-top {
  grid-column: 2;
  grid-row: 1;
  height: 125px;
  font-size: clamp(40px, 6vw, 75px);
}

.layout-left-right-right .slot-inner-bottom {
  grid-column: 2;
  grid-row: 2;
  height: 125px;
  font-size: clamp(40px, 6vw, 75px);
}

/* ===== 包圍結構（外 + 內居中）===== */
.layout-surround {
  position: relative;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layout-surround .slot-outer {
  position: relative;
  width: 88%;
  height: 92%;
  z-index: 1;
  font-size: clamp(60px, 8vw, 120px);
}

.layout-surround .slot-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50%;
  height: 60%;
  z-index: 2;
  font-size: clamp(35px, 5vw, 65px);
}

/* ===== 半包圍結構（辶包左）===== */
.layout-half-surround-left {
  position: relative;
  height: 280px;
}

.layout-half-surround-left .slot-outer {
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  z-index: 1;
  font-size: clamp(60px, 10vw, 120px);
}

.layout-half-surround-left .slot-inner {
  position: absolute;
  top: 50%;
  left: 48%;
  transform: translate(0, -50%);
  width: 50%;
  height: 60%;
  z-index: 2;
  font-size: clamp(40px, 6vw, 85px);
}

/* ===== 三方結構（辶左 + 上下右）===== */
.layout-complex-3-left {
  display: grid;
  grid-template-columns: 45% 1fr;
  grid-template-rows: 125px 125px;
  gap: 12px;
  height: 280px;
}

.layout-complex-3-left .slot-outer {
  grid-column: 1;
  grid-row: 1 / 3;
  font-size: clamp(55px, 9vw, 110px);
}

.layout-complex-3-left .slot-inner-top,
.layout-complex-3-left .slot-inner-bottom {
  grid-column: 2;
  height: 125px;
  font-size: clamp(40px, 6vw, 70px);
}

/* ===== 四方結構（辶左 + 自穴方右）===== */
.layout-complex-4-left {
  display: grid;
  grid-template-columns: 42% 1fr;
  grid-template-rows: 95px 95px 95px;
  gap: 12px;
  height: 320px;
}

.layout-complex-4-left .slot-outer {
  grid-column: 1;
  grid-row: 1 / 4;
  font-size: clamp(55px, 9vw, 110px);
}

.layout-complex-4-left .slot-inner-top,
.layout-complex-4-left .slot-inner-middle,
.layout-complex-4-left .slot-inner-bottom {
  grid-column: 2;
  height: 95px;
  font-size: clamp(35px, 4vw, 55px);
}

.slot {
  border: 3px dashed #b2bec3;
  border-radius: 14px;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(40px, 6vw, 90px);
  color: #2d3436;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}

.slot.drag-over {
  background: #fff3cd;
  border-color: #ffc107;
  border-style: solid;
}

.slot.filled {
  border-style: solid;
  border-color: #00b894;
  background: #d1f7eb;
  animation: pop-subtle 0.3s;
}

@keyframes pop-subtle {
  0% { opacity: 0.5; }
  60% { opacity: 1; }
  100% { opacity: 1; }
}

.slot.wrong {
  border-color: #e74c3c;
  background: #ffe6e6;
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

@keyframes pop {
  0% { transform: scale(0.8); }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* ===== Hint ===== */
.hint-section { text-align: center; margin-top: 16px; }

.btn-hint {
  background: #fdcb6e;
  color: #2d3436;
  border: none;
  padding: 12px 28px;
  border-radius: 24px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-hint:hover {
  background: #fdb44e;
  box-shadow: 0 4px 12px rgba(253,208,128,0.5);
  transform: translateY(-2px);
}

.hint-content {
  background: linear-gradient(135deg, #fff9c4 0%, #fff3a0 100%);
  padding: 16px 20px;
  border-radius: 14px;
  margin-top: 12px;
  font-size: 22px;
  color: #5d4037;
  font-weight: bold;
  border-left: 6px solid #f39c12;
  text-align: left;
  display: inline-block;
  max-width: 80%;
}

/* ===== Pieces Tray ===== */
.pieces-card { text-align: center; }

.pieces-tray {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 140px;
  align-items: center;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 12px;
}

.piece {
  background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
  color: white;
  border: 4px solid #0984e3;
  border-radius: 14px;
  width: 120px;
  height: 120px;
  font-size: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  font-weight: bold;
  box-shadow: 0 6px 12px rgba(9,132,227,0.4);
  transition: all 0.2s;
  touch-action: none;
}

.piece:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 8px 16px rgba(9,132,227,0.5);
}

.piece.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.piece.selected {
  background: linear-gradient(135deg, #fdcb6e 0%, #e17055 100%);
  border-color: #e17055;
  transform: scale(1.05);
  box-shadow: 0 0 0 6px rgba(225,112,85,0.3), 0 8px 16px rgba(225,112,85,0.5);
}

/* ===== Buttons ===== */
.game-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  padding: 14px 28px;
  border-radius: 26px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn:hover {
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #00b894 0%, #00cec9 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(0,184,149,0.4);
}

.btn-primary:hover { box-shadow: 0 6px 16px rgba(0,184,149,0.5); }

.btn-secondary {
  background: white;
  color: #6a5acd;
  border: 3px solid #6a5acd;
}

.btn-skip {
  background: #b2bec3;
  color: white;
  border: 3px solid #636e72;
}

.btn-skip:hover {
  background: #636e72;
  transform: translateY(-2px);
}

.btn.small {
  padding: 8px 16px;
  font-size: 14px;
}

/* ===== Celebration ===== */
.celebration {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadein 0.3s;
}

.celebration-content {
  background: linear-gradient(135deg, #fff9c4 0%, #ffeaa7 100%);
  padding: 60px 80px;
  border-radius: 30px;
  text-align: center;
  border: 6px solid #fdcb6e;
  animation: bouncein 0.6s;
}

.celebration-emoji {
  font-size: 180px;
  animation: spin 1s ease;
}

.celebration-text {
  font-size: 48px;
  font-weight: bold;
  color: #f39c12;
  text-shadow: 2px 2px 0 white;
  margin-top: 16px;
}

@keyframes bouncein {
  0% { transform: scale(0); }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes spin {
  0% { transform: rotate(0deg) scale(0); }
  50% { transform: rotate(360deg) scale(1.2); }
  100% { transform: rotate(360deg) scale(1); }
}

/* ===== Game Over ===== */
.game-over {
  text-align: center;
  padding: 40px 20px;
}

.game-over h2 {
  font-size: 60px;
  color: #00b894;
  margin-bottom: 16px;
}

.game-over p {
  font-size: 22px;
  margin-bottom: 24px;
  color: #636e72;
}

/* ===== Admin ===== */
.admin-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
}

.admin-left {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-right {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

@media (max-width: 880px) {
  .admin-layout { grid-template-columns: 1fr; }
}

.form-field { margin-bottom: 16px; }

.form-field label {
  display: block;
  margin-bottom: 6px;
  font-weight: bold;
  color: #2d3436;
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid #dfe6e9;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: #6a5acd;
  box-shadow: 0 0 0 3px rgba(106,90,205,0.15);
}

.form-field small {
  display: block;
  margin-top: 4px;
  color: #b2bec3;
  font-size: 12px;
}

.form-actions { display: flex; gap: 10px; }

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.char-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  max-height: 600px;
  overflow-y: auto;
  padding-right: 4px;
}

.char-item {
  background: linear-gradient(135deg, #f8f9fa 0%, #ffeaa7 100%);
  padding: 14px;
  border-radius: 14px;
  border: 2px solid #dfe6e9;
}

.char-display-mini {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.big-char {
  font-size: 42px;
  font-weight: bold;
  color: #6a5acd;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

.arrow { color: #636e72; font-size: 18px; }
.components {
  font-size: 18px;
  color: #2d3436;
  font-weight: bold;
}

.char-hint-mini {
  font-size: 13px;
  color: #2d3436;
  margin-top: 6px;
  line-height: 1.4;
}

.char-meta {
  font-size: 11px;
  color: #b2bec3;
  margin-top: 4px;
}

.char-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.char-actions button {
  flex: 1;
  background: white;
  border: 2px solid #dfe6e9;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}

.char-actions button:hover {
  transform: translateY(-1px);
}

.btn-edit:hover { background: #74b9ff; color: white; border-color: #74b9ff; }
.btn-delete:hover { background: #e17055; color: white; border-color: #e17055; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(45,52,54,0.95);
  color: white;
  padding: 14px 28px;
  border-radius: 24px;
  font-size: 16px;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  animation: fadein 0.3s;
}

.hidden {
  display: none !important;
}

/* ===== 完成态：显示完整汉字 ===== */
.character-display.complete-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 280px;
  border-style: solid;
  background: linear-gradient(135deg, #fff9c4 0%, #ffeaa7 100%);
  border-color: #fdcb6e;
  border-width: 4px;
}

.complete-character {
  font-size: 220px;
  font-weight: bold;
  color: #6a5acd;
  text-shadow:
    4px 4px 0 rgba(255,255,255,0.8),
    0 0 30px rgba(106,90,205,0.3);
  animation: char-pop-in 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  line-height: 1;
}

@keyframes char-pop-in {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(0deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ===== 登入/註冊 ===== */
.login-card {
  max-width: 400px;
  margin: 60px auto;
  text-align: center;
}

.login-card h2 {
  margin-bottom: 24px;
  color: #6a5acd;
}

.auth-switch {
  margin-top: 16px;
  color: #636e72;
}

.auth-switch a {
  color: #6a5acd;
  text-decoration: underline;
}

.error-msg {
  color: #e74c3c;
  margin-top: 12px;
  font-size: 14px;
}

/* ===== 用戶面板 ===== */
.dashboard-header {
  text-align: center;
  margin-bottom: 24px;
}

.dashboard-header h2 {
  color: #6a5acd;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
  color: white;
  padding: 24px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 4px 15px rgba(108, 92, 231, 0.3);
}

.stat-value {
  font-size: 42px;
  font-weight: bold;
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  opacity: 0.9;
}

.progress-list {
  max-height: 400px;
  overflow-y: auto;
}

.progress-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid #eee;
  gap: 16px;
}

.progress-char {
  font-size: 32px;
  width: 60px;
  text-align: center;
  color: #6a5acd;
}

.progress-stats {
  flex: 1;
  font-size: 14px;
  color: #636e72;
}

.progress-date {
  font-size: 12px;
  color: #b2bec3;
}

/* ===== 管理員面板 ===== */
.user-list, .char-stats-list {
  max-height: 400px;
  overflow-y: auto;
}

.user-item, .char-stat-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid #eee;
  gap: 16px;
}

.user-name, .char-stat-char {
  font-size: 18px;
  font-weight: bold;
  color: #6a5acd;
  width: 120px;
}

.user-stats, .char-stat-info {
  flex: 1;
  font-size: 14px;
  color: #636e72;
}

/* ===== Dashboard Tabs ===== */
.dashboard-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.dashboard-tab {
  display: none;
}

.dashboard-tab.active {
  display: block;
}

/* ===== Leaderboard ===== */
.leaderboard-list {
  max-height: 500px;
  overflow-y: auto;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid #eee;
  gap: 16px;
}

.leaderboard-item:hover {
  background: #f8f9fa;
}

.leaderboard-rank {
  font-size: 20px;
  font-weight: bold;
  width: 40px;
  text-align: center;
  color: #6a5acd;
}

.leaderboard-rank.top-1 { color: #ffd700; }
.leaderboard-rank.top-2 { color: #c0c0c0; }
.leaderboard-rank.top-3 { color: #cd7f32; }

.leaderboard-avatar {
  font-size: 24px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f0f0;
  border-radius: 50%;
  flex-shrink: 0;
}

.leaderboard-name {
  font-weight: bold;
  min-width: 100px;
  color: #2d3436;
}

.leaderboard-stats {
  flex: 1;
  color: #636e72;
  font-size: 14px;
}

.leaderboard-badge {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 12px;
  background: #dfe6e9;
  color: #636e72;
}

/* ===== Profile ===== */
.profile-card {
  max-width: 500px;
  margin-bottom: 20px;
}

.profile-avatar-section {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: bold;
  color: white;
  overflow: hidden;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-url-field {
  flex: 1;
}

.avatar-url-field input {
  width: 100%;
  padding: 10px;
  border: 1px solid #dfe6e9;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 8px;
}

.avatar-selector {
  margin-bottom: 20px;
}

.avatar-selector > label {
  display: block;
  font-weight: bold;
  color: #2d3436;
  margin-bottom: 10px;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.avatar-option {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  transition: all 0.2s;
  background: #f8f9fa;
}

.avatar-option:hover {
  transform: scale(1.1);
  border-color: #a29bfe;
}

.avatar-option.selected {
  border-color: #6c5ce7;
  background: #e8e6ff;
}

.avatar-url-field input {
  width: 100%;
  padding: 10px;
  border: 1px solid #dfe6e9;
  border-radius: 8px;
  font-size: 14px;
  margin-top: 8px;
}

.profile-card .form-field {
  margin-bottom: 16px;
}

.profile-card input {
  width: 100%;
  padding: 10px;
  border: 1px solid #dfe6e9;
  border-radius: 8px;
  font-size: 14px;
}

.profile-card label {
  display: block;
  margin-bottom: 6px;
  font-weight: bold;
  color: #2d3436;
}

/* ===== Admin Tabs ===== */
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 20px;
  background: #dfe6e9;
  border: none;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.tab-btn.active {
  background: #6a5acd;
  color: white;
}

.admin-tab {
  display: none;
}

.admin-tab.active {
  display: block;
}

/* ===== User List ===== */
.user-item {
  display: flex;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid #eee;
  gap: 12px;
}

.user-item:hover {
  background: #f8f9fa;
}

.user-name {
  font-weight: bold;
  min-width: 100px;
  color: #2d3436;
}

.user-stats {
  flex: 1;
  color: #636e72;
  font-size: 14px;
}

.user-actions {
  display: flex;
  gap: 6px;
}

.btn-small {
  padding: 5px 10px;
  font-size: 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-view {
  background: #74b9ff;
  color: white;
}

.btn-toggle-role {
  background: #fdcb6e;
  color: #2d3436;
}

.btn-danger {
  background: #ff7675;
  color: white;
}

.btn-small:hover {
  opacity: 0.8;
}

/* ===== User Detail Panel ===== */
.user-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.user-detail-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
}

.stat-mini {
  background: linear-gradient(135deg, #a29bfe 0%, #6c5ce7 100%);
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  text-align: center;
  min-width: 80px;
}

.stat-mini-val {
  display: block;
  font-size: 24px;
  font-weight: bold;
}

.stat-mini-label {
  font-size: 12px;
  opacity: 0.9;
}

.records-list {
  max-height: 400px;
  overflow-y: auto;
}

.record-item {
  display: flex;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #f0f0f0;
  gap: 16px;
}

.record-char {
  font-size: 28px;
  width: 50px;
  text-align: center;
  color: #6a5acd;
}

.record-stats {
  flex: 1;
  font-size: 13px;
  color: #636e72;
}

.record-date {
  font-size: 12px;
  color: #b2bec3;
}

/* ===== Char Stats ===== */
.char-stat-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid #f0f0f0;
  gap: 16px;
}

#import-chars {
  width: 100%;
  padding: 12px;
  border: 1px solid #dfe6e9;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
}

.import-preview-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid #eee;
  gap: 16px;
  flex-wrap: wrap;
}

.import-preview-char {
  font-size: 32px;
  width: 60px;
  text-align: center;
}

.import-preview-info {
  flex: 1;
}

.import-preview-components {
  font-size: 18px;
  color: #6c5ce7;
  margin-bottom: 4px;
}

.import-preview-layout {
  font-size: 12px;
  color: #b2bec3;
}

.import-preview-hint {
  font-size: 13px;
  color: #636e72;
  margin-top: 4px;
}

.decomp-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.decomp-option {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: #f0f0f0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.decomp-option.selected {
  background: #e8e6ff;
  border: 1px solid #6c5ce7;
}

.decomp-option input {
  display: none;
}

.layout-select {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.layout-select label {
  font-size: 13px;
  color: #636e72;
}

.layout-select select {
  padding: 4px 8px;
  border: 1px solid #dfe6e9;
  border-radius: 6px;
  font-size: 13px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.char-lib-list {
  max-height: 400px;
  overflow-y: auto;
}

.char-lib-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid #f0f0f0;
  gap: 12px;
}

.char-lib-char {
  font-size: 28px;
  width: 50px;
  text-align: center;
  color: #6a5acd;
}

.char-lib-info {
  flex: 1;
}

.char-lib-components {
  font-size: 14px;
  color: #6c5ce7;
}

.char-lib-layout {
  font-size: 11px;
  color: #b2bec3;
}

.char-lib-actions {
  display: flex;
  gap: 8px;
}

.char-stat-char {
  font-size: 28px;
  width: 60px;
  text-align: center;
  color: #6a5acd;
}

.char-stat-info {
  flex: 1;
  font-size: 13px;
  color: #636e72;
}

/* ===== Position Editor Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.modal-content {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
}

.modal-header h3 {
  margin: 0;
  color: #2d3436;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #636e72;
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.modal-close:hover {
  background: #f0f0f0;
}

.modal-body {
  padding: 20px;
  flex: 1;
  overflow: auto;
}

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

.position-canvas {
  position: relative;
  width: 100%;
  height: 400px;
  background: #f8f9fa;
  border: 2px dashed #dfe6e9;
  border-radius: 8px;
  overflow: hidden;
}

.position-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    linear-gradient(rgba(200, 200, 200, 0.2) 1px, transparent 1px),
    linear-gradient(90deg, rgba(200, 200, 200, 0.2) 1px, transparent 1px);
  background-size: 25px 25px;
  pointer-events: none;
}

.position-box {
  position: absolute;
  width: 80px;
  height: 60px;
  background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: bold;
  cursor: move;
  user-select: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s;
}

.position-box:hover {
  transform: scale(1.02);
}

.position-box:active {
  cursor: grabbing;
}

.position-box.selected {
  outline: 3px solid #fdcb6e;
  outline-offset: 2px;
  z-index: 100;
}

/* 调整大小手柄 */
.position-box .resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid #0984e3;
  border-radius: 50%;
  z-index: 10;
}

.position-box .resize-handle.br {
  right: -7px;
  bottom: -7px;
  cursor: nwse-resize;
}

.position-box .resize-handle.tl {
  left: -7px;
  top: -7px;
  cursor: nwse-resize;
}

/* 对齐辅助线 */
.align-guides {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

.align-guide {
  position: absolute;
  background: #ff6b6b;
  pointer-events: none;
}

.align-guide.vertical {
  width: 1px;
  height: 100%;
  top: 0;
}

.align-guide.horizontal {
  height: 1px;
  width: 100%;
  left: 0;
}

.snap-indicator {
  position: absolute;
  background: rgba(255, 107, 107, 0.15);
  pointer-events: none;
  z-index: 5;
}

/* ===== 響應式 ===== */
@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .admin-tabs {
    flex-direction: column;
  }
  .user-item {
    flex-wrap: wrap;
  }
  .user-actions {
    width: 100%;
    margin-top: 8px;
  }
  .avatar-grid {
    grid-template-columns: repeat(5, 1fr);
  }
  .avatar-option {
    width: 50px;
    height: 50px;
    font-size: 26px;
  }
}

.fade-out {
  opacity: 0 !important;
  transform: scale(0.9);
  transition: all 0.4s;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .piece { width: 90px; height: 90px; font-size: 64px; }
  .slot { font-size: 80px; }
  .layout-left-right, .layout-top-bottom, .layout-surround { height: 220px; }
  .layout-top-bottom-bottom { height: 260px; }
  .complete-character { font-size: 140px; }
  .logo { font-size: 22px; }
  .nav-btn { padding: 8px 14px; font-size: 14px; }
  .container { padding: 16px; }
  .celebration-content { padding: 40px 50px; }
  .celebration-emoji { font-size: 120px; }
  .celebration-text { font-size: 32px; }
}