/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Hiragino Kaku Gothic Pro', 'Yu Gothic', 'Meiryo', sans-serif;
  background: #f5f0e8;
  color: #333;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 420px;
  padding: 12px 16px;
}

.screen { display: flex; flex-direction: column; gap: 12px; }

/* ===== Language Select ===== */
#screen-lang { align-items: center; padding-top: 40px; }

#lang-buttons {
  display: flex;
  gap: 16px;
  margin-top: 20px;
}

.lang-btn {
  width: 140px;
  padding: 16px 0;
  border-radius: 14px;
  border: 2px solid #3aaa7a;
  background: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  color: #3aaa7a;
  cursor: pointer;
  transition: all 0.15s;
}

.lang-btn:hover {
  background: #3aaa7a;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(58,170,122,0.3);
}

/* ===== Header ===== */
header { text-align: center; }

header h1 {
  font-size: 1.8rem;
  font-weight: 900;
  color: #3aaa7a;
  letter-spacing: 4px;
}

header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: #444;
}

.subtitle {
  font-size: 0.85rem;
  color: #888;
  letter-spacing: 2px;
  margin-top: 2px;
}

.back-btn {
  background: none;
  border: none;
  color: #3aaa7a;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
}

/* ===== World/Stage Select ===== */
#world-status {
  text-align: center;
  padding: 8px 0;
}

#total-score-label {
  font-size: 1.1rem;
  font-weight: 700;
  color: #555;
}

#title-label {
  font-size: 0.9rem;
  color: #3aaa7a;
  font-weight: 600;
}

#world-list, #stage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.world-item, .stage-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}

.world-item:hover, .stage-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 3px 8px rgba(0,0,0,0.12);
}

.world-item.locked, .stage-item.locked {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.item-title {
  font-weight: 700;
  font-size: 1rem;
}

.item-stars {
  color: #f0a030;
  font-size: 1.1rem;
  letter-spacing: 2px;
}

/* ===== Play Header ===== */
#screen-play header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
}

#play-header-left { display: flex; align-items: center; gap: 8px; }

#stage-label {
  font-weight: 700;
  font-size: 1rem;
  color: #444;
}

#miss-label {
  font-size: 0.85rem;
  color: #888;
}

/* ===== Toolbar ===== */
#toolbar {
  display: flex;
  gap: 8px;
  justify-content: center;
}

#toolbar button {
  background: #fff;
  border: 2px solid #ddd;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #555;
  cursor: pointer;
  transition: all 0.12s;
}

#toolbar button:hover:not(:disabled) {
  border-color: #3aaa7a;
  color: #3aaa7a;
}

#toolbar button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ===== Answer Corner ===== */
#answer-corner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.answer-item {
  background: #e8f5ee;
  border-radius: 10px;
  padding: 8px 12px;
  animation: popIn 0.3s ease;
}

.answer-expression {
  font-weight: 700;
  font-size: 1rem;
  color: #2a8860;
}

.answer-reading {
  font-size: 0.75rem;
  color: #6a9;
  letter-spacing: 1px;
}

.answer-meaning {
  font-size: 0.8rem;
  color: #555;
  margin-top: 2px;
}

/* ===== Message ===== */
.message {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 1.5em;
  transition: opacity 0.3s;
}
.message.success { color: #2a9e70; }
.message.wrong { color: #d83030; }
.message.info { color: #6688aa; }

/* ===== Row Stack ===== */
#row-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.row-item {
  display: flex;
  align-items: center;
  background: #fff;
  border: 2px solid #e0dcd4;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  position: relative;
}

/* 7行以上のステージではコンパクトに */
#row-stack.compact .row-item {
  padding: 7px 10px;
}

#row-stack.compact .row-template {
  font-size: 0.92rem;
}

.row-item:last-child {
  border-color: #3aaa7a;
  background: #f0faf5;
}

.row-item.selected {
  border-color: #f0a030;
  background: #fff8ee;
  box-shadow: 0 0 0 3px rgba(240,160,48,0.25);
}

.row-item.clearing {
  animation: slideOut 0.4s ease forwards;
}

.row-item.dropping {
  animation: dropDown 0.3s ease;
}

.row-template {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 1px;
}

.blank-slot {
  display: inline-block;
  min-width: 1.2em;
  text-align: center;
  border-bottom: 2px solid #3aaa7a;
  color: #3aaa7a;
  margin: 0 1px;
}

.blank-slot.filled {
  color: #2a8860;
  border-bottom-color: transparent;
  animation: fillPop 0.3s ease;
}

.row-handle {
  color: #ccc;
  font-size: 1.2rem;
  padding-left: 8px;
}

/* ===== Pool ===== */
#pool-area {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 8px 0;
}

.pool-word {
  min-width: 56px;
  height: 56px;
  width: auto;
  padding: 0 10px;
  border-radius: 14px;
  border: 2px solid #3aaa7a;
  background: #fff;
  font-size: 1.5rem;
  font-weight: 900;
  color: #3aaa7a;
  cursor: pointer;
  transition: all 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pool-word:hover:not(:disabled) {
  background: #3aaa7a;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 3px 8px rgba(58,170,122,0.3);
}

.pool-word:disabled {
  border-color: #ddd;
  color: #ccc;
  background: #f5f5f5;
  cursor: default;
}

.pool-word.shake {
  animation: shake 0.4s ease;
}

/* ===== Score ===== */
#score-area {
  text-align: center;
  padding: 4px 0;
}

#score-val {
  font-size: 1.3rem;
  font-weight: 900;
  color: #444;
}

.pt-label {
  font-size: 0.8rem;
  color: #888;
  margin-left: 2px;
}

/* ===== Overlay ===== */
#overlay, #info-dialog, #records-dialog {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

#overlay-card, #info-card, #records-card {
  background: #fff;
  border-radius: 18px;
  padding: 24px 20px;
  max-width: 360px;
  width: 90%;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

#overlay-card h2, #info-card h2, #records-card h2 {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 12px;
  color: #3aaa7a;
}

#overlay-body { margin-bottom: 16px; }

.stars-display {
  text-align: center;
  font-size: 2rem;
  letter-spacing: 6px;
  color: #f0a030;
  margin: 8px 0;
}

.clear-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
}

.clear-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

#overlay-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

#overlay-buttons button {
  padding: 10px 24px;
  border-radius: 10px;
  border: none;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s;
}

.btn-primary {
  background: #3aaa7a;
  color: #fff;
}

.btn-primary:hover { background: #2a8860; }

.btn-secondary {
  background: #eee;
  color: #555;
}

.btn-secondary:hover { background: #ddd; }

/* ===== Info/Records Dialog ===== */
#info-card h3 {
  font-size: 1rem;
  color: #444;
  margin: 12px 0 6px;
}

#info-card ol, #info-card ul {
  padding-left: 20px;
  font-size: 0.85rem;
  color: #555;
  line-height: 1.7;
}

#info-card p {
  font-size: 0.8rem;
  color: #888;
  margin-top: 12px;
  line-height: 1.6;
}

#info-card a { color: #3aaa7a; }

#info-close, #records-close {
  display: block;
  margin: 16px auto 0;
  padding: 10px 32px;
  border-radius: 10px;
  border: 2px solid #3aaa7a;
  background: #fff;
  color: #3aaa7a;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.rec-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.rec-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.rec-title-section { margin-top: 8px; }

.rec-title-header {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 6px;
  color: #444;
}

.rec-title-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 3px 8px;
  border-radius: 6px;
}

.rec-title-row.achieved { color: #555; }
.rec-title-row.current { background: #e8f5ee; color: #2a8860; font-weight: 700; }
.rec-title-row:not(.achieved):not(.current) { color: #ccc; }

#records-reset {
  display: block;
  margin: 24px auto 0;
  padding: 8px 24px;
  border-radius: 8px;
  border: 1px solid #d83030;
  background: #fff;
  color: #d83030;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s;
}

#records-reset:hover { opacity: 1; }

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 12px 0;
  font-size: 0.85rem;
}

footer button {
  background: none;
  border: none;
  color: #3aaa7a;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.footer-sep { color: #ccc; margin: 0 6px; }

/* ===== Animations ===== */
@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

@keyframes slideOut {
  to { transform: translateX(110%); opacity: 0; }
}

@keyframes dropDown {
  from { transform: translateY(-20px); opacity: 0.6; }
  to   { transform: translateY(0); opacity: 1; }
}

@keyframes fillPop {
  0%   { transform: scale(0.5); }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* ===== Responsive ===== */
@media (min-width: 440px) {
  .row-template { font-size: 1.15rem; }
  .pool-word { min-width: 64px; height: 64px; font-size: 1.7rem; }
}
