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

[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: 'Quicksand', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  background: linear-gradient(135deg, #ffe4ef 0%, #ffeed1 35%, #d4f1f9 100%);
  color: #4a3a2a;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px;
  min-height: 100vh;
}

.app {
  width: 100%;
  max-width: 460px;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(120, 80, 80, 0.12);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 24px;
  color: #d96d6d;
  font-weight: 700;
  letter-spacing: 1px;
}

.title-emoji {
  font-size: 26px;
  filter: drop-shadow(0 2px 0 rgba(0,0,0,0.06));
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-btn {
  background: linear-gradient(180deg, #ffe4ed 0%, #ffd1dc 100%);
  border: 2px solid #ffb6c8;
  color: #b8475a;
  padding: 7px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 3px 0 #f0a0b5;
  transition: transform 0.05s, box-shadow 0.05s;
}

.diff-pill {
  background: white;
  border: 2px solid #ffd1dc;
  color: #b8475a;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 0 #f0a0b5;
  transition: transform 0.05s, box-shadow 0.05s;
}

.diff-pill:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 #f0a0b5;
}

.header-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #f0a0b5;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr 1fr;
  gap: 8px;
}

.stat {
  background: #fff;
  border: 2px solid #ffeed5;
  border-radius: 14px;
  padding: 8px 4px;
  text-align: center;
  min-width: 0;
}

.stat-label {
  color: #a09080;
  font-size: 11px;
  display: block;
  line-height: 1.4;
}

.stat-value {
  color: #4a3a2a;
  font-size: 20px;
  font-weight: 700;
  display: block;
  line-height: 1.2;
}

.stat-name .stat-value {
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Game stage */
.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #fff8e8;
  border-radius: 16px;
  overflow: hidden;
  border: 3px solid #ecd9b8;
  box-shadow: inset 0 2px 10px rgba(120, 90, 60, 0.08);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(40, 30, 30, 0.45);
  display: flex;
  justify-content: center;
  align-items: center;
  animation: fade-in 0.25s ease-out;
}

.overlay-card {
  background: white;
  padding: 24px 32px;
  border-radius: 22px;
  text-align: center;
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  max-width: 280px;
}

.overlay-emoji { font-size: 56px; margin-bottom: 6px; }
.overlay-title { font-size: 22px; color: #d96d6d; font-weight: 700; margin-bottom: 4px; }
.overlay-sub { color: #6a5a4a; margin-bottom: 4px; }
.overlay-best { color: #4a9070; font-size: 13px; margin-bottom: 16px; min-height: 16px; }

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.primary-btn {
  background: linear-gradient(180deg, #ffa5b8 0%, #ff8fa3 100%);
  border: none;
  color: white;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  box-shadow: 0 3px 0 #d96d6d;
  transition: transform 0.05s, box-shadow 0.05s;
}

.primary-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #d96d6d;
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: 0 3px 0 #d96d6d;
}

.ghost-btn {
  background: white;
  border: 2px solid #ffb6c8;
  color: #b8475a;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

.ghost-btn:active { background: #fff0f4; }

/* Controls */
.controls {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}

.action-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}

.action-btn {
  background: white;
  border: 2px solid #c8e2f0;
  color: #3f7a92;
  padding: 8px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  box-shadow: 0 2px 0 #a9c8d8;
  min-width: 92px;
  justify-content: center;
  transition: transform 0.05s, box-shadow 0.05s;
}

.action-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 #a9c8d8;
  background: #eef6fb;
}

.action-icon { font-size: 18px; line-height: 1; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(3, 54px);
  gap: 6px;
  flex: 0 0 auto;
}

.dpad-btn {
  background: linear-gradient(180deg, #f7ffe9 0%, #e4f5d0 100%);
  border: 2px solid #b7d39a;
  color: #5a7a4a;
  font-size: 18px;
  font-weight: 700;
  border-radius: 14px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  box-shadow: 0 3px 0 #8eb072;
  transition: transform 0.05s, box-shadow 0.05s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #8eb072;
  background: #d8eec0;
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

.hint {
  text-align: center;
  font-size: 11px;
  color: #a99e8e;
  line-height: 1.5;
}

/* Share button & modal */
.share-btn {
  margin-top: 12px;
  width: 100%;
  background: linear-gradient(180deg, #fff0c8 0%, #ffe09a 100%);
  border: 2px solid #f0c870;
  color: #8a5a20;
  padding: 9px 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 3px 0 #d4a850;
  transition: transform 0.05s, box-shadow 0.05s;
}

.share-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #d4a850;
}

.share-modal {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 16px;
  animation: fade-in 0.2s ease-out;
}

.share-modal-card {
  background: white;
  border-radius: 22px;
  padding: 18px;
  width: 100%;
  max-width: 360px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  position: relative;
}

.share-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 17px;
  font-weight: 700;
  color: #4a3a2a;
}

.share-preview-wrap {
  width: 100%;
  background: #f6efe4;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px;
  margin-bottom: 10px;
}

#share-canvas {
  width: 100%;
  height: auto;
  max-height: 56vh;
  display: block;
  border-radius: 10px;
  background: #fff;
}

#share-preview {
  width: 100%;
  height: auto;
  max-height: 56vh;
  display: block;
  border-radius: 10px;
  background: #fff;
  /* iOS Safari long-press → save-to-photos */
  -webkit-touch-callout: default;
  touch-callout: default;
  user-select: none;
  -webkit-user-drag: auto;
}

.share-tip {
  font-size: 11px;
  color: #a09080;
  text-align: center;
  margin-bottom: 10px;
  line-height: 1.5;
}

.share-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.share-actions .primary-btn,
.share-actions .ghost-btn {
  flex: 1;
}

.share-toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(40, 30, 30, 0.85);
  color: white;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  white-space: nowrap;
  animation: fade-in 0.2s ease-out;
  pointer-events: none;
}

/* Level Panel */
.level-panel {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 30, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
  animation: fade-in 0.2s ease-out;
}

.level-panel-card {
  background: white;
  border-radius: 22px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.level-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #4a3a2a;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 26px;
  cursor: pointer;
  color: #a09080;
  line-height: 1;
  padding: 0 4px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  overflow-y: auto;
  padding: 4px;
}

.level-btn {
  aspect-ratio: 1;
  background: linear-gradient(180deg, #fff7d6 0%, #ffe9a8 100%);
  border: 2px solid #f0c870;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #8a6a30;
  cursor: pointer;
  position: relative;
  box-shadow: 0 2px 0 #d4a850;
  transition: transform 0.05s, box-shadow 0.05s;
}

.level-btn.done {
  background: linear-gradient(180deg, #e4f8d8 0%, #c7eab2 100%);
  border-color: #8ec97a;
  color: #4a7050;
  box-shadow: 0 2px 0 #76b864;
}

.level-btn.done::after {
  content: '✓';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 11px;
  color: #4a7050;
  font-weight: 700;
}

.level-btn.locked {
  background: #f0f0f0;
  border-color: #ddd;
  color: #c0c0c0;
  cursor: not-allowed;
  box-shadow: 0 2px 0 #d0d0d0;
}

.level-btn.locked::after {
  content: '🔒';
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
}

.level-btn:active:not(.locked) {
  transform: translateY(2px);
  box-shadow: 0 0 0 #d4a850;
}

.level-tip {
  margin-top: 12px;
  font-size: 11px;
  color: #a09080;
  text-align: center;
}

/* Difficulty tabs inside level panel */
.diff-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  background: #f8efe0;
  padding: 4px;
  border-radius: 12px;
}

.diff-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: #8a6a40;
  padding: 8px 6px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s;
}

.diff-tab.active {
  background: white;
  color: #d96d6d;
  box-shadow: 0 2px 6px rgba(120, 80, 80, 0.08);
}

/* Difficulty picker (full-screen modal) */
.diff-picker {
  position: fixed;
  inset: 0;
  background: rgba(40, 30, 30, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
  padding: 16px;
  animation: fade-in 0.25s ease-out;
}

.diff-picker-card {
  background: white;
  border-radius: 22px;
  padding: 24px 20px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
}

.diff-picker-close {
  position: absolute;
  top: 8px;
  right: 12px;
}

.diff-picker-emoji {
  font-size: 48px;
  margin-bottom: 4px;
}

.diff-picker-title {
  font-size: 22px;
  font-weight: 700;
  color: #d96d6d;
  margin-bottom: 4px;
}

.diff-picker-sub {
  font-size: 13px;
  color: #a09080;
  margin-bottom: 18px;
}

.diff-picker-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.diff-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, #fff7e3 0%, #ffeed1 100%);
  border: 2px solid #f0d5b5;
  border-radius: 16px;
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 #e0b890;
  transition: transform 0.05s, box-shadow 0.05s;
}

.diff-choice:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #e0b890;
}

.diff-choice[data-diff="medium"] {
  background: linear-gradient(180deg, #fff0e0 0%, #ffd9b8 100%);
  border-color: #f0b070;
  box-shadow: 0 3px 0 #d49050;
}
.diff-choice[data-diff="medium"]:active { box-shadow: 0 1px 0 #d49050; }

.diff-choice[data-diff="hard"] {
  background: linear-gradient(180deg, #ffe0e8 0%, #ffc5d0 100%);
  border-color: #ff9bb0;
  box-shadow: 0 3px 0 #d96d6d;
}
.diff-choice[data-diff="hard"]:active { box-shadow: 0 1px 0 #d96d6d; }

.diff-choice-emoji {
  font-size: 32px;
  flex: 0 0 auto;
}

.diff-choice-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.diff-choice-name {
  font-size: 17px;
  font-weight: 700;
  color: #4a3a2a;
  line-height: 1.2;
}

.diff-choice-desc {
  font-size: 12px;
  color: #8a7a6a;
  margin-top: 2px;
}

.diff-choice-progress {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 600;
  color: #4a9070;
  background: rgba(255,255,255,0.7);
  padding: 4px 8px;
  border-radius: 999px;
}

/* Animations */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Responsive */
@media (max-width: 380px) {
  body { padding: 8px; }
  .app { padding: 14px; gap: 10px; }
  .title { font-size: 22px; }
  .stat-value { font-size: 18px; }
  .stat-name .stat-value { font-size: 13px; }
  .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); }
  .action-btn { min-width: 82px; padding: 8px 10px; font-size: 13px; }
  .diff-pill { padding: 5px 8px; font-size: 12px; }
  .header-btn { padding: 6px 10px; font-size: 13px; }
}

@media (min-width: 560px) {
  .app { max-width: 520px; padding: 24px; }
  .title { font-size: 28px; }
  .stat-value { font-size: 22px; }
  .dpad { grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(3, 60px); }
}

@media (hover: hover) {
  .header-btn:hover { background: linear-gradient(180deg, #ffeef3 0%, #ffd9e2 100%); }
  .dpad-btn:hover { background: linear-gradient(180deg, #f7ffe9 0%, #ebf9d6 100%); }
  .action-btn:hover { background: #f5fafd; }
  .primary-btn:hover { background: linear-gradient(180deg, #ffb1c0 0%, #ff9bb0 100%); }
  .level-btn:hover:not(.locked) { transform: translateY(-1px); }
}
