/* ========================================
   基本スタイル
======================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  max-width: 100%;
  max-height: 100vh;
  padding: 0.5rem 0 0 0.5rem;
  line-height: 1.1;
  font-family: "UD Digi Kyokasho NK-B", "ヒラギノ角ゴ Pro", "Yu Gothic Medium", "游ゴシック Medium", YuGothic, "游ゴシック体", "メイリオ", sans-serif;
  font-size: clamp(18px, 2.5vw, 22px);
  font-weight: 400;
  color: white;
  background-color: #2a4d5a;
  user-select: none;
  overflow-x: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

/* ========================================
   レイアウト
======================================== */

header {
  width: 95%;
  padding: 0.5rem 0;
  margin-top: 0.5rem;
}

header section {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

main {
  width: 95%;
  margin: 0.25rem;
  min-height: calc(100vh - 5rem);
}

/* ========================================
   文字サイズ
======================================== */

h1 {
  font-size: clamp(18px, 3vw, 24px);
  line-height: 1.1;
  margin-top: 0.25rem;
}

h2 {
  margin: 0;
  padding: 0.5rem 0 0 0;
  font-size: clamp(18px, 3vw, 24px);
}

h3 {
  padding: 0.25rem 0 0 0;
  font-size: clamp(18px, 2.8vw, 22px);
}

h4, h6 {
  line-height: 1.1;
  margin-top: 0.25rem;
  font-size: clamp(16px, 2.5vw, 20px);
}

h6 {
  margin: 0.5rem;
}

p {
  margin: 0.25rem;
  font-size: clamp(18px, 2.5vw, 22px);
}

a {
  color: #ffd54f;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ========================================
   黒板スタイル
======================================== */

.kokuban {
  width: 95%;
  min-height: 50vh;
  max-height: 85vh;
  padding: 0.5rem;
  color: #fff;
  background-color: #1a3a3a;
  border: 6px solid #8b7355;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  line-height: 1.2;
  overflow-y: auto;
}

.meate {
  width: 90%;
  margin: 0.5rem 0.5rem 1rem 0.5rem;
  position: relative;
  border: solid 2px #ffb74d;
  border-radius: 4px;
  padding: 0.75rem;
}

.meate .box-title {
  position: absolute;
  display: inline-block;
  padding: 0.25rem 0.5rem;
  top: -0.75rem;
  left: 1rem;
  line-height: 1.1;
  font-weight: bold;
  font-size: clamp(16px, 2.5vw, 20px);
  color: #ffffff;
  border: solid 2px #ffb74d;
  background: #ff8f00;
  border-radius: 6px;
}

.meate p {
  padding-left: 1rem;
  margin: 0.5rem 0;
  padding-top: 0.5rem;
}

/* ========================================
   入力エリア
======================================== */

.input-area {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem;
  margin: 1rem 0;
  padding: 0.5rem;
}

.input-area p {
  margin: 0 0.25rem;
  align-self: flex-end;
  padding-bottom: 0.25rem;
}

input[type="number"] {
  width: clamp(60px, 8vw, 90px);
  height: 45px;
  font-size: clamp(18px, 3vw, 22px);
  text-align: center;
  border: 2px solid #4a7c7e;
  border-radius: 8px;
  padding: 0.25rem;
}

/* ========================================
   計算式エリア
======================================== */

.shiki {
  font-size: clamp(22px, 3.5vw, 28px);
  height: auto;
  margin-top: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  display: flex;
}

#warareru, #waru, #kotae, #amari {
  width: clamp(60px, 8vw, 90px);
  height: 45px;
  line-height: 45px;
  margin: 0.25rem;
  font-size: clamp(18px, 3vw, 22px);
  text-align: center;
  color: #1a1a1a;
  background-color: #ffd54f;
  border: 2px solid #4a7c7e;
  border-radius: 8px;
}

#ko {
  margin-top: 0.75rem;
  font-size: clamp(20px, 3.5vw, 24px);
  color: #d84315;
  background-color: #fff3e0;
  padding: 0.75rem;
  border-radius: 10px;
  border: 2px solid #ffb74d;
}

#kake, #ta {
  margin-left: 1rem;
  color: #ffd54f;
}

/* ========================================
   テーブル
======================================== */

table {
  margin-top: 0.75rem;
  margin-bottom: 0.5rem;
  border: none;
  border-collapse: separate;
  width: 100%;
  max-width: 90vw;
}

#TBL tr:nth-child(odd) td {
  min-width: clamp(60px, 10vw, 100px);
  height: clamp(80px, 12vw, 120px);
  border: 3px double #4a7c7e;
  background-color: #fff3e0;
  border-radius: 8px;
  color: #5d4037;
  text-align: center;
  vertical-align: top;
  padding: 0.25rem;
  overflow-y: auto;
}

.egao {
  background-color: #2a4d5a;
  text-align: center;
  vertical-align: top;
  border: none;
}

.egao img {
  width: clamp(20px, 4vw, 40px);
  height: clamp(20px, 4vw, 40px);
}

/* ========================================
   画像
======================================== */

main img {
  width: clamp(25px, 4vw, 40px);
  height: clamp(25px, 4vw, 40px);
}

#jimi {
  height: clamp(40px, 6vh, 60px);
}

/* ========================================
   スペースエリア
======================================== */

#space {
  width: 90%;
  min-height: clamp(60px, 10vw, 100px);
  max-height: 120px;
  margin: 0.5rem;
  background-color: #f8bbd9;
  border: 2px solid #ad1457;
  border-radius: 10px;
  padding: 0.5rem;
  clear: both;
  overflow-y: auto;
}

/* ========================================
   ボタン
======================================== */

button {
  height: 45px;
  font-size: clamp(18px, 3vw, 22px);
  font-weight: 500;
  font-family: "UD Digi Kyokasho NK-B", "ヒラギノ角ゴ Pro", "Yu Gothic Medium", "游ゴシック Medium", YuGothic, "游ゴシック体", "メイリオ", sans-serif;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  border-radius: 8px;
  padding: 0.25rem 1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.25);
}

#reset {
  color: white;
  background-color: #d84315;
  font-weight: 600;
}

#set {
  color: white;
  margin: 0 0.5rem;
  background-color: #ff8f00;
  font-weight: 600;
}

#answer {
  margin: 0 0.5rem;
  color: #1a1a1a;
  background-color: #ffd54f;
  border: 2px solid #4a7c7e;
  font-weight: 600;
}

#erase {
  margin: 0 0.5rem;
  color: white;
  background-color: #689f38;
  font-weight: 600;
}

/* ========================================
   トースト通知
======================================== */

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: #2a4d5a;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  border: 2px solid #4a7c7e;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  max-width: 300px;
  transform: translateX(400px);
  transition: transform 0.3s ease;
}

.toast.show {
  transform: translateX(0);
}

.toast h4 {
  margin: 0 0 0.5rem 0;
  color: #ffd54f;
  font-size: 16px;
}

.toast p {
  margin: 0.25rem 0;
  font-size: 14px;
  line-height: 1.3;
}

.toast-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: #ffd54f;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-close:hover {
  background-color: rgba(255, 213, 79, 0.2);
  border-radius: 50%;
}

/* ========================================
   ドラッグ可能な要素
======================================== */

.draggable-elem {
  cursor: move;
  touch-action: none;
}

.droppable-elem {
  position: relative;
}

/* ========================================
   レスポンシブデザイン
======================================== */

@media (max-width: 768px) {
  body {
    padding: 0.25rem;
    font-size: 18px;
  }

  header section {
    flex-direction: column !important;
    align-items: center;
    gap: 1rem;
  }

  h1 {
    font-size: 24px;
    text-align: center;
  }

  .meate {
    width: 95%;
    margin: 0.5rem;
  }

  .input-area {
    justify-content: center;
  }

  .shiki {
    justify-content: center;
  }

  input[type="number"], #warareru, #waru, #kotae, #amari {
    width: 70px;
    height: 40px;
    line-height: 40px;
    font-size: 18px;
  }

  #space {
    width: 95%;
    margin: 0.5rem auto;
  }

  table {
    width: 100%;
    overflow-x: auto;
    display: block;
  }

  #TBL tr:nth-child(odd) td {
    min-width: 80px;
    height: 90px;
  }

  button {
    height: 40px;
    font-size: 18px;
    padding: 0.25rem 0.75rem;
    border-radius: 8px;
  }

  .toast {
    right: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
  }
}

@media (max-width: 480px) {
  body {
    font-size: 16px;
  }

  h1 {
    font-size: 20px;
  }

  input[type="number"], #warareru, #waru, #kotae, #amari {
    width: 60px;
    height: 35px;
    line-height: 35px;
    font-size: 16px;
  }

  button {
    height: 35px;
    font-size: 16px;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
  }

  .kokuban {
    padding: 0.5rem;
    border-width: 4px;
  }

  #TBL tr:nth-child(odd) td {
    min-width: 70px;
    height: 80px;
  }

  main img {
    width: 25px;
    height: 25px;
  }

  .egao img {
    width: 25px;
    height: 25px;
  }
}