body {
  margin: 0;
  padding: 0;
  background-color: #f7eed8;
  background-image:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.48) 0, rgba(255, 255, 255, 0.48) 2px, transparent 3px),
    radial-gradient(circle at 78% 32%, rgba(201, 176, 147, 0.11) 0, rgba(201, 176, 147, 0.11) 2px, transparent 3px),
    radial-gradient(circle at 34% 72%, rgba(255, 255, 255, 0.34) 0, rgba(255, 255, 255, 0.34) 1px, transparent 2px),
    linear-gradient(30deg, rgba(160, 132, 109, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(160, 132, 109, 0.05) 87.5%, rgba(160, 132, 109, 0.05)),
    linear-gradient(150deg, rgba(160, 132, 109, 0.05) 12%, transparent 12.5%, transparent 87%, rgba(160, 132, 109, 0.05) 87.5%, rgba(160, 132, 109, 0.05)),
    linear-gradient(90deg, rgba(160, 132, 109, 0.035) 2%, transparent 2.5%, transparent 97%, rgba(160, 132, 109, 0.035) 97.5%, rgba(160, 132, 109, 0.035)),
    linear-gradient(180deg, #f8f0dd 0%, #f4ead3 100%);
  background-size:
    180px 180px,
    220px 220px,
    160px 160px,
    72px 125px,
    72px 125px,
    72px 125px,
    100% 100%;
  background-position:
    0 0,
    0 0,
    0 0,
    0 0,
    0 0,
    0 0,
    0 0;
  /* 和紙の地に、ごく薄い麻の葉を重ねる */
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
  overflow: hidden;
}

.lp-back-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  text-decoration: none;
  font-size: 11px;
  font-weight: bold;
  color: #5c4033;
  background: rgba(255, 250, 244, 0.92);
  border: 1px solid rgba(193, 164, 140, 0.95);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.lp-back-btn:hover {
  background: rgba(255, 244, 232, 0.96);
  border-color: #a68568;
}

.layout-wrapper {
  display: flex;
  gap: 30px;
  align-items: flex-start;
}

.game-column {
  width: 400px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#game-container {
  position: relative;
  width: 400px;
  height: 600px;
  background-color: #fcece0;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
}

#ui-layer {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 3px 7px 2px;
  background: rgba(255, 250, 244, 0.86);
  border: 1px solid rgba(193, 164, 140, 0.75);
  border-radius: 12px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(2px);
}

.ui-left {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.topbar-meta {
  display: flex;
  justify-content: flex-start;
  min-width: 0;
}

.hud-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 4px;
}

.hud-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-top: -4px;
  position: relative;
  top: -1px;
}

.control-buttons {
  display: flex;
  gap: 3px;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: space-between;
  margin: 0;
  width: 100%;
}

.player-name-row {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin: 0 0 0 1px;
  flex: 0 0 116px;
  min-width: 116px;
}

.player-name-inline-label {
  font-size: 10px;
  line-height: 1;
  color: #7b6658;
  font-weight: bold;
  white-space: nowrap;
}

#player-name-input {
  width: 100%;
  max-width: none;
  min-height: 26px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid rgba(193, 164, 140, 0.9);
  background: rgba(255, 250, 244, 0.92);
  color: #5c4033;
  font-size: 10px;
  box-sizing: border-box;
  box-shadow: inset 0 1px 2px rgba(120, 92, 72, 0.08);
}

#player-name-input::placeholder {
  color: #9c8b7d;
}

#player-name-input:focus {
  outline: none;
  border-color: #b77b5b;
  box-shadow: 0 0 0 2px rgba(209, 92, 92, 0.15);
  background: rgba(255, 255, 255, 0.98);
}

.control-buttons button {
  pointer-events: auto;
  min-height: 28px;
  padding: 2px 6px;
  font-size: 10px;
  background-color: rgba(255, 255, 255, 0.84);
  border: 1px solid #c1a48c;
  border-radius: 4px;
  color: #5c4033;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: all 0.2s;
}

#sound-toggle-btn {
  min-width: 52px;
}

.control-buttons button:hover {
  background-color: #f7eed8;
  border-color: #5c4033;
}

.score-slot {
  display: flex;
  justify-content: center;
  min-width: 0;
}

#score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  min-width: 120px;
  padding: 0 11px;
  margin: 0;
  border-radius: 999px;
  border: 1px solid rgba(193, 164, 140, 0.78);
  background: rgba(255, 251, 246, 0.9);
  color: #333;
  font-size: 15px;
  font-weight: bold;
  line-height: 1;
  letter-spacing: 0.01em;
  text-align: center;
  text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.75);
  white-space: nowrap;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  box-sizing: border-box;
}

#next-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.78);
  gap: 1px;
  padding: 2px 6px 3px;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  min-width: 56px;
  flex-shrink: 0;
  justify-self: end;
}

#next-label {
  font-size: 9px;
  font-weight: bold;
  color: #666;
  margin-bottom: 0;
}

#next-item-preview {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  margin-bottom: 0;
}

#next-item-name {
  font-size: 9px;
  font-weight: bold;
  color: #333;
  line-height: 1;
}

.lang-toggle-btn {
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid rgba(193, 164, 140, 0.9);
  background: rgba(255, 248, 240, 0.92);
  color: #6b584b;
  font-size: 9px;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
}

.lang-toggle-btn:hover {
  background: rgba(248, 238, 222, 0.96);
}

#game-over {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 20;
  color: white;
  overflow-y: auto;
  padding: 24px 0 calc(24px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

h2 {
  font-size: 48px;
  margin-bottom: 20px;
  color: #ffcccc;
}

#result-board {
  background-color: rgba(0, 0, 0, 0.4);
  padding: 20px 40px;
  border-radius: 12px;
  text-align: center;
  margin-bottom: 30px;
  border: 2px solid #666;
}

.result-row {
  font-size: 24px;
  margin: 10px 0;
  font-weight: bold;
}

#best-score {
  color: #fbff00;
  /* ゴールド風 */
}

#new-record-badge {
  color: white;
  background-color: #e63946;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 10px;
  vertical-align: middle;
}

.rank-info {
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px dashed rgba(255, 255, 255, 0.4);
  font-size: 18px;
  color: #e0e0e0;
}

.rank-info p {
  margin: 5px 0;
}

#retry-btn {
  margin-top: 20px;
  padding: 10px 30px;
  font-size: 20px;
  background-color: #d15c5c;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s;
}

#retry-btn:hover {
  background-color: #b54a4a;
}

.share-actions {
  display: flex;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.share-btn {
  min-width: 132px;
  padding: 12px 16px;
  border-radius: 999px;
  text-align: center;
  text-decoration: none;
  font-size: 15px;
  font-weight: bold;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.share-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
}

.share-btn-x {
  background: linear-gradient(180deg, #4a4a4a 0%, #222 100%);
  color: #fffaf4;
}

.share-btn-line {
  background: linear-gradient(180deg, #8ecf8a 0%, #5ea85c 100%);
  color: #fffaf4;
}

.ranking-panel {
  width: min(88%, 360px);
  margin-top: 18px;
  margin-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ranking-section {
  background: rgba(255, 248, 240, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(2px);
}

.ranking-title {
  margin: 0 0 10px;
  font-size: 16px;
  color: #ffe7cf;
  letter-spacing: 0.04em;
}

.ranking-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.18);
  font-size: 14px;
}

.ranking-list li:last-child {
  border-bottom: none;
}

.ranking-list span {
  color: #fff7ef;
}

.ranking-list strong {
  color: #ffe59a;
  font-size: 14px;
}

.ranking-you {
  background: linear-gradient(180deg, rgba(219, 163, 163, 0.28) 0%, rgba(173, 133, 116, 0.24) 100%);
}

.your-rank-card {
  border-radius: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  text-align: center;
}

.result-player-name {
  margin: -8px 0 14px;
  font-size: 15px;
  color: #ffe7cf;
  letter-spacing: 0.03em;
}

.your-rank-label {
  font-size: 12px;
  color: #f8dfd2;
  margin-bottom: 6px;
}

.your-rank-value {
  font-size: 28px;
  font-weight: bold;
  color: #fff4de;
  margin-bottom: 4px;
}

.your-rank-score {
  font-size: 13px;
  color: #fbe8c8;
}

/* ルールモーダル */
#rule-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
  pointer-events: auto;
}

.modal-content {
  background-color: #fcf8f2;
  width: 85%;
  max-height: 90%;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  border-radius: 8px;
  box-sizing: border-box;
  overflow-y: auto;
  position: relative;
  color: #5c4033;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  border: 1px solid #e0d5c1;
}

#close-rule-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 24px;
  background: none;
  border: none;
  color: #a08c78;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

#close-rule-btn:hover {
  color: #5c4033;
}

.modal-title {
  font-size: 20px;
  color: #5c4033;
  margin-top: 0;
  margin-bottom: 15px;
  text-align: center;
  border-bottom: 1px dashed #c1a48c;
  padding-bottom: 10px;
}

.rule-description {
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 15px;
}

.rule-description p {
  margin: 5px 0;
}

.lang-en {
  font-size: 11px;
  color: #887a6f;
  border-left: 2px solid #e0d5c1;
  padding-left: 10px;
}

.evolution-example {
  background-color: rgba(255, 255, 255, 0.8);
  padding: 12px;
  border-radius: 6px;
  font-size: 13px;
  border: 1px solid #eee5d8;
}

.modal-ranking-section {
  margin-top: 14px;
  padding: 12px;
  background: rgba(255, 253, 248, 0.88);
  border: 1px solid #e4d7c8;
  border-radius: 8px;
}

.modal-ranking-section h3,
.modal-ranking-section h4 {
  color: #5c4033;
}

.modal-ranking-section h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.modal-ranking-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
}

.modal-rank-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.modal-rank-card {
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 246, 238, 0.95);
  border: 1px solid #ead9ca;
  text-align: center;
}

.modal-rank-label {
  font-size: 11px;
  color: #8f7868;
  margin-bottom: 4px;
}

.modal-rank-value {
  font-size: 20px;
  font-weight: bold;
  color: #5c4033;
  margin-bottom: 4px;
}

.modal-rank-sub {
  font-size: 11px;
  color: #806b5c;
}

.modal-ranking-lists {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.modal-ranking-block {
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid #eadfce;
}

.ranking-list-modal li {
  color: #6e5b4d;
  border-bottom-color: rgba(160, 132, 109, 0.18);
}

.ranking-list-modal span {
  color: #6e5b4d;
}

.ranking-list-modal strong {
  color: #b4664d;
}

.evolution-example h3 {
  font-size: 14px;
  margin-top: 0;
  margin-bottom: 10px;
  color: #5c4033;
}

.evolution-example p {
  margin: 5px 0;
  color: #666;
}

/* サイドバー・進化順ガイド */
.sidebar {
  width: 250px;
  background-color: rgba(255, 255, 255, 0.8);
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  border-radius: 8px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
  border: 1px solid #e0d5c1;
  max-height: 600px;
  overflow-y: auto;
  box-sizing: border-box;
}

.sidebar-title {
  font-size: 22px;
  color: #5c4033;
  margin-top: 0;
  margin-bottom: 10px;
  text-align: center;
  border-bottom: 2px solid #d15c5c;
  padding-bottom: 10px;
}

.sidebar-desc {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
  margin-bottom: 20px;
}

#evolution-guide,
#modal-evolution-guide {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.evo-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 8px;
  background-color: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.evo-item-circle {
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  border: 2px solid rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.4);
}

.evo-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.evo-item-name {
  font-size: 14px;
  font-weight: bold;
  color: #333;
}

.evo-item-name-en {
  font-size: 11px;
  color: #8d7f73;
  line-height: 1.25;
}

.evo-item-level {
  font-size: 11px;
  color: #999;
}

/* スマホ用レスポンシブ対応 */
@media (max-width: 768px) {
  .sidebar {
    display: none;
    /* スマホでは右側のサイドバーを隠す */
  }

  .layout-wrapper {
    gap: 0;
  }

  .game-column {
    width: min(100vw, 400px);
  }
}

@media (max-width: 420px) {
  body {
    align-items: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: calc(env(safe-area-inset-top, 0px) + 16px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    min-height: 100dvh;
    box-sizing: border-box;
  }

  .game-column {
    width: 100vw;
    gap: 4px;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  }

  #game-container {
    width: 100vw;
    height: min(150vw, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 136px));
    /* 比率を2:3（400:600）をベースに、上下UI分の高さを確保 */
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 136px);
    border-radius: 0;
  }

  #ui-layer {
    margin: 0 8px;
    padding: 3px 6px 2px;
    gap: 1px;
    border-radius: 10px;
  }

  #score {
    min-width: 102px;
    min-height: 27px;
    padding: 0 8px;
    font-size: 14px;
  }

  .hud-top {
    gap: 3px;
    align-items: center;
  }

  .hud-bottom {
    gap: 0;
    margin-top: -4px;
    top: -1px;
  }

  #player-name-input {
    min-height: 27px;
    padding: 0 6px;
    font-size: 10px;
  }

  canvas {
    width: 100% !important;
    height: 100% !important;
  }

  #rule-modal {
    position: fixed;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
    /* 画面全体に固定 */
  }

  .share-actions {
    width: min(92vw, 340px);
    gap: 10px;
  }

  .share-btn {
    flex: 1 1 140px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .ranking-panel {
    width: min(92vw, 340px);
    gap: 10px;
    margin-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .modal-rank-summary,
  .modal-ranking-lists {
    grid-template-columns: 1fr;
  }

  .ranking-section {
    padding: 12px 14px;
  }

  .ranking-title {
    font-size: 15px;
  }

  .ranking-list li {
    font-size: 13px;
  }

  .your-rank-value {
    font-size: 24px;
  }

  .evo-item-name-en {
    font-size: 10px;
  }

  .control-buttons {
    flex: 1 1 auto;
    gap: 3px;
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .control-buttons button {
    min-height: 30px;
    padding: 2px 6px;
    font-size: 10px;
  }

  .player-name-row {
    gap: 3px;
    flex: 0 0 102px;
    min-width: 102px;
    margin-left: 0;
  }

  .player-name-inline-label {
    font-size: 9px;
  }

  #next-container {
    min-width: 54px;
    gap: 1px;
    padding: 2px 5px 3px;
  }

  .lp-back-btn {
    min-height: 30px;
    padding: 0 8px;
    font-size: 10px;
  }

  .lang-toggle-btn {
    min-height: 22px;
    padding: 0 7px;
    font-size: 9px;
  }
}
