.keyboard {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2;
}

.key-row {
  display: flex;
  gap: 10px;
}

.key-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 15px 25px;
  border-radius: 25px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
}

.key-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.japanese-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 1920px;
  height: 1080px;
  z-index: 3;
  display: none;
  justify-content: center;
  align-items: flex-start;
  animation: fadeIn 0.3s ease-in-out;
  background: transparent;
  overflow: hidden;
}

.japanese-popup.show {
  display: flex;
}

.popup-content {
  position: relative;
  background: transparent;
  border-radius: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  box-shadow: none;
  animation: slideIn 0.3s ease-out;
  border: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 1400px;
  margin: 0 auto;
  min-height: 600px;
  overflow-y: -webkit-paged-y;
}

.charts-container {
  position: relative;
  top: auto;
  right: auto;
  transform: none;
  display: flex;
  gap: 20px;
  justify-content: center;
  align-items: stretch;
  padding: 0;
  width: 100%;
  max-width: 1400px;
  margin-top: 20px;
}

.chart-section {
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  border: none;
  min-width: 500px;
  height: 100%;
  align-items: stretch;
  justify-content: space-between;
}

.score-input-container {
  position: relative;
  display: flex;
  align-items: center;
  gap: 24px;
  background: transparent;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  justify-content: flex-start;
  align-items: flex-start;
  margin-bottom: 40px;
  margin-top: 260px;
}

.score-unit {
  display: block;
  color: #000;
  font-size: 42px;
  font-weight: bold;
  margin-left: 6px;
}

.score-input-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 500px;
  width: 100%;
  max-width: 1200px;
  flex: 1;
  margin-left: 0;
  margin-right: 0;
}

.ranking-text {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  text-align: start;
}

.ranking-line-1,
.ranking-line-2 {
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
  font-size: 36px;
  color: #000;
  font-weight: bold;
  margin: 0;
  text-shadow: 0 1px 0 #fff, 0 -1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff,
    1px 1px 0 #fff, -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff,
    2px 0 0 #fff, -2px 0 0 #fff, 0 2px 0 #fff, 0 -2px 0 #fff, 2px 2px 0 #fff,
    -2px -2px 0 #fff;
  line-height: 1.1;
}

.ranking-line-1 ruby {
  letter-spacing: -3px;
}

.ranking-line-2 ruby {
  margin-bottom: 10px;
}

.name-input {
  padding: 20px 30px;
  border: 4px solid #000;
  border-radius: 12px;
  font-family: "Arial", sans-serif !important;
  font-size: 24px;
  font-weight: bold;
  text-align: start;
  background: white;
  transition: all 0.3s ease;
  width: 90%;
  margin: 0;
}

.name-input:focus {
  outline: none;
  border-color: #3498db;
}

.name-input:focus {
  outline: none;
  border-color: #3498db;
}

.chart-section:nth-child(1),
.chart-section:nth-child(2) {
  flex: 3;
  min-width: 400px;
}

.chart-section:nth-child(3) {
  flex: 1;
  min-width: 0;
  max-width: 250px;
  padding: 20px 15px;
  justify-content: space-between;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.chart-section:nth-child(4) {
  flex: 1;
  min-width: 0;
  max-width: 200px;
  padding: 0;
  justify-content: center;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  border: none;
}

/* Main keyboard section - expands when in QWERTY mode */
#main-keyboard-section {
  flex: 3;
  min-width: 400px;
}

#main-keyboard-section.qwerty-mode {
  flex: 6;
  min-width: 800px;
  max-width: 1000px;
}

.japanese-keyboard-content,
.qwerty-keyboard-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qwerty-keyboard-content {
  flex-direction: column;
}

.japanese-characters {
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  width: 100%;
}

.char-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
}

.char-row:last-child {
  margin-bottom: 0;
}

.row-yellow .char-cell {
  background-color: #e3e3a1;
}

.row-grey .char-cell {
  background-color: #f5f5f5;
}

.char-cell {
  border: 1px solid #ddd;
  border-radius: 6px;
  width: 75px;
  height: 75px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
  font-size: 32px;
  font-weight: bold;
  color: #333;
  transition: all 0.2s ease;
  cursor: pointer;
}

.char-cell:hover {
  transform: translateY(-2px);
  border-color: #999;
}

.empty-cell {
  background-color: #e3e3a1;
  cursor: default;
}

.empty-cell:hover {
  transform: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  border-color: #ddd;
}

.virtual-keyboard {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.input-mode-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  justify-content: center;
}

.mode-btn {
  background-color: #f0f0f0;
  border: 2px solid #ccc;
  border-radius: 6px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
  font-size: 14px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
}

.mode-btn.romaji-btn ruby {
  margin-bottom: 6px;
}

.mode-btn:hover {
  background-color: #e0e0e0;
  transform: translateY(-1px);
}

.mode-btn.active {
  background-color: #ff4444;
  border-color: #cc3333;
  color: white;
}

.mode-btn.active:hover {
  background-color: #ff3333;
  transform: translateY(-1px);
}

.symbol-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  height: 20%;
  align-items: center;
}

.function-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;
  height: 20%;
  align-items: center;
}

.ok-row {
  display: flex;
  justify-content: center;
  width: 100%;
  height: 20%;
  align-items: center;
  margin-top: 5px;
}

.symbol-btn {
  background-color: #e3e3a1;
  border: 2px solid #ddd;
  border-radius: 8px;
  width: 50%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
  font-size: 24px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.symbol-btn:hover {
  background-color: #d0d0a0;
  transform: translateY(-2px);
  border-color: #999;
}

.function-btn {
  background-color: #f5f5f5;
  border: 2px solid #ddd;
  border-radius: 8px;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
  font-size: 11px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.function-btn:hover {
  background-color: #e5e5e5;
  transform: translateY(-2px);
  border-color: #999;
}

.wide-btn {
  flex: 2;
  min-width: 160px;
}

.ok-btn {
  background-color: #ff4444;
  border: 2px solid #cc3333;
  border-radius: 10px;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
  font-size: 18px;
  font-weight: bold;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.ok-btn:hover {
  background-color: #ff3333;
  transform: translateY(-3px);
  border-color: #aa2222;
}

/* Large Desktop */
@media (max-width: 1600px) {
  .popup-content {
    max-width: 95%;
    width: 95%;
    min-height: 600px;
    overflow-y: -webkit-paged-y;
  }

  .charts-container {
    gap: 15px;
  }
}

/* Desktop */
@media (max-width: 1400px) {
  .popup-content {
    max-width: 95%;
    width: 95%;
    min-height: 600px;
    overflow-y: -webkit-paged-y;
  }

  .chart-section:nth-child(1),
  .chart-section:nth-child(2) {
    max-width: 450px;
    min-width: 400px;
  }

  .chart-section:nth-child(3) {
    max-width: 200px;
    min-width: 180px;
  }

  .chart-section:nth-child(4) {
    max-width: 200px;
    min-width: 180px;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border: none;
    padding: 0;
  }

  .char-cell {
    width: 70px;
    height: 70px;
    font-size: 30px;
  }

  .qwerty-key {
    width: 60px;
    height: 60px;
    font-size: 24px;
  }
}

/* Laptop */
@media (max-width: 1200px) {
  .popup-content {
    max-width: 95%;
    width: 95%;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 600px;
    overflow-y: -webkit-paged-y;
  }

  .charts-container {
    flex-direction: row;
    gap: 20px;
    margin-top: 10px;
    max-width: 100%;
  }

  .score-input-container {
    padding: 20px;
    padding-left: 100px;
    align-items: center;
    gap: 20px;
  }

  .ranking-line-1 {
    font-size: 1.2rem;
  }

  .ranking-line-2 {
    font-size: 1rem;
  }
}

/* Tablet Landscape */
@media (max-width: 1024px) {
  .popup-content {
    max-width: 98%;
    width: 98%;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 20px;
    min-height: 600px;
    overflow-y: -webkit-paged-y;
  }

  .charts-container {
    flex-direction: row;
    gap: 20px;
    margin-top: 10px;
    width: 100%;
    max-width: 100%;
  }

  .score-input-container {
    padding: 20px;
    padding-left: 100px;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 100%;
    margin-bottom: 30px;
  }

  .score-input-content {
    min-width: 300px;
    max-width: 100%;
  }

  .char-cell {
    width: 65px;
    height: 65px;
    font-size: 28px;
  }

  .qwerty-key {
    width: 55px;
    height: 55px;
    font-size: 22px;
  }
}

/* Tablet Portrait */
@media (max-width: 896px) {
  .popup-content {
    padding: 15px;
    min-height: 600px;
    overflow-y: -webkit-paged-y;
  }

  .score-input-container {
    padding-left: 80px;
  }

  .score-input-content {
    min-width: 280px;
    max-width: 100%;
  }

  .charts-container {
    gap: 15px;
  }

  .chart-section:nth-child(1),
  .chart-section:nth-child(2) {
    max-width: 380px;
    min-width: 350px;
  }

  .chart-section:nth-child(3) {
    max-width: 180px;
    min-width: 160px;
  }

  .chart-section:nth-child(4) {
    max-width: 180px;
    min-width: 160px;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border: none;
    padding: 0;
  }

  .char-cell {
    width: 60px;
    height: 60px;
    font-size: 26px;
  }

  .qwerty-key {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }

  .symbol-btn {
    width: 45px;
    height: 45px;
    font-size: 20px;
  }

  .function-btn {
    width: 70px;
    height: 35px;
    font-size: 11px;
  }

  .ok-btn {
    width: 100px;
    height: 45px;
    font-size: 16px;
  }
}

/* Mobile Landscape */
@media (max-width: 768px) {
  .charts-container {
    max-width: 100%;
    margin-top: 5px;
    order: 2;
    width: 100%;
  }

  .popup-content {
    padding: 20px;
    width: calc(100% - 40px);
    max-width: 100%;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: scroll;
    padding-top: 0px;
    -webkit-overflow-scrolling: touch;
    margin-top: 0;
    margin-bottom: 0;
    min-height: 600px;
    overflow-y: -webkit-paged-y;
  }

  .score-input-container {
    padding: 20px;
    padding-left: 20px;
    margin-bottom: 25px;
    margin-top: 0px;
    width: 100%;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-left: 0;
    margin-right: 0;
    order: 1;
  }

  .score-input-content {
    min-width: 250px;
    max-width: 100%;
    width: 100%;
    text-align: center;
  }

  .chart-section {
    padding: 8px;
  }

  .chart-section:nth-child(4) {
    padding: 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border: none;
  }

  .score-unit {
    font-size: 28px;
  }

  .ranking-line-1,
  .ranking-line-2 {
    font-size: 28px;
  }

  .name-input {
    width: 100%;
    padding: 16px 24px;
    font-size: 20px;
  }

  .char-cell {
    width: 60px;
    height: 60px;
    font-size: 26px;
  }

  .char-row {
    margin-bottom: 10px;
    justify-content: space-between;
  }

  .key-btn {
    padding: 12px 20px;
    font-size: 14px;
  }

  .charts-container {
    gap: 25px;
    margin-top: 0px;
    order: 2;
    width: 100%;
    max-width: 100%;
  }

  .symbol-btn {
    width: 45px;
    height: 45px;
    font-size: 20px;
  }

  .function-btn {
    width: 70px;
    height: 35px;
    font-size: 11px;
  }

  .ok-btn {
    width: 100px;
    height: 45px;
    font-size: 16px;
  }

  .mode-btn {
    font-size: 13px;
    padding: 10px 14px;
  }

  .qwerty-key {
    width: 50px;
    height: 50px;
    font-size: 20px;
  }

  .qwerty-row {
    gap: 4px;
  }
}

/* Mobile Portrait */
@media (max-width: 480px) {
  .popup-content {
    padding: 15px;
    width: calc(100% - 30px);
    max-width: 100%;
    height: 100vh;
    overflow-x: hidden;
    overflow-y: scroll;
    padding-top: 0px;
    -webkit-overflow-scrolling: touch;
    margin-top: 0;
    margin-bottom: 0;
    min-height: 600px;
    overflow-y: -webkit-paged-y;
  }

  .score-input-container {
    padding: 15px;
    padding-left: 15px;
    margin-bottom: 20px;
    margin-top: 0px;
    width: 100%;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-left: 0;
    margin-right: 0;
    order: 1;
  }

  .score-input-content {
    min-width: 200px;
    max-width: 100%;
    width: 100%;
    text-align: center;
  }

  .chart-section {
    padding: 6px;
  }

  .chart-section:nth-child(4) {
    padding: 0;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border: none;
  }

  .score-unit {
    font-size: 24px;
  }

  .ranking-line-1,
  .ranking-line-2 {
    font-size: 24px;
  }

  .name-input {
    padding: 14px 20px;
    font-size: 18px;
  }

  .char-cell {
    width: 50px;
    height: 50px;
    font-size: 22px;
  }

  .char-row {
    margin-bottom: 8px;
    justify-content: space-between;
  }

  .key-btn {
    padding: 10px 16px;
    font-size: 12px;
  }

  .keyboard {
    bottom: 15px;
    right: 15px;
  }

  .symbol-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .function-btn {
    width: 60px;
    height: 30px;
    font-size: 10px;
  }

  .ok-btn {
    width: 90px;
    height: 40px;
    font-size: 14px;
  }

  .mode-btn {
    font-size: 11px;
    padding: 8px 12px;
  }

  .qwerty-key {
    width: 45px;
    height: 45px;
    font-size: 18px;
  }

  .qwerty-row {
    gap: 3px;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.9);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.popup-content::-webkit-scrollbar {
  width: 12px;
}

.popup-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  margin: 10px 0;
}

.popup-content::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.popup-content::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.popup-content::-webkit-scrollbar-thumb:active {
  background: linear-gradient(135deg, #4e5bc6 0%, #5e377e 100%);
}

.popup-content {
  scrollbar-width: thin;
  scrollbar-color: #667eea rgba(255, 255, 255, 0.1);
}

.qwerty-keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.qwerty-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.qwerty-row.number-row .qwerty-key {
  font-weight: normal !important;
}

.qwerty-key {
  background-color: #e3e3a1;
  border: 2px solid #ddd;
  border-radius: 8px;
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "FGP-Marugothic", "Hiragino Sans", "Yu Gothic", "Meiryo",
    sans-serif;
  font-size: 28px;
  font-weight: bold;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.qwerty-row:nth-child(1) .qwerty-key {
  background-color: #e3e3a1;
}

.qwerty-row:nth-child(2) .qwerty-key {
  background-color: #f5f5f5;
}

.qwerty-row:nth-child(3) .qwerty-key {
  background-color: #e3e3a1;
}

.qwerty-row:nth-child(4) .qwerty-key {
  background-color: #f5f5f5;
}

.qwerty-key:hover {
  background-color: #d0d0d0;
  transform: translateY(-2px);
  border-color: #999;
}

.qwerty-key:active {
  transform: translateY(0);
}

.qwerty-row:nth-child(5) .qwerty-key {
  background-color: #e3e3a1;
}

.qwerty-row:nth-child(6) .qwerty-key {
  background-color: #f5f5f5;
}

.qwerty-key.function-key {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: 2px solid #5a6fd8;
  font-size: 16px;
  min-width: 120px;
  font-weight: bold;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
}

.qwerty-key.function-key:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  border-color: #4e5bc6;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.qwerty-key.function-key:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.caps-lock-key {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: 2px solid #5a6fd8;
  font-size: 16px;
  min-width: 120px;
  font-weight: bold;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
}

.caps-lock-key:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  border-color: #4e5bc6;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.caps-lock-key:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.caps-lock-key.active {
  background: #4caf50 !important;
  color: white;
  border-color: #45a049 !important;
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.qwerty-key.spacer {
  width: 100%;
  cursor: default;
  background: #e3e3a1;
}

.qwerty-row:nth-child(7) .qwerty-key {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: 2px solid #5a6fd8;
  font-size: 16px;
  min-width: 120px;
  font-weight: bold;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  transition: all 0.3s ease;
}

.qwerty-row:nth-child(7) .qwerty-key:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
  border-color: #4e5bc6;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.qwerty-row:nth-child(7) .qwerty-key:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
