/* =========================
   Emoji Nickname Generator
   Full CSS — Desktop + Mobile Fixed for Overflow & Preview/Button Tweaks
   Replace your existing style.css with this file
   ========================= */

/* Reset & base */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale; }
html, body { height: 100%; }
body {
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  color: #343a40;
  min-height: 100vh;
  padding: 20px;
  line-height: 1.6;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  /* 防止页面整体横向滚动被意外触发（通常安全且常用） */
  overflow-x: hidden;
}

/* Header */
header {
  text-align: center;
  padding: 40px 10px 20px;
  margin-bottom: 20px;
}
h1 {
  font-size: 2.8rem;
  margin-bottom: 10px;
  color: #2b8a3e;
  font-weight: 700;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.06);
}
.subtitle {
  font-size: 1.2rem;
  color: #495057;
  max-width: 680px;
  margin: 0 auto 20px;
  font-weight: 400;
}

/* Layout container */
.container {
  display: flex;
  flex-wrap: wrap;
  max-width: 1400px;
  margin: 0 auto;
  gap: 25px;
  align-items: flex-start;
}

/* Important: ensure flex children can shrink to avoid overflow */
.panel, .preview-section, .emoji-data-seo {
  min-width: 0; /* allows flex items to shrink and prevents overflow */
}

/* Panel (Emoji Styles) */
.panel {
  flex: 1 1 320px;
  background: white;
  border-radius: 16px;
  padding: 22px;
  border: 1px solid #dee2e6;
  box-shadow: 0 6px 15px rgba(0,0,0,0.05);
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}
.panel-header {
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e9ecef;
}
.panel-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: #2b8a3e;
}

/* Emoji Tabs — default: wrap on desktop, only scroll on small screens */
.emoji-tabs {
  display: flex;
  gap: 10px;
  margin: 16px 0 18px;
  align-items: center;
  /* default: allow wrapping to next line (prevents horizontal scroll on wide screens) */
  flex-wrap: wrap;
  overflow-x: visible;
  width: 100%;
  box-sizing: border-box;
}
.emoji-tabs::-webkit-scrollbar { height: 6px; }
.tab-btn {
  background: #f1f3f5;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  color: #495057;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all 0.18s ease;
  flex: 0 1 auto;            /* allow shrinking but keep inline */
  text-align: center;
  white-space: nowrap;       /* ensure label text doesn't wrap inside button */
  box-sizing: border-box;
}
.tab-btn:hover { background: #e9ecef; transform: translateY(-2px); }
.tab-btn.active {
  background: #2b8a3e;
  color: white;
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(43,138,62,0.2);
}

/* Emoji grid - grid layout, responsive */
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(45px,1fr));
  gap: 12px;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 12px;
  border: 1px solid #e9ecef;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  box-sizing: border-box;
}
.emoji-grid::-webkit-scrollbar { width: 8px; }
.emoji-grid::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.06); border-radius: 6px; }

/* Emoji item */
.emoji-item {
  font-size: 26px;
  text-align: center;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
  background: white;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  user-select: none;
  -webkit-user-select: none;
  box-sizing: border-box;
}
.emoji-item:active { transform: translateY(1px) scale(0.995); }
.emoji-item:hover { background: #e6fcf5; transform: translateY(-4px); box-shadow: 0 5px 15px rgba(43,138,62,0.1); }
.emoji-item::after { content: ""; }

/* Preview section (includes How to Use) */
.preview-section {
  flex: 2 1 620px;
  display: flex;
  flex-direction: column;
  gap: 25px;
  width: 100%;
  min-width: 0;
  order: 2; /* default: show after panel on wide screens */
}
.preview-card {
  background: white;
  border-radius: 16px;
  padding: 28px;
  border: 1px solid #dee2e6;
  box-shadow: 0 6px 15px rgba(0,0,0,0.05);
  box-sizing: border-box;
}
.preview-header {
  font-size: 1.25rem;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #2b8a3e;
}
.preview-box {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 22px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
  word-break: break-all;
  text-align: center;
  margin-bottom: 18px;
  border: 2px dashed #ced4da;
  color: #343a40;
  transition: all 0.22s ease;
  box-sizing: border-box;
}

/* Custom input & Add Text button */
.custom-input {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}
.custom-input input {
  flex: 1;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid #ced4da;
  background: white;
  color: #495057;
  font-size: 1.05rem;
  transition: all 0.18s ease;
  box-sizing: border-box;
  min-width: 0; /* critical for shrinking inside flex */
}
.custom-input input:focus {
  outline: none;
  border-color: #2b8a3e;
  box-shadow: 0 0 0 3px rgba(43,138,62,0.08);
}
.custom-input button {
  background: #2b8a3e;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0 22px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1.05rem;
  transition: all 0.18s ease;
  box-shadow: 0 3px 8px rgba(43,138,62,0.18);
  flex: 0 0 auto;
  min-width: 110px; /* prevents it from becoming too narrow on smaller widths */
  height: 48px;
  box-sizing: border-box;
}
.custom-input button:hover { background: #248232; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(43,138,62,0.22); }

/* Controls (Generate / Clear / Copy) */
.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px,1fr));
  gap: 18px;
  width: 100%;
  box-sizing: border-box;
}
.control-btn {
  padding: 14px;
  font-size: 1.05rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.18s ease;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08);
  height: 52px;
  box-sizing: border-box;
}
.generate-btn { background: #2b8a3e; color: white; }
.clear-btn { background: #f8f9fa; color: #495057; border: 1px solid #dee2e6; }
.copy-btn { background: #343a40; color: white; }
.control-btn:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.12); }
.generate-btn:hover { background: #248232; }
.clear-btn:hover { background: #e9ecef; }
.copy-btn:hover { background: #212529; }

/* Icons (pseudo) */
.icon-random::before { content: "↻"; font-size: 1.1rem; }
.icon-clear::before { content: "×"; font-size: 1.3rem; }
.icon-copy::before { content: "⎘"; font-size: 1.15rem; }
.icon-palette::before { content: "🎨"; margin-right: 8px; }
.icon-lightbulb::before { content: "💡"; margin-right: 8px; }

/* How to Use */
.preview-card ul { padding-left: 20px; line-height: 1.8; }
ul li { margin: 8px 0; color: #495057; }

/* Footer */
footer {
  text-align: center;
  margin-top: 40px;
  padding: 25px;
  font-size: 0.95rem;
  color: #6c757d;
}
footer .dbu {
  margin: 0 0 20px 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
footer .dbu a {
  display: inline-block;
  background-color: #f8950b;
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  padding: 12px 20px;
  border-radius: 6px;
  text-decoration: none;
  text-align: center;
  transition: background-color 0.25s, transform 0.2s;
}
footer .dbu a:hover { background-color: #e57b00; transform: translateY(-2px); }

/* SEO Emoji Data Section */
.emoji-data-seo {
  max-width: 1400px;
  margin: 40px auto;
  padding: 20px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 6px 15px rgba(0,0,0,0.05);
  box-sizing: border-box;
}
.emoji-data-seo h2 { text-align: center; color: #2b8a3e; margin-bottom: 30px; }
.emoji-categories { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.emoji-category h3 { color: #2b8a3e; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #e9ecef; }
.emoji-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

/* =========================
   Responsive: Tablet & Mobile
   ========================= */

/* Medium screens: tablets and small laptops */
@media (max-width: 900px) {
  /* Stack vertically on narrower viewports */
  .container { flex-direction: column; gap: 18px; }

  /* Ensure Emoji Styles (panel) appears before preview on mobile */
  .panel { order: 1; }
  .preview-section { order: 2; }

  /* Tabs on small screens: enable horizontal scroll instead of wrap */
  .emoji-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 6px;
  }
  .emoji-tabs::-webkit-scrollbar { height: 6px; }
  .emoji-tabs::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.08); border-radius: 6px; }

  /* Tab buttons become fixed-size touch targets */
  .tab-btn { flex: 0 0 auto; min-width: 88px; }

  /* Emoji grid becomes denser and scrollable */
  .emoji-grid {
    max-height: 52vh;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 10px;
  }

  .emoji-item { font-size: 30px; padding: 12px; }

  /* Input & button sizing for tablet */
  .custom-input { flex-direction: row; gap: 10px; }
  .custom-input input { font-size: 1rem; padding: 12px 14px; }
  .custom-input button { flex: 0 0 120px; min-width: 110px; height: 48px; padding: 0 12px; }

  .controls { grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 12px; }
  .control-btn { height: 48px; padding: 12px; font-size: 1rem; }

  .preview-box { font-size: 32px; min-height: 90px; padding: 18px; }
}

/* Small phones: <= 500px — customized preview font-size & button parity */
@media (max-width: 500px) {
  body { padding: 12px; }
  h1 { font-size: 1.7rem; }
  .subtitle { font-size: 0.98rem; max-width: 96%; }

  .container { gap: 12px; }
  .panel { padding: 16px; border-radius: 12px; }
  .preview-section { padding: 0; }

  /* Tabs: keep horizontal scroll on phones */
  .emoji-tabs { gap: 8px; margin: 12px 0; padding-bottom: 6px; }
  .tab-btn { padding: 8px 12px; min-width: 72px; font-size: 0.9rem; border-radius: 16px; }

  /* Emoji grid micro-adjust */
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 8px; max-height: 44vh; padding: 8px; }
  .emoji-item { font-size: 26px; padding: 9px; border-radius: 10px; }

  /* —— Nickname Preview 字号与高度（关键改动） —— */
  .preview-box {
    font-size: 20px;        /* 更节省空间但仍然可读 */
    min-height: 64px;       /* 压缩垂直高度 */
    padding: 10px 12px;
    margin-bottom: 14px;
  }

  .preview-card { padding: 18px; }
  .preview-header { font-size: 1.05rem; margin-bottom: 12px; }

  /* —— Add Text 与控制按钮大小一致 —— */
  .custom-input {
    display: flex;
    flex-direction: row;     /* 横向排列，避免 Add Text 变为整行过宽 */
    gap: 8px;
    align-items: center;
  }

  .custom-input input {
    flex: 1 1 auto;
    min-width: 0;            /* 保证在 flex 子项里可压缩，不溢出 */
    padding: 10px 12px;
    font-size: 1rem;
  }

  .custom-input button {
    flex: 0 0 110px;         /* 固定宽度，避免变得过宽 */
    min-width: 100px;
    height: 44px;            /* 与下方控制按钮同高度 */
    padding: 0 12px;
    font-size: 1rem;
    border-radius: 10px;
    box-sizing: border-box;
  }

  /* Controls: two-column layout to make buttons visually balanced */
  .controls {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .control-btn {
    height: 44px;           /* 与 Add Text 相同高度 */
    padding: 10px;
    font-size: 1rem;
    border-radius: 10px;
  }
}

/* Extremely narrow phones: <=360px — stack buttons to avoid squish */
@media (max-width: 360px) {
  .custom-input { flex-direction: column; }
  .custom-input button { width: 100%; flex: none; min-width: 0; }
  .controls { grid-template-columns: 1fr; }
  .control-btn { width: 100%; }
  .preview-box { font-size: 18px; min-height: 60px; }
}

/* Reduce hover transitions on touch devices */
@media (hover: none) {
  .emoji-item:hover, .tab-btn:hover, .control-btn:hover, .custom-input button:hover {
    transform: none;
    box-shadow: 0 3px 8px rgba(0,0,0,0.06);
  }
}

/* Accessibility: focus outlines */
button:focus, input:focus, .emoji-item:focus {
  outline: 3px solid rgba(43,138,62,0.12);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Small utility helpers */
.hidden-mobile { display: none; }
@media (min-width: 901px) { .hidden-desktop { display: none; } }

/* End of CSS */
