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

/* Map Screen Styles */
.map-screen {
	margin: 20px auto;
	text-align: center;
}

#mapCanvas {
	border: 2px solid #4ecdc4;
	border-radius: 10px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
	background: #1a1a1a;
	image-rendering: pixelated;
	image-rendering: -moz-crisp-edges;
	image-rendering: crisp-edges;
}

.map-instructions {
	margin-top: 15px;
	font-size: 1.1em;
	color: #4ecdc4;
	text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

body {
	font-family: "Courier New", monospace;
	background: linear-gradient(135deg, #1e1e2e 0%, #2d1b69 100%);
	color: #e0e0e0;
	min-height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 20px;
	/* Enable smooth scrolling on mobile */
	overflow-x: hidden;
}

.game-container {
	max-width: 1200px;
	width: 100%;
	background: rgba(30, 30, 46, 0.95);
	border-radius: 20px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
	padding: 30px;
}

.title-container {
	text-align: center;
	margin-bottom: 30px;
}

.title-logo {
	width: 128px;
	height: 64px;
	image-rendering: pixelated;
	image-rendering: -moz-crisp-edges;
	image-rendering: crisp-edges;
	filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3));
}

.game-phase {
	text-align: center;
	font-size: 1.3em;
	font-weight: bold;
	padding: 10px;
	margin: 20px 0;
	border-radius: 10px;
	transition: all 0.3s ease;
}

.game-phase.ready {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: #fff;
	animation: pulse 2s infinite;
}

.game-phase.preparation {
	background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
	color: #fff;
	animation: pulse 1s infinite;
}

.game-phase.battle {
	background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
	color: #333;
}

.battle-area {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 30px;
	margin-bottom: 30px;
}

.character-card {
	background: rgba(255, 255, 255, 0.05);
	border-radius: 15px;
	padding: 20px;
	border: 2px solid rgba(255, 255, 255, 0.1);
	transition: all 0.3s ease;
}

.character-card.active {
	border-color: #4ecdc4;
	box-shadow: 0 0 20px rgba(78, 205, 196, 0.3);
}

.character-card.damaged {
	animation: shake 0.5s;
	border-color: #ff6b6b;
}

.character-card.healed {
	animation: glow 0.5s;
	border-color: #4ecdc4;
}

@keyframes shake {
	0%,
	100% {
		transform: translateX(0);
	}
	25% {
		transform: translateX(-5px);
	}
	75% {
		transform: translateX(5px);
	}
}

@keyframes glow {
	0%,
	100% {
		box-shadow: 0 0 20px rgba(78, 205, 196, 0.3);
	}
	50% {
		box-shadow: 0 0 30px rgba(78, 205, 196, 0.8);
	}
}

@keyframes pulse {
	0% {
		transform: scale(1);
	}
	50% {
		transform: scale(1.02);
	}
	100% {
		transform: scale(1);
	}
}

.character-name {
	font-size: 1.5em;
	margin-bottom: 10px;
	color: #4ecdc4;
}

.enemy-name {
	color: #ff6b6b;
}

.stats {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.stat-bar {
	position: relative;
	background: rgba(0, 0, 0, 0.3);
	border-radius: 10px;
	height: 30px;
	overflow: hidden;
}

.stat-fill {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	border-radius: 10px;
	transition: width 0.5s ease;
}

.hp-fill {
	background: linear-gradient(90deg, #ff6b6b, #ff8787);
}

.mp-fill {
	background: linear-gradient(90deg, #4ecdc4, #6ee7df);
}

.stat-text {
	position: relative;
	z-index: 1;
	text-align: center;
	line-height: 30px;
	font-weight: bold;
	text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.character-stats {
	margin-top: 10px;
	padding: 8px;
	background: rgba(0, 0, 0, 0.2);
	border-radius: 8px;
	border: 1px solid rgba(255, 255, 255, 0.1);
}

.character-stat {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 4px;
	font-size: 0.9em;
}

.character-stat:last-child {
	margin-bottom: 0;
}

.stat-label {
	color: #ccc;
	font-weight: 500;
}

.stat-value {
	color: #4ecdc4;
	font-weight: bold;
	min-width: 30px;
	text-align: right;
}

.buffs {
	margin-top: 10px;
	display: flex;
	gap: 5px;
	flex-wrap: wrap;
}

.buff {
	background: rgba(255, 255, 255, 0.1);
	padding: 5px 10px;
	border-radius: 5px;
	font-size: 0.9em;
}

.buff.shield {
	background: rgba(78, 205, 196, 0.3);
	border: 1px solid #4ecdc4;
}

.buff.power {
	background: rgba(255, 193, 7, 0.3);
	border: 1px solid #ffc107;
}

.code-editor {
	background: #1a1a2e;
	border-radius: 10px;
	padding: 20px;
	margin-bottom: 20px;
	border: 2px solid rgba(78, 205, 196, 0.3);
}

.code-input {
	width: 100%;
	min-height: 100px;
	background: rgba(0, 0, 0, 0.3);
	color: #4ecdc4;
	border: 1px solid rgba(78, 205, 196, 0.3);
	border-radius: 5px;
	padding: 10px;
	font-family: "Courier New", monospace;
	font-size: 14px;
	resize: vertical;
}

.code-info {
	display: flex;
	justify-content: space-between;
	margin-top: 10px;
	color: #888;
}

.controls {
	display: flex;
	gap: 10px;
	margin-bottom: 20px;
}

button {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: white;
	border: none;
	padding: 12px 24px;
	border-radius: 8px;
	font-size: 16px;
	cursor: pointer;
	transition: all 0.3s ease;
	font-weight: bold;
}

button:hover {
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

button:disabled {
	background: #555;
	cursor: not-allowed;
	transform: none;
}

.help-panel {
	background: rgba(255, 255, 255, 0.05);
	border-radius: 10px;
	padding: 20px;
	margin-bottom: 20px;
}

.help-title {
	font-size: 1.3em;
	color: #4ecdc4;
	margin-bottom: 10px;
}

.spell-list {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: 10px;
}

.spell-item {
	background: rgba(0, 0, 0, 0.3);
	padding: 10px;
	border-radius: 5px;
	border-left: 3px solid #4ecdc4;
}

.spell-name {
	color: #ffc107;
	font-weight: bold;
}

.spell-cost {
	color: #888;
	font-size: 0.9em;
}

.battle-log {
	background: rgba(0, 0, 0, 0.3);
	border-radius: 10px;
	padding: 15px;
	max-height: 200px;
	overflow-y: auto;
}

.log-entry {
	margin-bottom: 5px;
	padding: 5px;
	border-left: 3px solid #4ecdc4;
	padding-left: 10px;
	animation: slideIn 0.3s ease;
}

@keyframes slideIn {
	from {
		opacity: 0;
		transform: translateX(-20px);
	}
	to {
		opacity: 1;
		transform: translateX(0);
	}
}

.log-entry.damage {
	border-left-color: #ff6b6b;
}

.log-entry.heal {
	border-left-color: #4ecdc4;
}

.log-entry.buff {
	border-left-color: #ffc107;
}

.level-info {
	text-align: center;
	margin-bottom: 20px;
	font-size: 1.2em;
}

.level-info span {
	color: #ffc107;
	font-weight: bold;
}

.exp-info {
	text-align: center;
	margin-bottom: 20px;
}

.exp-label {
	font-size: 1em;
	margin-bottom: 5px;
	color: #e0e0e0;
}

.exp-label span {
	color: #4ecdc4;
	font-weight: bold;
}

.exp-bar {
	position: relative;
	background: rgba(0, 0, 0, 0.3);
	border-radius: 10px;
	height: 20px;
	overflow: hidden;
	max-width: 300px;
	margin: 0 auto;
	border: 1px solid rgba(78, 205, 196, 0.3);
}

.exp-fill {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	background: linear-gradient(90deg, #4ecdc4, #45b7d1);
	border-radius: 10px;
	transition: width 0.5s ease;
}

.casting-bar {
	position: relative;
	background: rgba(0, 0, 0, 0.3);
	border-radius: 5px;
	height: 20px;
	margin-top: 10px;
	overflow: hidden;
}

.casting-fill {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	background: linear-gradient(90deg, #ffc107, #ffeb3b);
	transition: width 0.1s linear;
}

.casting-label {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: #fff;
	font-size: 0.9em;
	font-weight: bold;
	text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
	z-index: 10;
	white-space: nowrap;
}

.preparation-fill {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	background: linear-gradient(90deg, #9c27b0, #e91e63);
	transition: width 0.1s linear;
}

.preparation-bar {
	background: rgba(156, 39, 176, 0.2);
	position: relative;
}

.preparation-label {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	color: #fff;
	font-size: 0.9em;
	font-weight: bold;
	text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
	z-index: 10;
	white-space: nowrap;
}

.error-msg {
	color: #ff6b6b;
	margin-top: 10px;
	padding: 10px;
	background: rgba(255, 107, 107, 0.1);
	border-radius: 5px;
	border: 1px solid #ff6b6b;
}

/* Responsive styles for mobile devices */
@media (max-width: 768px) {
	body {
		padding: 10px;
		align-items: flex-start;
		padding-top: 20px;
	}

	.game-container {
		padding: 15px;
		border-radius: 10px;
	}

	.title-logo {
		width: 192px;
		height: 96px;
	}

	/* Map screen mobile optimization */
	.map-screen {
		margin: 10px auto;
	}

	#mapCanvas {
		max-width: 100%;
		width: 100%;
		height: auto;
		/* Make canvas responsive */
		max-height: 60vh;
	}

	.map-instructions {
		font-size: 0.9em;
		margin-top: 10px;
	}

	/* Battle area mobile layout */
	.battle-area {
		grid-template-columns: 1fr;
		gap: 15px;
		margin-bottom: 20px;
	}

	.character-card {
		padding: 15px;
	}

	.character-name {
		font-size: 1.2em;
	}

	/* Code editor mobile optimization */
	.code-editor {
		padding: 15px;
		margin-bottom: 15px;
	}

	.code-input {
		min-height: 80px;
		font-size: 16px; /* Prevent iOS zoom */
	}

	.code-info {
		flex-direction: column;
		gap: 5px;
		font-size: 0.9em;
	}

	/* Controls mobile layout */
	.controls {
		flex-direction: column;
		gap: 8px;
		margin-bottom: 15px;
	}

	button {
		padding: 15px 20px; /* Larger touch targets */
		font-size: 16px;
	}

	/* Help panel mobile optimization */
	.help-panel {
		padding: 15px;
		margin-bottom: 15px;
	}

	.spell-list {
		grid-template-columns: 1fr;
		gap: 8px;
	}

	/* Battle log mobile optimization */
	.battle-log {
		max-height: 150px;
		padding: 10px;
	}

	.log-entry {
		font-size: 0.9em;
		padding: 3px;
		padding-left: 8px;
	}

	/* Level info mobile optimization */
	.level-info {
		font-size: 1em;
		margin-bottom: 15px;
	}

	/* Exp info mobile optimization */
	.exp-info {
		margin-bottom: 15px;
	}

	.exp-label {
		font-size: 0.9em;
	}

	.exp-bar {
		height: 18px;
		max-width: 250px;
	}

	/* Progress bars mobile optimization */
	.casting-bar,
	.preparation-bar {
		height: 25px; /* Slightly larger for better visibility */
	}

	.casting-label,
	.preparation-label {
		font-size: 0.8em;
	}

	/* Game phase mobile optimization */
	.game-phase {
		font-size: 1.1em;
		padding: 8px;
		margin: 15px 0;
	}

	/* Stat bars mobile optimization */
	.stat-bar {
		height: 25px;
	}

	.stat-text {
		line-height: 25px;
		font-size: 0.9em;
	}

	/* Buffs mobile optimization */
	.buff {
		font-size: 0.8em;
		padding: 3px 6px;
	}
}

/* Modal Styles */
.modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.7);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
	animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

.modal-content {
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	border-radius: 15px;
	padding: 30px;
	max-width: 400px;
	width: 90%;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
	animation: slideUp 0.3s ease;
	text-align: center;
}

@keyframes slideUp {
	from {
		transform: translateY(30px);
		opacity: 0;
	}
	to {
		transform: translateY(0);
		opacity: 1;
	}
}

.modal-title {
	color: #fff;
	font-size: 1.8em;
	margin-bottom: 15px;
	text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.modal-message {
	color: #f0f0f0;
	font-size: 1.1em;
	margin-bottom: 25px;
}

.modal-buttons {
	display: flex;
	gap: 15px;
	justify-content: center;
}

.modal-button {
	padding: 12px 25px;
	border: none;
	border-radius: 8px;
	font-size: 1em;
	font-weight: bold;
	cursor: pointer;
	transition: all 0.3s ease;
	min-width: 120px;
}

.modal-button-primary {
	background: linear-gradient(135deg, #ff6b6b 0%, #ff8787 100%);
	color: white;
	box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}

.modal-button-primary:hover {
	transform: translateY(-2px);
	box-shadow: 0 6px 20px rgba(255, 107, 107, 0.4);
}

.modal-button-secondary {
	background: rgba(255, 255, 255, 0.2);
	color: white;
	border: 2px solid rgba(255, 255, 255, 0.3);
}

.modal-button-secondary:hover {
	background: rgba(255, 255, 255, 0.3);
	border-color: rgba(255, 255, 255, 0.5);
}

/* Username input styles */
.username-input {
	width: 100%;
	padding: 12px;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
	font-size: 1.1em;
	margin: 20px 0;
	transition: all 0.3s ease;
}

.username-input:focus {
	outline: none;
	border-color: #4ecdc4;
	background: rgba(255, 255, 255, 0.15);
	box-shadow: 0 0 10px rgba(78, 205, 196, 0.3);
}

.username-input::placeholder {
	color: rgba(255, 255, 255, 0.5);
}

/* Username change button */
.username-change-btn {
	background: rgba(78, 205, 196, 0.2);
	border: 1px solid #4ecdc4;
	color: #4ecdc4;
	padding: 4px 8px;
	border-radius: 5px;
	cursor: pointer;
	font-size: 0.9em;
	margin-left: 10px;
	transition: all 0.3s ease;
}

.username-change-btn:hover {
	background: rgba(78, 205, 196, 0.3);
	transform: translateY(-1px);
}

/* Touch-friendly map navigation */
.map-controls {
	display: none;
	grid-template-columns: repeat(3, 1fr);
	grid-template-rows: repeat(3, 1fr);
	gap: 5px;
	max-width: 200px;
	margin: 15px auto;
}

.map-control-btn {
	background: rgba(78, 205, 196, 0.2);
	border: 2px solid #4ecdc4;
	color: #4ecdc4;
	padding: 15px;
	border-radius: 8px;
	font-size: 18px;
	cursor: pointer;
	transition: all 0.3s ease;
	display: flex;
	justify-content: center;
	align-items: center;
	user-select: none;
	-webkit-user-select: none;
	-webkit-touch-callout: none;
}

.map-control-btn:active {
	background: rgba(78, 205, 196, 0.4);
	transform: scale(0.95);
}

.map-control-btn.empty {
	opacity: 0;
	pointer-events: none;
}

@media (max-width: 768px) {
	.map-controls {
		display: grid;
	}
}

/* Prevent text selection on touch */
@media (max-width: 768px) {
	* {
		-webkit-touch-callout: none;
		-webkit-user-select: none;
		-khtml-user-select: none;
		-moz-user-select: none;
		-ms-user-select: none;
		user-select: none;
	}

	/* Allow text selection for input elements */
	input, textarea, .code-input {
		-webkit-user-select: text;
		-khtml-user-select: text;
		-moz-user-select: text;
		-ms-user-select: text;
		user-select: text;
	}

	/* Mobile-specific adjustments for cast instruction */
	.cast-instruction {
		display: none !important;
	}

	/* Add mobile cast button hint */
	.code-info::after {
		content: "下の「魔術詠唱」ボタンで詠唱";
		color: #4ecdc4;
		margin-left: 10px;
	}
}

#playerImage {
  width: 96px;
  height: 144px;
  background-image: url(assets/witches/blue/idle.png);
  background-size: cover;
  background-position: 0 0;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  animation: idle 1s steps(5) infinite;
  margin-right: auto;
}

@keyframes idle {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -720px;
  }
}

.character-image-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 192px;
}

#playerImage.casting {
  width: 144px;
  height: 120px;
  background-image: url(assets/witches/blue/charge.png);
  animation: casting 1s steps(4) infinite;
}

@keyframes casting {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -600px;
  }
}

#playerImage.execute {
  width: 312px;
  height: 138px;
  background-image: url(assets/witches/blue/attack.png);
  animation: execute 1s steps(8) infinite;
}

@keyframes execute {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -1104px;
  }
}

#enemyImage {
  width: 96px;
  height: 192px;
  transform: scaleX(-1);
  background-image: url(assets/witches/red/idle.png);
  background-size: cover;
  background-position: 0 0;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  animation: tallIdle 1s steps(5) infinite;
  margin-left: auto;
}

@keyframes tallIdle {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -960px;
  }
}

#enemyImage.casting {
  width: 465px;
  height: 195px;
  background-image: url(assets/witches/red/charge.png);
  animation: enemy-casting 1s steps(9) infinite;
}

@keyframes enemy-casting {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -1755px;
  }
}

#enemyImage.execute {
  width: 100%;
  height: 195px;
  background-size: 465px;
  background-image: url(assets/witches/red/attack.png);
  animation: enemy-execute 1s steps(7) infinite;
}

@keyframes enemy-execute {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -1365px;
  }
}

#playerImage.damage {
  width: 96px;
  height: 144px;
  background-image: url(assets/witches/blue/damage.png);
  animation: player-damage 0.6s steps(1) 1;
}

@keyframes player-damage {
  0% {
    background-position: 0 0;
  }
  33% {
    background-position: 0 -144px;
  }
  66% {
    background-position: 0 -144px;
  }
  100% {
    background-position: 0 -288px;
  }
}

#enemyImage.damage {
  width: 96px;
  height: 192px;
  background-image: url(assets/witches/red/damage.png);
  animation: enemy-damage 0.6s steps(1) 1;
}

@keyframes enemy-damage {
  0% {
    background-position: 0 0;
  }
  33% {
    background-position: 0 -192px;
  }
  66% {
    background-position: 0 -192px;
  }
  100% {
    background-position: 0 -384px;
  }
}

#playerImage.death {
  width: 96px;
  height: 144px;
  background-image: url(assets/witches/blue/death.png);
  animation: player-death 2s steps(11) 1 forwards;
}

@keyframes player-death {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -1584px;
  }
}

#enemyImage.death {
  width: 100%;
  height: 195px;
  background-size: 465px;
  background-image: url(assets/witches/red/death.png);
  animation: enemy-death 2s steps(13) 1 forwards;
}

@keyframes enemy-death {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 0 -2535px;
  }
}

/* Game Clear Modal Styles */
.modal-stats {
    margin: 20px 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin: 10px 0;
    font-size: 18px;
}

#gameClearModal .stat-label {
    color: #888;
}

#gameClearModal .stat-value {
    color: #4ecdc4;
    font-weight: bold;
}

.share-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 20px 0;
}
