* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: #0a1628; color: #fff; user-select: none; }
#app { width: 100%; height: 100%; position: relative; }

/* Screens */
.screen { display: none; position: absolute; inset: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ===== START SCREEN ===== */
#screen-start { align-items: center; justify-content: center; background: linear-gradient(180deg, #0a1628 0%, #1a2a4a 40%, #0d4a6e 100%); }
.start-content { text-align: center; z-index: 2; padding: 20px; }
.logo-fish { font-size: 80px; animation: fishBounce 2s ease-in-out infinite; margin-bottom: 10px; }
@keyframes fishBounce { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-12px) rotate(3deg); } }
.start-content h1 { font-size: 48px; font-weight: 800; background: linear-gradient(135deg, #4fc3f7, #29b6f6, #81d4fa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; letter-spacing: 4px; margin-bottom: 8px; }
.subtitle { font-size: 16px; color: rgba(255,255,255,0.6); margin-bottom: 40px; }

/* Buttons */
.btn-primary { display: block; width: 200px; margin: 0 auto 12px; padding: 14px 0; border: none; border-radius: 24px; font-size: 18px; font-weight: 700; background: linear-gradient(135deg, #29b6f6, #0288d1); color: #fff; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; box-shadow: 0 4px 15px rgba(41,182,246,0.3); }
.btn-primary:active { transform: scale(0.96); }
.btn-secondary { display: block; width: 200px; margin: 0 auto; padding: 12px 0; border: 1px solid rgba(255,255,255,0.2); border-radius: 24px; font-size: 14px; background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.7); cursor: pointer; transition: background 0.15s; }
.btn-secondary:active { background: rgba(255,255,255,0.1); }

/* ===== DRAW SCREEN ===== */
#screen-draw { background: #0f1a2e; }
.draw-header { display: flex; align-items: center; padding: 12px 16px; gap: 12px; background: rgba(0,0,0,0.2); }
.draw-title { font-size: 18px; font-weight: 700; }
.draw-hint { font-size: 12px; color: rgba(255,255,255,0.4); }
.btn-icon { width: 32px; height: 32px; border: none; border-radius: 50%; background: rgba(255,255,255,0.1); color: #fff; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.15s; flex-shrink: 0; }
.btn-icon:active { background: rgba(255,255,255,0.2); }

.canvas-wrapper { flex:1; display:flex; align-items:center; justify-content:center; padding:10px; }
#draw-canvas { width: 100%; max-width: 360px; aspect-ratio: 360/240; background: #fff; border-radius: 12px; cursor: crosshair; touch-action: none; box-shadow: 0 4px 20px rgba(0,0,0,0.3); }

/* Toolbar */
#toolbar { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 12px; background: rgba(255,255,255,0.05); border-radius: 16px; margin: 0 16px 8px; flex-wrap: wrap; }
.tool-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool-divider { width: 1px; height: 24px; background: rgba(255,255,255,0.15); flex-shrink: 0; }
.tool-btn { width: 34px; height: 34px; border: none; border-radius: 8px; background: rgba(255,255,255,0.08); color: #fff; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.15s; }
.tool-btn:active { background: rgba(255,255,255,0.18); }
.tool-btn.active { background: rgba(41,182,246,0.3); }

.color-btn { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: transform 0.15s; flex-shrink: 0; }
.color-btn:active { transform: scale(0.9); }
.color-btn.active { border-color: #fff; transform: scale(1.15); }

.brush-size-group { display: flex; align-items: center; gap: 6px; }
.size-label { font-size: 11px; color: rgba(255,255,255,0.5); }
#brush-size { width: 70px; height: 4px; -webkit-appearance: none; appearance: none; background: rgba(255,255,255,0.15); border-radius: 2px; outline: none; }
#brush-size::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #29b6f6; cursor: pointer; }

/* Fish score bar */
#fish-score-bar { display: flex; align-items: center; gap: 10px; padding: 4px 20px; margin-bottom: 4px; }
.score-track { flex: 1; max-width: 200px; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; }
.score-fill { height: 100%; width: 0%; border-radius: 3px; background: linear-gradient(90deg, #ff5252, #ffab40, #69f0ae); transition: width 0.3s ease; }
#score-label { font-size: 12px; color: rgba(255,255,255,0.6); white-space: nowrap; }

.swim-btn { margin-top: 4px; width: 220px; }

/* ===== TANK SCREEN ===== */
#screen-tank { background: #0a1628; }
.tank-header { display: flex; align-items: center; padding: 12px 16px; gap: 12px; background: rgba(0,0,0,0.3); z-index: 2; }
.tank-title { font-size: 18px; font-weight: 700; flex: 1; }
.btn-sm { padding: 6px 14px; border: none; border-radius: 16px; font-size: 13px; font-weight: 600; background: linear-gradient(135deg, #29b6f6, #0288d1); color: #fff; cursor: pointer; transition: transform 0.15s; white-space: nowrap; }
.btn-sm:active { transform: scale(0.95); }

.tank-wrapper { flex: 1; position: relative; overflow: hidden; }
#tank-canvas { width: 100%; height: 100%; display: block; }
.tank-glass { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(180deg, rgba(79,195,247,0.05) 0%, transparent 20%, transparent 80%, rgba(0,0,0,0.1) 100%); }

.tank-footer { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: rgba(0,0,0,0.3); z-index: 2; }
#fish-count { font-size: 13px; color: rgba(255,255,255,0.6); }
.tank-actions { display: flex; gap: 6px; }

/* ===== MODAL ===== */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.78); z-index: 1000; overflow: auto; -webkit-overflow-scrolling: touch; pointer-events: auto; }
.modal-overlay.hidden { display: none; }
.modal-box { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #1a2a4a; border-radius: 20px; padding: 30px 24px; width: 280px; max-width: calc(100vw - 32px); box-sizing: border-box; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.modal-icon { font-size: 48px; margin-bottom: 10px; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; color: rgba(255,255,255,0.9); }
#fish-name-input { width: 100%; padding: 12px 16px; border: 2px solid rgba(255,255,255,0.1); border-radius: 12px; background: rgba(255,255,255,0.05); color: #fff; font-size: 16px; outline: none; text-align: center; transition: border-color 0.2s; }
#fish-name-input:focus { border-color: #29b6f6; }
#fish-name-input::placeholder { color: rgba(255,255,255,0.3); }
.modal-buttons { display: flex; gap: 10px; margin-top: 20px; }
.btn-modal-cancel, .btn-modal-confirm { flex: 1; padding: 12px; border: none; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer; transition: transform 0.1s; }
.btn-modal-cancel { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.6); }
.btn-modal-confirm { background: linear-gradient(135deg, #29b6f6, #0288d1); color: #fff; }
.btn-modal-cancel:active, .btn-modal-confirm:active { transform: scale(0.96); }

/* ===== BUBBLE EMIT ===== */
.bubble { position: absolute; border-radius: 50%; pointer-events: none; animation: bubbleRise 2s ease-out forwards; }
@keyframes bubbleRise { 0% { opacity: 0.7; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(-200px) scale(0.3); } }

/* Responsive */
@media (max-width: 420px) {
  .start-content h1 { font-size: 36px; }
  .tool-btn { width: 30px; height: 30px; font-size: 14px; }
  .color-btn { width: 22px; height: 22px; }
  #brush-size { width: 50px; }
  .draw-title { font-size: 16px; }
  .draw-hint { font-size: 11px; }
}

/* ===== FISH DETAIL MODAL ===== */
.fish-detail-box {
  width: 320px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  padding: 18px 18px 16px;
  position: relative;
}
.detail-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.detail-close:active { background: rgba(255,255,255,0.2); }
.detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding-right: 30px;
}
.detail-fish-img {
  width: 70px;
  height: 50px;
  object-fit: contain;
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.detail-info {
  flex: 1;
  min-width: 0;
}
.detail-name {
  font-size: 16px;
  font-weight: 700;
  color: #4fc3f7;
  word-break: break-all;
}
.detail-author {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}

/* Vote row */
.vote-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}
.vote-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.vote-btn:active { transform: scale(0.97); }
.vote-btn.vote-up.active {
  background: rgba(76, 175, 80, 0.25);
  border-color: #4caf50;
}
.vote-btn.vote-down.active {
  background: rgba(244, 67, 54, 0.25);
  border-color: #f44336;
}
.vote-icon { font-size: 18px; }
.vote-count {
  font-weight: 700;
  font-size: 14px;
  min-width: 18px;
  text-align: left;
}

/* Comments */
.comments-section {
  margin-bottom: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 12px;
}
.comments-header {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 8px;
  font-weight: 600;
}
.comments-list {
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}
.comment-item {
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}
.comment-author-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}
.comment-author {
  color: #4fc3f7;
  font-weight: 600;
  font-size: 12px;
}
.comment-time {
  color: rgba(255,255,255,0.35);
  font-size: 10px;
}
.comment-text {
  color: rgba(255,255,255,0.85);
  line-height: 1.4;
  word-break: break-word;
}
.no-comments {
  text-align: center;
  color: rgba(255,255,255,0.35);
  font-size: 12px;
  padding: 12px 0;
}

/* Add comment */
.add-comment-section {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#comment-author,
#comment-text {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  resize: none;
}
#comment-author:focus,
#comment-text:focus {
  border-color: #29b6f6;
}
#comment-author::placeholder,
#comment-text::placeholder {
  color: rgba(255,255,255,0.3);
}
#btn-submit-comment {
  padding: 10px 0;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #29b6f6, #0288d1);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s;
}
#btn-submit-comment:active { transform: scale(0.97); }
#btn-submit-comment:disabled {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.4);
  cursor: not-allowed;
}

/* Fish clicked highlight */
.fish-highlight {
  animation: fishClickPulse 0.4s ease-out;
}
@keyframes fishClickPulse {
  0% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.15); filter: brightness(1.4); }
  100% { transform: scale(1); filter: brightness(1); }
}

/* ===== RANKING SCREEN ===== */
.rank-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(0,0,0,0.3);
  z-index: 2;
}
.rank-title { font-size: 16px; font-weight: 600; color: #fff; flex: 1; text-align: center; }
.rank-count { font-size: 12px; color: rgba(255,255,255,0.6); }
.rank-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.05);
  overflow-x: auto;
  flex-shrink: 0;
}
.sort-btn {
  flex: 1;
  min-width: 70px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.7);
  border-radius: 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.sort-btn:hover { background: rgba(255,255,255,0.1); }
.sort-btn.active {
  background: linear-gradient(135deg, #ff7043, #f4511e);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(244, 81, 30, 0.3);
}
.rank-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px;
  overflow-y: auto;
  align-content: start;
}
@media (min-width: 600px) {
  .rank-grid { grid-template-columns: repeat(4, 1fr); }
}
.rank-card {
  position: relative;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 8px 6px 6px;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  border: 1px solid rgba(255,255,255,0.05);
}
.rank-card:hover { transform: translateY(-2px); background: rgba(255,255,255,0.12); }
.rank-card:active { transform: scale(0.97); }
.rank-card .rank-num {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  z-index: 1;
}
.rank-card.rank-top-1 .rank-num { background: linear-gradient(135deg, #ffd700, #ffa000); }
.rank-card.rank-top-2 .rank-num { background: linear-gradient(135deg, #c0c0c0, #9e9e9e); }
.rank-card.rank-top-3 .rank-num { background: linear-gradient(135deg, #cd7f32, #a0522d); }
.rank-fish-img {
  width: 100%;
  aspect-ratio: 1.4 / 1;
  object-fit: contain;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  display: block;
  image-rendering: -webkit-optimize-contrast;
}
.rank-info { margin-top: 5px; }
.rank-author {
  font-size: 11px;
  color: rgba(255,255,255,0.85);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.rank-stats {
  display: flex;
  justify-content: space-around;
  margin-top: 3px;
  font-size: 10px;
  color: rgba(255,255,255,0.55);
}
.rank-stats span { white-space: nowrap; }
.rank-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.5);
  font-size: 14px;
}
.rank-empty.hidden { display: none; }

/* Backend server status indicator */
.server-status {
  display: inline-block;
  margin: 8px auto;
  padding: 4px 12px;
  font-size: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #aaa;
  letter-spacing: 0.5px;
  user-select: none;
}
.server-status.online {
  background: rgba(76, 175, 80, 0.18);
  color: #66bb6a;
}
.server-status.offline {
  background: rgba(244, 67, 54, 0.18);
  color: #ef5350;
}