:root {
  --bg: #fff7e6;
  --card: #ffffff;
  --ink: #2b2b3a;
  --primary: #ff6b6b;
  --primary-dark: #e85a5a;
  --accent: #4ecdc4;
  --accent-dark: #38b3aa;
  --soft: #ffe5b4;
  --shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --gap: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Comic Sans MS", "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  background: linear-gradient(135deg, #fff7e6, #ffe6f0 60%, #e6f7ff);
  color: var(--ink);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--card);
  box-shadow: var(--shadow);
  flex-wrap: wrap;
  gap: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}

#auth-area { display: flex; align-items: center; gap: 10px; }
#user-info { display: flex; align-items: center; gap: 10px; }
#user-avatar { width: 32px; height: 32px; border-radius: 50%; }
#user-name { font-weight: bold; }

.btn {
  border: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--soft);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
  font-weight: bold;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; border: 2px dashed rgba(0,0,0,0.15); }
.btn.big { font-size: 1.15rem; padding: 14px 26px; }

.landing {
  display: flex;
  justify-content: center;
  padding: 30px 22px 60px;
}
.landing-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 30px;
  max-width: 520px;
  text-align: center;
}
.landing-emoji { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.landing-card h2 { margin: 6px 0 4px; font-size: 1.8rem; }
.landing-tag { color: var(--primary); margin: 0 0 18px; font-size: 1rem; }
.landing-card p { line-height: 1.5; margin: 12px 0; }
.landing-list {
  list-style: none;
  padding: 0;
  margin: 18px 0 24px;
  text-align: left;
  display: inline-block;
}
.landing-list li { padding: 6px 0; font-size: 1rem; }
.landing-foot { color: rgba(0,0,0,0.5); font-size: 0.9rem; margin-top: 16px; }

#decode-preview-wrap {
  margin-top: 12px;
  padding: 10px;
  background: rgba(0,0,0,0.04);
  border-radius: 10px;
  text-align: center;
}
#decode-preview {
  max-width: 100%;
  max-height: 240px;
  border-radius: 8px;
  background: #fff;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 14px 22px 0;
  flex-wrap: wrap;
}
.tab {
  border: 0;
  padding: 10px 16px;
  border-radius: 12px 12px 0 0;
  background: rgba(255, 255, 255, 0.6);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  font-weight: bold;
}
.tab.active { background: var(--card); box-shadow: var(--shadow); }

main { padding: 0 22px 30px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-top: 0;
}

.card label { font-weight: bold; display: block; margin-bottom: 6px; }

textarea {
  width: 100%;
  font-family: inherit;
  font-size: 1.1rem;
  padding: 12px;
  border-radius: 12px;
  border: 2px solid #eee;
  resize: vertical;
}
textarea:focus { outline: none; border-color: var(--accent); }

.row {
  display: flex;
  gap: var(--gap);
  align-items: center;
  margin: 14px 0;
  flex-wrap: wrap;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--soft);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: bold;
}
.toggle input { accent-color: var(--primary); }

.output-block {
  margin: 12px 0;
  padding: 14px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  min-height: 80px;
  background: #f7fffd;
}
.output-label {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 8px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.msg-output {
  font-size: 1.6rem;
  letter-spacing: 2px;
  word-break: break-word;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.msg-output .glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.8em;
  text-align: center;
}
.msg-output img.icon-glyph {
  width: 48px;
  height: 48px;
  background: white;
  border-radius: 8px;
  border: 1px solid #eee;
  object-fit: contain;
}
.msg-output .space { width: 16px; }

.hint { color: #555; margin-top: 0; }

.cipher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.cipher-cell {
  background: #fafafa;
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  border: 2px solid #eee;
}
.cipher-cell .source {
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--accent-dark);
}
.cipher-cell input {
  width: 100%;
  padding: 6px;
  margin-top: 4px;
  font-size: 1.2rem;
  text-align: center;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-family: inherit;
}
.cipher-cell.dup { border-color: var(--primary); }

.save-status { margin-top: 10px; color: var(--accent-dark); font-weight: bold; min-height: 1.2em; }

.letter-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.letter-btn {
  position: relative;
  background: #fafafa;
  border: 2px solid #eee;
  border-radius: 10px;
  padding: 6px;
  cursor: pointer;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 1.1rem;
  font-family: inherit;
}
.letter-btn.active { border-color: var(--primary); background: #fff0f0; }
.letter-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.letter-btn .badge {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.7rem;
  color: var(--accent-dark);
}

.draw-area { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.draw-tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.draw-tools label { display: inline-flex; gap: 6px; align-items: center; font-size: 0.95rem; }
.current-letter { font-size: 1.1rem; }
.current-letter strong { font-size: 1.6rem; color: var(--primary); }

#paint {
  background: white;
  border: 3px solid var(--accent);
  border-radius: 14px;
  touch-action: none;
  cursor: crosshair;
  max-width: 100%;
}

.footer {
  text-align: center;
  padding: 12px;
  color: #888;
  font-size: 0.9rem;
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 1.2rem; }
  .tab { padding: 8px 10px; font-size: 0.9rem; }
  main { padding: 0 12px 30px; }
}
