:root {
  --bg-color: #f1f3f5;
  --container-bg: #ffffff;
  --card-bg: #f8f9fa;
  --text-color: #212529;
  --subtitle-color: #868e96;
  --button-bg: #4c6ef5;
  --button-hover: #3b5bdb;
  --secondary-button: #e9ecef;
  --secondary-hover: #dee2e6;
  --shadow-color: rgba(0, 0, 0, 0.05);
  --separator-color: #dee2e6;
  --accent-color: #ff922b;
  --modal-bg: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
  --bg-color: #1a1b1e;
  --container-bg: #25262b;
  --card-bg: #2c2e33;
  --text-color: #c1c2c5;
  --subtitle-color: #909296;
  --button-bg: #5c7cfa;
  --button-hover: #4263eb;
  --secondary-button: #373a40;
  --secondary-hover: #4a4d53;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --separator-color: #373a40;
  --modal-bg: rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }
body {
  margin: 0; padding: 0;
  font-family: 'Pretendard', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: all 0.3s ease;
}

.app-wrapper {
  max-width: 800px;
  margin: 0 auto;
  padding: 10px;
  display: flex; flex-direction: column; gap: 15px;
}

/* Navigation */
.main-nav {
  display: flex;
  justify-content: space-between;
  background: var(--container-bg);
  padding: 5px;
  border-radius: 16px;
  box-shadow: 0 4px 15px var(--shadow-color);
  position: sticky; top: 10px; z-index: 100;
}
.nav-item {
  flex: 1; padding: 12px 5px; border: none; background: none;
  color: var(--subtitle-color); font-weight: 700; cursor: pointer;
  border-radius: 12px; transition: all 0.2s; font-size: 0.85rem;
}
.nav-item.active { background: var(--button-bg); color: white; }

/* Container */
.container {
  background-color: var(--container-bg);
  padding: 2.5rem 1.5rem;
  border-radius: 24px;
  box-shadow: 0 10px 30px var(--shadow-color);
  position: relative;
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease-in; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.main-header { text-align: center; margin-bottom: 2rem; }
h1 { font-size: 1.8rem; margin: 0; }
.subtitle { color: var(--subtitle-color); font-size: 0.95rem; }

.analysis-desc-wrapper {
  margin-top: 1rem;
  padding: 1.25rem;
  background: var(--card-bg);
  border-radius: 16px;
  border-left: 5px solid var(--button-bg);
  box-shadow: 0 4px 12px var(--shadow-color);
  max-width: 100%;
}
.analysis-text {
  line-height: 1.8;
  text-align: justify;
  margin: 0;
  word-break: keep-all;
  color: var(--text-color);
  font-size: 0.9rem;
}

/* Tool Grid */
.tool-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 600px) { .tool-grid { grid-template-columns: 1fr 1fr; } }

.tool-card {
  background: var(--card-bg); padding: 20px; border-radius: 20px;
  display: flex; flex-direction: column; gap: 15px;
  border: 1px solid var(--separator-color);
}
.tool-card h3 { margin: 0; font-size: 1.1rem; color: var(--button-bg); }

/* Results & Displays */
.result-display {
  background: var(--container-bg); padding: 15px; border-radius: 12px;
  text-align: center; font-weight: 700; min-height: 50px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--separator-color);
}

/* Games Styling */
.game-selector { display: flex; gap: 5px; margin-bottom: 2rem; overflow-x: auto; padding-bottom: 5px; }
.game-sel-btn {
  flex-shrink: 0; padding: 8px 15px; border-radius: 10px; border: 1px solid var(--separator-color);
  background: var(--card-bg); color: var(--text-color); cursor: pointer; font-size: 0.85rem;
}
.game-sel-btn.active { background: var(--button-bg); color: white; border-color: var(--button-bg); }

.game-instance { display: none; flex-direction: column; gap: 20px; animation: fadeIn 0.3s ease; }
.game-instance.active { display: flex; }

.game-controls { display: flex; flex-direction: column; gap: 10px; }
.input-group { display: flex; flex-direction: column; gap: 5px; }
.input-group label { font-size: 0.85rem; font-weight: 600; }

/* Ladder Game */
.canvas-wrapper { width: 100%; background: #fff; border-radius: 12px; border: 1px solid var(--separator-color); overflow: hidden; }
#ladder-canvas { display: block; width: 100%; height: 300px; }
.ladder-io-container { display: flex; justify-content: space-between; padding: 0 10px; }
.ladder-io-container input { width: 40px; text-align: center; font-size: 0.8rem; padding: 5px; }

/* Wheel Game */
.wheel-outer { position: relative; width: 280px; height: 280px; margin: 0 auto; }
.wheel-pointer { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); z-index: 10; font-size: 24px; color: #ff4d4d; }
.wheel-container { width: 100%; height: 100%; border-radius: 50%; overflow: hidden; border: 5px solid var(--separator-color); transition: transform 4s cubic-bezier(0.15, 0, 0.15, 1); }
#wheel-canvas { width: 100%; height: 100%; }

/* Bomb Game */
.bomb-visual { text-align: center; padding: 20px; }
.bomb-emoji { font-size: 5rem; animation: shake 0.5s infinite alternate; }
@keyframes shake { from { transform: scale(1); } to { transform: scale(1.1); } }
.bomb-emoji.exploded { animation: explode 0.5s forwards; }
@keyframes explode { 0% { transform: scale(1); } 50% { transform: scale(2); opacity: 0.5; } 100% { transform: scale(1.5); opacity: 0; } }
.bomb-status { font-size: 1.2rem; font-weight: 800; margin-top: 10px; }

/* Race Game */
.race-track { background: #eee; padding: 10px; border-radius: 12px; display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--separator-color); }
.race-lane { height: 40px; background: #fff; border-radius: 20px; position: relative; border: 1px dashed #ccc; }
.race-horse { position: absolute; left: 0; top: 50%; transform: translateY(-50%); font-size: 1.5rem; transition: left 0.1s linear; }
.finish-line { position: absolute; right: 20px; top: 0; bottom: 0; width: 5px; background: red; }

/* Croc Game */
.croc-visual { font-size: 4rem; text-align: center; }
.croc-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 10px; }
.tooth-btn { height: 40px; background: #fff; border: 2px solid #ddd; border-radius: 8px; cursor: pointer; transition: all 0.2s; }
.tooth-btn.pressed { background: #eee; border-color: #bbb; pointer-events: none; }
.tooth-btn.trap { background: #ff4d4d; border-color: #ff4d4d; }

/* Common UI */
.primary-btn { width: 100%; padding: 15px; border-radius: 15px; border: none; background: var(--button-bg); color: white; font-weight: 800; cursor: pointer; box-shadow: 0 4px 15px rgba(76, 110, 245, 0.3); }
.secondary-btn { padding: 10px; border-radius: 10px; border: none; background: var(--secondary-button); color: var(--text-color); font-weight: 700; cursor: pointer; transition: all 0.2s; }
.secondary-btn:hover { background: var(--secondary-hover); }

/* Tarot, Lotto, etc. */
.tarot-wrapper { perspective: 1000px; height: 120px; width: 80px; margin: 0 auto; }
.tarot-inner { position: relative; width: 100%; height: 100%; text-align: center; transition: transform 0.6s; transform-style: preserve-3d; cursor: pointer; }
.tarot-inner.flipped { transform: rotateY(180deg); }
.tarot-front, .tarot-back { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-weight: 800; font-size: 1.5rem; }
.tarot-front { background: var(--button-bg); color: white; border: 2px solid white; }
.tarot-back { background: var(--accent-color); color: white; transform: rotateY(180deg); font-size: 0.8rem; padding: 5px; }

.lotto-container { display: flex; flex-direction: column; gap: 12px; margin-bottom: 2rem; }
.lotto-row-wrapper { background: var(--card-bg); padding: 12px; border-radius: 16px; }
.lotto-row { display: flex; justify-content: center; gap: 6px; }
.ball { width: 35px; height: 35px; border-radius: 50%; display: flex; justify-content: center; align-items: center; color: white; font-weight: 700; font-size: 0.9rem; animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; opacity: 0; transform: scale(0.5); }
@keyframes pop { to { opacity: 1; transform: scale(1); } }
.ball-yellow { background: radial-gradient(circle at 30% 30%, #fbc400, #d4a700); }
.ball-blue { background: radial-gradient(circle at 30% 30%, #69c8f2, #4da9d1); }
.ball-red { background: radial-gradient(circle at 30% 30%, #ff7272, #e05252); }
.ball-gray { background: radial-gradient(circle at 30% 30%, #aaaaaa, #888888); }
.ball-green { background: radial-gradient(circle at 30% 30%, #b0d840, #8eb52f); }

.wave-container { height: 60px; background: #e7f5ff; border-radius: 12px; overflow: hidden; position: relative; display: none; }
.wave-container.active { display: block; }
.wave-container::after { content: ''; position: absolute; top: 0; left: -100%; width: 200%; height: 100%; background: linear-gradient(90deg, transparent, rgba(76, 110, 245, 0.2), transparent); animation: wave 2s infinite linear; }
@keyframes wave { to { transform: translateX(50%); } }

input, select, textarea { padding: 10px; border-radius: 8px; border: 1px solid var(--separator-color); background: var(--container-bg); color: var(--text-color); width: 100%; font-family: inherit; }
.input-row { display: flex; gap: 10px; }

.share-area { display: flex; gap: 10px; margin-top: 2rem; }
.share-btn { flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--separator-color); background: var(--card-bg); color: var(--text-color); font-weight: 700; cursor: pointer; }

.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background: var(--modal-bg); backdrop-filter: blur(4px); }
.modal-content { background: var(--container-bg); margin: 15% auto; padding: 25px; border-radius: 24px; width: 90%; max-width: 500px; position: relative; }
.close-modal { position: absolute; right: 15px; top: 10px; font-size: 24px; cursor: pointer; }

.theme-toggle { position: absolute; top: 15px; right: 15px; background: var(--card-bg); border: 1px solid var(--separator-color); width: 35px; height: 35px; border-radius: 10px; cursor: pointer; }
.main-footer { text-align: center; padding: 2rem 0; font-size: 0.8rem; color: var(--subtitle-color); }
.footer-links a { color: var(--subtitle-color); text-decoration: none; margin: 0 5px; }

@media (max-width: 600px) {
  .nav-item { font-size: 0.75rem; padding: 10px 2px; }
  .container { padding: 2rem 1rem; }
  .wheel-outer { width: 240px; height: 240px; }
}
